diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java index e9b057f05..9c38d606e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapterv2.java @@ -146,7 +146,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter 0) { builder.setAllowPresets(true); - builder.setShowColorShades(false); - builder.setPresets(coordinator.getColorPresets()); + builder.setPresets(presets); } ColorPickerDialog dialog = builder.create(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java index 47351dd01..caba200a6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi1Coordinator.java @@ -49,9 +49,4 @@ public class Roidmi1Coordinator extends RoidmiCoordinator { public DeviceType getDeviceType() { return DeviceType.ROIDMI; } - - @Override - public int[] getColorPresets() { - return RoidmiConst.COLOR_PRESETS; - } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java index 10c351844..81fb6b2e9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/Roidmi3Coordinator.java @@ -36,8 +36,7 @@ public class Roidmi3Coordinator extends RoidmiCoordinator { String name = device.getName(); if (name != null && name.contains("Roidmi Music Blue C")) { - LOG.warn("Found a Roidmi 3, but support is disabled."); - return DeviceType.UNKNOWN; // TODO Roidmi 3 is not working atm + return DeviceType.ROIDMI3; } } catch (Exception ex) { LOG.error("unable to check device support", ex); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/RoidmiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/RoidmiCoordinator.java index 39d7ce76e..2b6fa4295 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/RoidmiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/roidmi/RoidmiCoordinator.java @@ -132,4 +132,9 @@ public abstract class RoidmiCoordinator extends AbstractDeviceCoordinator { public boolean supportsLedColor() { return true; } + + @Override + public int[] getColorPresets() { + return RoidmiConst.COLOR_PRESETS; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java index 2adc2ae71..766ad799b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java @@ -274,6 +274,7 @@ public class GBDevice implements Parcelable { setFirmwareVersion(null); setFirmwareVersion2(null); setRssi(RSSI_UNKNOWN); + resetExtraInfos(); if (mBusyTask != null) { unsetBusyTask(); } @@ -403,6 +404,13 @@ public class GBDevice implements Parcelable { mExtraInfos.put(key, info); } + /** + * Deletes all the extra infos + */ + public void resetExtraInfos() { + mExtraInfos = null; + } + /** * Ranges from 0-100 (percent), or -1 if unknown * diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index dd969d237..1f995e4ca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -216,7 +216,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { protected void handleGBDeviceEvent(GBDeviceEventLEDColor colorEvent) { 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) { return; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/roidmi/Roidmi3Protocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/roidmi/Roidmi3Protocol.java index a4d6412e7..38d192837 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/roidmi/Roidmi3Protocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/roidmi/Roidmi3Protocol.java @@ -24,6 +24,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInf import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFmFrequency; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventLEDColor; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; +import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; import nodomain.freeyourgadget.gadgetbridge.util.GB; 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_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_OFF = new byte[]{0x05, 0x06, 0x00}; @@ -58,7 +59,7 @@ public class Roidmi3Protocol extends RoidmiProtocol { return null; } - if (calcChecksum(res) != res[res.length - 2]) { + if (calcChecksum(res) != res[res.length - 1]) { LOG.info("Invalid response checksum"); return null; } @@ -68,21 +69,22 @@ public class Roidmi3Protocol extends RoidmiProtocol { return null; } - if (res[1] != (byte) 0x81) { - LOG.error("Unrecognized response" + GB.hexdump(res, 0, res.length)); - return null; + if (res[2] != (byte) 0x81) { + LOG.warn("Potentially unsupported response: " + GB.hexdump(res, 0, res.length)); } if (res[1] == RESPONSE_VOLTAGE) { 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); GBDeviceEventBatteryInfo evBattery = new GBDeviceEventBatteryInfo(); + evBattery.state = BatteryState.NO_BATTERY; + evBattery.level = GBDevice.BATTERY_UNKNOWN; evBattery.voltage = voltage; return new GBDeviceEvent[]{evBattery}; } else if (res[1] == RESPONSE_COLOR) { - LOG.debug("Got color: " + GB.hexdump(res, 3, 3)); - int color = res[3] << 16 | res[4] << 8 | res[4]; + LOG.debug("Got color: #" + GB.hexdump(res, 3, 3)); + int color = 0xFF000000 | ((res[3] << 16) & 0xFF0000) | ((res[4] << 8) & 0xFF00) | (res[5] & 0xFF); GBDeviceEventLEDColor evColor = new GBDeviceEventLEDColor(); evColor.color = color; return new GBDeviceEvent[]{evColor}; @@ -94,7 +96,7 @@ public class Roidmi3Protocol extends RoidmiProtocol { evFrequency.frequency = frequency; return new GBDeviceEvent[]{evFrequency}; } else { - LOG.error("Unrecognized response" + GB.hexdump(res, 0, res.length)); + LOG.error("Unrecognized response: " + GB.hexdump(res, 0, res.length)); return null; } } @@ -103,9 +105,9 @@ public class Roidmi3Protocol extends RoidmiProtocol { public byte[] encodeLedColor(int color) { byte[] cmd = COMMAND_SET_COLOR.clone(); - cmd[2] = (byte) color; + cmd[2] = (byte) (color >> 16); cmd[3] = (byte) (color >> 8); - cmd[4] = (byte) (color >> 16); + cmd[4] = (byte) color; return encodeCommand(cmd); } @@ -144,7 +146,7 @@ public class Roidmi3Protocol extends RoidmiProtocol { } public byte[] encodeGetVoltage() { - return COMMAND_GET_VOLTAGE; + return encodeCommand(COMMAND_GET_VOLTAGE); } public byte[] encodeDenoise(boolean enabled) {