mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 08:05:55 +01:00
Mi Band 2: Add rudimentary raw sensor data support
Note that this is extremely hacky (and does not really work all that great) and some more investigation into the mechanism/flags is needed.
This commit is contained in:
parent
36e50bddb0
commit
4b5810a1a0
@ -35,8 +35,8 @@ public class MiBand2Service {
|
|||||||
public static final UUID UUID_CHARACTERISTIC_FIRMWARE_DATA = UUID.fromString("00001532-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_FIRMWARE_DATA = UUID.fromString("00001532-0000-3512-2118-0009af100700");
|
||||||
|
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC0 = UUID.fromString("00000000-0000-3512-2118-0009af100700");
|
public static final UUID UUID_UNKNOWN_CHARACTERISTIC0 = UUID.fromString("00000000-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC1 = UUID.fromString("00000001-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_1_SENSOR_CONTROL = UUID.fromString("00000001-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC2 = UUID.fromString("00000002-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_2_SENSOR_DATA = UUID.fromString("00000002-0000-3512-2118-0009af100700");
|
||||||
/**
|
/**
|
||||||
* Alarms, Display and other configuration.
|
* Alarms, Display and other configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -154,12 +154,17 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
private boolean needsAuth;
|
private boolean needsAuth;
|
||||||
private volatile boolean telephoneRinging;
|
private volatile boolean telephoneRinging;
|
||||||
private volatile boolean isLocatingDevice;
|
private volatile boolean isLocatingDevice;
|
||||||
|
private volatile boolean isReadingSensorData;
|
||||||
|
|
||||||
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||||
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
||||||
private RealtimeSamplesSupport realtimeSamplesSupport;
|
private RealtimeSamplesSupport realtimeSamplesSupport;
|
||||||
private boolean alarmClockRinging;
|
private boolean alarmClockRinging;
|
||||||
|
|
||||||
|
private static final byte[] startSensorRead1 = new byte[]{0x01, 0x01, 0x19};
|
||||||
|
private static final byte[] startSensorRead2 = new byte[]{0x02};
|
||||||
|
private static final byte[] stopSensorRead = new byte[]{0x03};
|
||||||
|
|
||||||
public MiBand2Support() {
|
public MiBand2Support() {
|
||||||
this(LOG);
|
this(LOG);
|
||||||
}
|
}
|
||||||
@ -271,6 +276,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), enable);
|
||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO), enable);
|
||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_DEVICEEVENT), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_DEVICEEVENT), enable);
|
||||||
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_2_SENSOR_DATA), enable);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -1037,6 +1043,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
} else if (MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS.equals(characteristicUUID)) {
|
} else if (MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS.equals(characteristicUUID)) {
|
||||||
handleRealtimeSteps(characteristic.getValue());
|
handleRealtimeSteps(characteristic.getValue());
|
||||||
return true;
|
return true;
|
||||||
|
} else if (MiBand2Service.UUID_CHARACTERISTIC_2_SENSOR_DATA.equals(characteristicUUID)) {
|
||||||
|
handleSensorData(characteristic.getValue());
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
||||||
logMessageContent(characteristic.getValue());
|
logMessageContent(characteristic.getValue());
|
||||||
@ -1131,6 +1140,10 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleSensorData(byte[] value) {
|
||||||
|
// See logcat for raw data output
|
||||||
|
}
|
||||||
|
|
||||||
private void enableRealtimeSamplesTimer(boolean enable) {
|
private void enableRealtimeSamplesTimer(boolean enable) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
getRealtimeSamplesSupport().start();
|
getRealtimeSamplesSupport().start();
|
||||||
@ -1350,9 +1363,16 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
public void onTestNewFunction() {
|
public void onTestNewFunction() {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("test realtime steps");
|
TransactionBuilder builder = performInitialized("test realtime steps");
|
||||||
builder.read(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS));
|
if (isReadingSensorData) {
|
||||||
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_1_SENSOR_CONTROL), stopSensorRead);
|
||||||
|
} else {
|
||||||
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_1_SENSOR_CONTROL), startSensorRead1);
|
||||||
|
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_1_SENSOR_CONTROL), startSensorRead2);
|
||||||
|
}
|
||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
|
isReadingSensorData = !isReadingSensorData;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
LOG.error("Unable to toggle sensor reading MI2", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user