diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerBF700_800.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerBF700_800.java index f2c72e2b..29ff9fe8 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerBF700_800.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerBF700_800.java @@ -103,6 +103,9 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication { private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = // write-only, notify ; handle=0x002e UUID.fromString("0000FFE1-0000-1000-8000-00805F9B34FB"); + // Command bytes + private static final byte[] SET_UNIT_COMMAND = new byte[] {(byte) 0xf7, (byte) 0x4d, (byte) 0x00}; + private int currentScaleUserId; private int countRegisteredScaleUsers; private TreeSet seenUsers; @@ -159,10 +162,14 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication { updateDateTimeBeurer(); break; case 3: + // Set measurement unit + setUnitCommand(); + break; + case 4: // Request general user information writeBytes(new byte[]{(byte) 0xf7, (byte) 0x33}); break; - case 4: + case 5: // Wait for ack of all users if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) { // Request this state again @@ -217,7 +224,7 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication { break; - case 5: + case 6: break; default: // Finish init if everything is done @@ -601,6 +608,28 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication { writeBytes(new byte[]{(byte) 0xf9, unixTimeBytes[4], unixTimeBytes[5], unixTimeBytes[6], unixTimeBytes[7]}); } + private void setUnitCommand() { + byte[] command = SET_UNIT_COMMAND; + final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser(); + + switch ((byte) selectedUser.getScaleUnit()) { + case 0: + // Kg + command[2] = (byte) 0x01; + break; + case 1: + // Lb + command[2] = (byte) 0x02; + break; + case 2: + // St + command[3] = (byte) 0x04; + break; + } + Log.d(TAG, "Setting unit " + ScaleUser.UNIT_STRING[selectedUser.getScaleUnit()]); + writeBytes(command); + } + private void writeBytes(byte[] data) { writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data); } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java index add9af6c..fb07563d 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothSanitasSbf70.java @@ -99,6 +99,9 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication { private static final UUID CUSTOM_CHARACTERISTIC_IMG_BLOCK = // write-only, notify UUID.fromString("F000FFC2-0451-4000-8000-000000000000"); + // Command bytes + private static final byte[] SET_UNIT_COMMAND = new byte[] {(byte) 0xe7, (byte) 0x4d, (byte) 0x00}; + private int currentScaleUserId; private int countRegisteredScaleUsers; @@ -153,10 +156,14 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication { updateDateTimeSanitas(); break; case 3: + // Set measurement unit + setUnitCommand(); + break; + case 4: // Request general user information writeBytes(new byte[]{(byte) 0xe7, (byte) 0x33}); break; - case 4: + case 5: // Wait for ack of all users if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) { // Request this state again @@ -211,7 +218,7 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication { break; - case 5: + case 6: break; default: // Finish init if everything is done @@ -596,6 +603,28 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication { writeBytes(new byte[]{(byte) 0xe9, unixTimeBytes[4], unixTimeBytes[5], unixTimeBytes[6], unixTimeBytes[7]}); } + private void setUnitCommand() { + byte[] command = SET_UNIT_COMMAND; + final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser(); + + switch ((byte) selectedUser.getScaleUnit()) { + case 0: + // Kg + command[2] = (byte) 0x01; + break; + case 1: + // Lb + command[2] = (byte) 0x02; + break; + case 2: + // St + command[3] = (byte) 0x04; + break; + } + Log.d(TAG, "Setting unit " + ScaleUser.UNIT_STRING[selectedUser.getScaleUnit()]); + writeBytes(command); + } + private void writeBytes(byte[] data) { writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data); } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java index f2fbe5f7..8d43c95e 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java @@ -376,7 +376,7 @@ public class MainActivity extends AppCompatActivity { setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success); ScaleMeasurement scaleBtData = (ScaleMeasurement) msg.obj; - scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().getScaleUnit()); + // scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().getScaleUnit()); OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData); break;