mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-26 09:44:31 +02:00
Added possibility to switch unit on Sanitas/SilverCrest/Beurer scales
This commit is contained in:
@@ -103,6 +103,9 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = // write-only, notify ; handle=0x002e
|
private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = // write-only, notify ; handle=0x002e
|
||||||
UUID.fromString("0000FFE1-0000-1000-8000-00805F9B34FB");
|
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 currentScaleUserId;
|
||||||
private int countRegisteredScaleUsers;
|
private int countRegisteredScaleUsers;
|
||||||
private TreeSet<Integer> seenUsers;
|
private TreeSet<Integer> seenUsers;
|
||||||
@@ -159,10 +162,14 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
updateDateTimeBeurer();
|
updateDateTimeBeurer();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
// Set measurement unit
|
||||||
|
setUnitCommand();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
// Request general user information
|
// Request general user information
|
||||||
writeBytes(new byte[]{(byte) 0xf7, (byte) 0x33});
|
writeBytes(new byte[]{(byte) 0xf7, (byte) 0x33});
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
// Wait for ack of all users
|
// Wait for ack of all users
|
||||||
if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) {
|
if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) {
|
||||||
// Request this state again
|
// Request this state again
|
||||||
@@ -217,7 +224,7 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
|||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 6:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Finish init if everything is done
|
// 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]});
|
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) {
|
private void writeBytes(byte[] data) {
|
||||||
writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data);
|
writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data);
|
||||||
}
|
}
|
||||||
|
@@ -99,6 +99,9 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
|
|||||||
private static final UUID CUSTOM_CHARACTERISTIC_IMG_BLOCK = // write-only, notify
|
private static final UUID CUSTOM_CHARACTERISTIC_IMG_BLOCK = // write-only, notify
|
||||||
UUID.fromString("F000FFC2-0451-4000-8000-000000000000");
|
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 currentScaleUserId;
|
||||||
private int countRegisteredScaleUsers;
|
private int countRegisteredScaleUsers;
|
||||||
@@ -153,10 +156,14 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
|
|||||||
updateDateTimeSanitas();
|
updateDateTimeSanitas();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
// Set measurement unit
|
||||||
|
setUnitCommand();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
// Request general user information
|
// Request general user information
|
||||||
writeBytes(new byte[]{(byte) 0xe7, (byte) 0x33});
|
writeBytes(new byte[]{(byte) 0xe7, (byte) 0x33});
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
// Wait for ack of all users
|
// Wait for ack of all users
|
||||||
if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) {
|
if (seenUsers.size() < countRegisteredScaleUsers || (countRegisteredScaleUsers == -1)) {
|
||||||
// Request this state again
|
// Request this state again
|
||||||
@@ -211,7 +218,7 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
|
|||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 6:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Finish init if everything is done
|
// 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]});
|
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) {
|
private void writeBytes(byte[] data) {
|
||||||
writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data);
|
writeBytes(CUSTOM_SERVICE_1, CUSTOM_CHARACTERISTIC_WEIGHT, data);
|
||||||
}
|
}
|
||||||
|
@@ -376,7 +376,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
||||||
ScaleMeasurement scaleBtData = (ScaleMeasurement) msg.obj;
|
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);
|
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user