mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-02 15:02:56 +01:00
Merge pull request #1289 from joserebelo/roidmi
Roidmi 3: Fix and enable support
This commit is contained in:
commit
ecbfa38214
@ -146,7 +146,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
}
|
}
|
||||||
} else if (BatteryState.NO_BATTERY.equals(batteryState) && batteryVoltage != GBDevice.BATTERY_UNKNOWN) {
|
} else if (BatteryState.NO_BATTERY.equals(batteryState) && batteryVoltage != GBDevice.BATTERY_UNKNOWN) {
|
||||||
holder.batteryStatusBox.setVisibility(View.VISIBLE);
|
holder.batteryStatusBox.setVisibility(View.VISIBLE);
|
||||||
holder.batteryStatusLabel.setText(String.format(Locale.getDefault(), "%.1fV", batteryVoltage));
|
holder.batteryStatusLabel.setText(String.format(Locale.getDefault(), "%.2f", batteryVoltage));
|
||||||
holder.batteryIcon.setImageLevel(200);
|
holder.batteryIcon.setImageLevel(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,16 +378,23 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
|
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
|
||||||
builder.setDialogTitle(R.string.preferences_led_color);
|
builder.setDialogTitle(R.string.preferences_led_color);
|
||||||
|
|
||||||
|
int[] presets = coordinator.getColorPresets();
|
||||||
|
|
||||||
builder.setColor((int) device.getExtraInfo("led_color"));
|
builder.setColor((int) device.getExtraInfo("led_color"));
|
||||||
|
builder.setShowAlphaSlider(false);
|
||||||
|
builder.setShowColorShades(false);
|
||||||
if (coordinator.supportsRgbLedColor()) {
|
if (coordinator.supportsRgbLedColor()) {
|
||||||
builder.setAllowCustom(true);
|
builder.setAllowCustom(true);
|
||||||
builder.setShowAlphaSlider(false);
|
if (presets.length == 0) {
|
||||||
builder.setAllowPresets(true);
|
builder.setDialogType(ColorPickerDialog.TYPE_CUSTOM);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.setAllowCustom(false);
|
builder.setAllowCustom(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (presets.length > 0) {
|
||||||
builder.setAllowPresets(true);
|
builder.setAllowPresets(true);
|
||||||
builder.setShowColorShades(false);
|
builder.setPresets(presets);
|
||||||
builder.setPresets(coordinator.getColorPresets());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorPickerDialog dialog = builder.create();
|
ColorPickerDialog dialog = builder.create();
|
||||||
|
@ -49,9 +49,4 @@ public class Roidmi1Coordinator extends RoidmiCoordinator {
|
|||||||
public DeviceType getDeviceType() {
|
public DeviceType getDeviceType() {
|
||||||
return DeviceType.ROIDMI;
|
return DeviceType.ROIDMI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getColorPresets() {
|
|
||||||
return RoidmiConst.COLOR_PRESETS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,7 @@ public class Roidmi3Coordinator extends RoidmiCoordinator {
|
|||||||
String name = device.getName();
|
String name = device.getName();
|
||||||
|
|
||||||
if (name != null && name.contains("Roidmi Music Blue C")) {
|
if (name != null && name.contains("Roidmi Music Blue C")) {
|
||||||
LOG.warn("Found a Roidmi 3, but support is disabled.");
|
return DeviceType.ROIDMI3;
|
||||||
return DeviceType.UNKNOWN; // TODO Roidmi 3 is not working atm
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error("unable to check device support", ex);
|
LOG.error("unable to check device support", ex);
|
||||||
|
@ -132,4 +132,9 @@ public abstract class RoidmiCoordinator extends AbstractDeviceCoordinator {
|
|||||||
public boolean supportsLedColor() {
|
public boolean supportsLedColor() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getColorPresets() {
|
||||||
|
return RoidmiConst.COLOR_PRESETS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,7 @@ public class GBDevice implements Parcelable {
|
|||||||
setFirmwareVersion(null);
|
setFirmwareVersion(null);
|
||||||
setFirmwareVersion2(null);
|
setFirmwareVersion2(null);
|
||||||
setRssi(RSSI_UNKNOWN);
|
setRssi(RSSI_UNKNOWN);
|
||||||
|
resetExtraInfos();
|
||||||
if (mBusyTask != null) {
|
if (mBusyTask != null) {
|
||||||
unsetBusyTask();
|
unsetBusyTask();
|
||||||
}
|
}
|
||||||
@ -403,6 +404,13 @@ public class GBDevice implements Parcelable {
|
|||||||
mExtraInfos.put(key, info);
|
mExtraInfos.put(key, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all the extra infos
|
||||||
|
*/
|
||||||
|
public void resetExtraInfos() {
|
||||||
|
mExtraInfos = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ranges from 0-100 (percent), or -1 if unknown
|
* Ranges from 0-100 (percent), or -1 if unknown
|
||||||
*
|
*
|
||||||
|
@ -216,7 +216,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
|
|
||||||
protected void handleGBDeviceEvent(GBDeviceEventLEDColor colorEvent) {
|
protected void handleGBDeviceEvent(GBDeviceEventLEDColor colorEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for LED Color");
|
LOG.info("Got event for LED Color: #" + Integer.toHexString(colorEvent.color).toUpperCase());
|
||||||
if (gbDevice == null) {
|
if (gbDevice == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInf
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFmFrequency;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFmFrequency;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventLEDColor;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventLEDColor;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class Roidmi3Protocol extends RoidmiProtocol {
|
public class Roidmi3Protocol extends RoidmiProtocol {
|
||||||
@ -40,7 +41,7 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
private static final byte[] COMMAND_GET_VOLTAGE = new byte[]{0x06, (byte) 0x81};
|
private static final byte[] COMMAND_GET_VOLTAGE = new byte[]{0x06, (byte) 0x81};
|
||||||
|
|
||||||
private static final byte[] COMMAND_SET_COLOR = new byte[]{0x02, 0x01, 0x00, 0x00, 0x00};
|
private static final byte[] COMMAND_SET_COLOR = new byte[]{0x02, 0x01, 0x00, 0x00, 0x00};
|
||||||
private static final byte[] COMMAND_SET_FREQUENCY = new byte[]{0x05, (byte) 0x81, 0x09, 0x64};
|
private static final byte[] COMMAND_SET_FREQUENCY = new byte[]{0x05, 0x01, 0x09, 0x64};
|
||||||
private static final byte[] COMMAND_DENOISE_ON = new byte[]{0x05, 0x06, 0x12};
|
private static final byte[] COMMAND_DENOISE_ON = new byte[]{0x05, 0x06, 0x12};
|
||||||
private static final byte[] COMMAND_DENOISE_OFF = new byte[]{0x05, 0x06, 0x00};
|
private static final byte[] COMMAND_DENOISE_OFF = new byte[]{0x05, 0x06, 0x00};
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calcChecksum(res) != res[res.length - 2]) {
|
if (calcChecksum(res) != res[res.length - 1]) {
|
||||||
LOG.info("Invalid response checksum");
|
LOG.info("Invalid response checksum");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -68,21 +69,22 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res[1] != (byte) 0x81) {
|
if (res[2] != (byte) 0x81) {
|
||||||
LOG.error("Unrecognized response" + GB.hexdump(res, 0, res.length));
|
LOG.warn("Potentially unsupported response: " + GB.hexdump(res, 0, res.length));
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res[1] == RESPONSE_VOLTAGE) {
|
if (res[1] == RESPONSE_VOLTAGE) {
|
||||||
String voltageHex = GB.hexdump(res, 3, 2);
|
String voltageHex = GB.hexdump(res, 3, 2);
|
||||||
float voltage = Float.valueOf(voltageHex) / 10.0f;
|
float voltage = Float.valueOf(voltageHex) / 100.0f;
|
||||||
LOG.debug("Got voltage: " + voltage);
|
LOG.debug("Got voltage: " + voltage);
|
||||||
GBDeviceEventBatteryInfo evBattery = new GBDeviceEventBatteryInfo();
|
GBDeviceEventBatteryInfo evBattery = new GBDeviceEventBatteryInfo();
|
||||||
|
evBattery.state = BatteryState.NO_BATTERY;
|
||||||
|
evBattery.level = GBDevice.BATTERY_UNKNOWN;
|
||||||
evBattery.voltage = voltage;
|
evBattery.voltage = voltage;
|
||||||
return new GBDeviceEvent[]{evBattery};
|
return new GBDeviceEvent[]{evBattery};
|
||||||
} else if (res[1] == RESPONSE_COLOR) {
|
} else if (res[1] == RESPONSE_COLOR) {
|
||||||
LOG.debug("Got color: " + GB.hexdump(res, 3, 3));
|
LOG.debug("Got color: #" + GB.hexdump(res, 3, 3));
|
||||||
int color = res[3] << 16 | res[4] << 8 | res[4];
|
int color = 0xFF000000 | ((res[3] << 16) & 0xFF0000) | ((res[4] << 8) & 0xFF00) | (res[5] & 0xFF);
|
||||||
GBDeviceEventLEDColor evColor = new GBDeviceEventLEDColor();
|
GBDeviceEventLEDColor evColor = new GBDeviceEventLEDColor();
|
||||||
evColor.color = color;
|
evColor.color = color;
|
||||||
return new GBDeviceEvent[]{evColor};
|
return new GBDeviceEvent[]{evColor};
|
||||||
@ -94,7 +96,7 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
evFrequency.frequency = frequency;
|
evFrequency.frequency = frequency;
|
||||||
return new GBDeviceEvent[]{evFrequency};
|
return new GBDeviceEvent[]{evFrequency};
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Unrecognized response" + GB.hexdump(res, 0, res.length));
|
LOG.error("Unrecognized response: " + GB.hexdump(res, 0, res.length));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,9 +105,9 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
public byte[] encodeLedColor(int color) {
|
public byte[] encodeLedColor(int color) {
|
||||||
byte[] cmd = COMMAND_SET_COLOR.clone();
|
byte[] cmd = COMMAND_SET_COLOR.clone();
|
||||||
|
|
||||||
cmd[2] = (byte) color;
|
cmd[2] = (byte) (color >> 16);
|
||||||
cmd[3] = (byte) (color >> 8);
|
cmd[3] = (byte) (color >> 8);
|
||||||
cmd[4] = (byte) (color >> 16);
|
cmd[4] = (byte) color;
|
||||||
|
|
||||||
return encodeCommand(cmd);
|
return encodeCommand(cmd);
|
||||||
}
|
}
|
||||||
@ -144,7 +146,7 @@ public class Roidmi3Protocol extends RoidmiProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] encodeGetVoltage() {
|
public byte[] encodeGetVoltage() {
|
||||||
return COMMAND_GET_VOLTAGE;
|
return encodeCommand(COMMAND_GET_VOLTAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] encodeDenoise(boolean enabled) {
|
public byte[] encodeDenoise(boolean enabled) {
|
||||||
|
Loading…
Reference in New Issue
Block a user