1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 01:43:59 +02:00

Added possibility to switch unit on Sanitas/SilverCrest/Beurer scales

This commit is contained in:
Martijn van Welie
2018-01-15 23:11:37 +01:00
parent c1f247cb27
commit ee04c5dfef
3 changed files with 63 additions and 5 deletions

View File

@@ -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<Integer> 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);
}

View File

@@ -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);
}

View File

@@ -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;