Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

[RFC] Mi Band 2: Add rudimentary raw sensor data support #894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_UNKNOWN_CHARACTERISTIC2 = UUID.fromString("00000002-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_CHARACTERISTIC_2_SENSOR_DATA = UUID.fromString("00000002-0000-3512-2118-0009af100700");
/**
* Alarms, Display and other configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,17 @@ public void onReceive(Context context, Intent intent) {
private boolean needsAuth;
private volatile boolean telephoneRinging;
private volatile boolean isLocatingDevice;
private volatile boolean isReadingSensorData;

private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
private RealtimeSamplesSupport realtimeSamplesSupport;
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() {
this(LOG);
}
Expand Down Expand Up @@ -271,6 +276,7 @@ public MiBand2Support enableFurtherNotifications(TransactionBuilder builder, boo
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_DEVICEEVENT), enable);
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_2_SENSOR_DATA), enable);

return this;
}
Expand Down Expand Up @@ -1037,6 +1043,9 @@ public boolean onCharacteristicChanged(BluetoothGatt gatt,
} else if (MiBand2Service.UUID_CHARACTERISTIC_7_REALTIME_STEPS.equals(characteristicUUID)) {
handleRealtimeSteps(characteristic.getValue());
return true;
} else if (MiBand2Service.UUID_CHARACTERISTIC_2_SENSOR_DATA.equals(characteristicUUID)) {
handleSensorData(characteristic.getValue());
return true;
} else {
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
logMessageContent(characteristic.getValue());
Expand Down Expand Up @@ -1131,6 +1140,10 @@ private void handleRealtimeSteps(byte[] value) {
}
}

private void handleSensorData(byte[] value) {
// See logcat for raw data output
}

private void enableRealtimeSamplesTimer(boolean enable) {
if (enable) {
getRealtimeSamplesSupport().start();
Expand Down Expand Up @@ -1350,9 +1363,16 @@ public void onSendConfiguration(String config) {
public void onTestNewFunction() {
try {
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());
isReadingSensorData = !isReadingSensorData;
} catch (IOException e) {
LOG.error("Unable to toggle sensor reading MI2", e);
}
}

Expand Down