mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-14 20:54:33 +02:00
Update BluetoothOKOK.java (#931)
Support for additional OKOK/Chipsea-BLE based scale
This commit is contained in:
@@ -22,6 +22,7 @@ import timber.log.Timber;
|
|||||||
public class BluetoothOKOK extends BluetoothCommunication {
|
public class BluetoothOKOK extends BluetoothCommunication {
|
||||||
private static final int MANUFACTURER_DATA_ID_V20 = 0x20ca; // 16-bit little endian "header" 0xca 0x20
|
private static final int MANUFACTURER_DATA_ID_V20 = 0x20ca; // 16-bit little endian "header" 0xca 0x20
|
||||||
private static final int MANUFACTURER_DATA_ID_V11 = 0x11ca; // 16-bit little endian "header" 0xca 0x11
|
private static final int MANUFACTURER_DATA_ID_V11 = 0x11ca; // 16-bit little endian "header" 0xca 0x11
|
||||||
|
private static final int MANUFACTURER_DATA_ID_VF0 = 0xf0ff; // 16-bit little endian "header" 0xff 0xf0
|
||||||
private static final int IDX_V20_FINAL = 6;
|
private static final int IDX_V20_FINAL = 6;
|
||||||
private static final int IDX_V20_WEIGHT_MSB = 8;
|
private static final int IDX_V20_WEIGHT_MSB = 8;
|
||||||
private static final int IDX_V20_WEIGHT_LSB = 9;
|
private static final int IDX_V20_WEIGHT_LSB = 9;
|
||||||
@@ -34,12 +35,15 @@ public class BluetoothOKOK extends BluetoothCommunication {
|
|||||||
private static final int IDX_V11_BODY_PROPERTIES = 9;
|
private static final int IDX_V11_BODY_PROPERTIES = 9;
|
||||||
private static final int IDX_V11_CHECKSUM = 16;
|
private static final int IDX_V11_CHECKSUM = 16;
|
||||||
|
|
||||||
|
private static final int IDX_VF0_WEIGHT_MSB = 3;
|
||||||
|
private static final int IDX_VF0_WEIGHT_LSB = 2;
|
||||||
|
|
||||||
private BluetoothCentralManager central;
|
private BluetoothCentralManager central;
|
||||||
private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() {
|
private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) {
|
public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) {
|
||||||
SparseArray<byte[]> manufacturerSpecificData = scanResult.getScanRecord().getManufacturerSpecificData();
|
SparseArray<byte[]> manufacturerSpecificData = scanResult.getScanRecord().getManufacturerSpecificData();
|
||||||
if (manufacturerSpecificData.indexOfKey(MANUFACTURER_DATA_ID_V20) > -1) {
|
if (manufacturerSpecificData.indexOfKey(MANUFACTURER_DATA_ID_V20) > -1) {
|
||||||
byte[] data = manufacturerSpecificData.get(MANUFACTURER_DATA_ID_V20);
|
byte[] data = manufacturerSpecificData.get(MANUFACTURER_DATA_ID_V20);
|
||||||
float divider = 10.0f;
|
float divider = 10.0f;
|
||||||
byte checksum = 0x20; // Version field is part of the checksum, but not in array
|
byte checksum = 0x20; // Version field is part of the checksum, but not in array
|
||||||
@@ -115,6 +119,16 @@ public class BluetoothOKOK extends BluetoothCommunication {
|
|||||||
entry.setWeight(extraWeight + weight / divider);
|
entry.setWeight(extraWeight + weight / divider);
|
||||||
addScaleMeasurement(entry);
|
addScaleMeasurement(entry);
|
||||||
disconnect();
|
disconnect();
|
||||||
|
} else if (manufacturerSpecificData.indexOfKey(MANUFACTURER_DATA_ID_VF0) > -1) {
|
||||||
|
byte[] data = manufacturerSpecificData.get(MANUFACTURER_DATA_ID_VF0);
|
||||||
|
float divider = 10.0f;
|
||||||
|
int weight = data[IDX_VF0_WEIGHT_MSB] & 0xff;
|
||||||
|
weight = weight << 8 | (data[IDX_VF0_WEIGHT_LSB] & 0xff);
|
||||||
|
Timber.d("Got weight: %f", weight / divider);
|
||||||
|
ScaleMeasurement entry = new ScaleMeasurement();
|
||||||
|
entry.setWeight(weight / divider);
|
||||||
|
addScaleMeasurement(entry);
|
||||||
|
disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user