mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -378,16 +378,23 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
|
||||
builder.setDialogTitle(R.string.preferences_led_color);
|
||||
|
||||
int[] presets = coordinator.getColorPresets();
|
||||
|
||||
builder.setColor((int) device.getExtraInfo("led_color"));
|
||||
builder.setShowAlphaSlider(false);
|
||||
builder.setShowColorShades(false);
|
||||
if (coordinator.supportsRgbLedColor()) {
|
||||
builder.setAllowCustom(true);
|
||||
builder.setShowAlphaSlider(false);
|
||||
builder.setAllowPresets(true);
|
||||
if (presets.length == 0) {
|
||||
builder.setDialogType(ColorPickerDialog.TYPE_CUSTOM);
|
||||
}
|
||||
} else {
|
||||
builder.setAllowCustom(false);
|
||||
}
|
||||
|
||||
if (presets.length > 0) {
|
||||
builder.setAllowPresets(true);
|
||||
builder.setShowColorShades(false);
|
||||
builder.setPresets(coordinator.getColorPresets());
|
||||
builder.setPresets(presets);
|
||||
}
|
||||
|
||||
ColorPickerDialog dialog = builder.create();
|
||||
|
@ -49,9 +49,4 @@ public class Roidmi1Coordinator extends RoidmiCoordinator {
|
||||
public DeviceType getDeviceType() {
|
||||
return DeviceType.ROIDMI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getColorPresets() {
|
||||
return RoidmiConst.COLOR_PRESETS;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -132,4 +132,9 @@ public abstract class RoidmiCoordinator extends AbstractDeviceCoordinator {
|
||||
public boolean supportsLedColor() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getColorPresets() {
|
||||
return RoidmiConst.COLOR_PRESETS;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user