mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 16:53:04 +02:00
Refactor: Move scale-specific descriptor UUID into subclasses
This commit is contained in:
@@ -51,7 +51,6 @@ public abstract class BluetoothCommunication {
|
||||
private int cleanupStepNr;
|
||||
private BT_MACHINE_STATE btMachineState;
|
||||
|
||||
private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
|
||||
|
||||
public BluetoothCommunication(Context context)
|
||||
{
|
||||
@@ -284,13 +283,13 @@ public abstract class BluetoothCommunication {
|
||||
* @param service the Bluetooth UUID device service
|
||||
* @param characteristic the Bluetooth UUID characteristic
|
||||
*/
|
||||
protected void setInidicationOn(UUID service, UUID characteristic) {
|
||||
protected void setIndicationOn(UUID service, UUID characteristic, UUID descriptor) {
|
||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||
.getCharacteristic(characteristic);
|
||||
|
||||
bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
|
||||
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(WEIGHT_MEASUREMENT_CONFIG);
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
|
||||
gattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
|
||||
|
||||
bluetoothGatt.writeDescriptor(gattDescriptor);
|
||||
@@ -302,13 +301,13 @@ public abstract class BluetoothCommunication {
|
||||
* @param service the Bluetooth UUID device service
|
||||
* @param characteristic the Bluetooth UUID characteristic
|
||||
*/
|
||||
protected void setNotificationOn(UUID service, UUID characteristic) {
|
||||
protected void setNotificationOn(UUID service, UUID characteristic, UUID descriptor) {
|
||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||
.getCharacteristic(characteristic);
|
||||
|
||||
bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
|
||||
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(WEIGHT_MEASUREMENT_CONFIG);
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
|
||||
gattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
bluetoothGatt.writeDescriptor(gattDescriptor);
|
||||
}
|
||||
@@ -319,13 +318,13 @@ public abstract class BluetoothCommunication {
|
||||
* @param service the Bluetooth UUID device service
|
||||
* @param characteristic the Bluetooth UUID characteristic
|
||||
*/
|
||||
protected void setNotificationOff(UUID service, UUID characteristic) {
|
||||
protected void setNotificationOff(UUID service, UUID characteristic, UUID descriptor) {
|
||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||
.getCharacteristic(characteristic);
|
||||
|
||||
bluetoothGatt.setCharacteristicNotification(gattCharacteristic, false);
|
||||
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(WEIGHT_MEASUREMENT_CONFIG);
|
||||
BluetoothGattDescriptor gattDescriptor = gattCharacteristic.getDescriptor(descriptor);
|
||||
gattDescriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
|
||||
bluetoothGatt.writeDescriptor(gattDescriptor);
|
||||
}
|
||||
|
@@ -82,15 +82,15 @@ public class BluetoothMedisanaBS444 extends BluetoothCommunication {
|
||||
switch (stateNr) {
|
||||
case 0:
|
||||
// set indication on for feature characteristic
|
||||
setInidicationOn(WEIGHT_MEASUREMENT_SERVICE, FEATURE_MEASUREMENT_CHARACTERISTIC);
|
||||
setIndicationOn(WEIGHT_MEASUREMENT_SERVICE, FEATURE_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 1:
|
||||
// set indication on for weight measurement
|
||||
setInidicationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC);
|
||||
setIndicationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 2:
|
||||
// set indication on for custom5 measurement
|
||||
setInidicationOn(WEIGHT_MEASUREMENT_SERVICE, CUSTOM5_MEASUREMENT_CHARACTERISTIC);
|
||||
setIndicationOn(WEIGHT_MEASUREMENT_SERVICE, CUSTOM5_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 3:
|
||||
// send magic number to receive weight data
|
||||
|
@@ -133,7 +133,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
||||
break;
|
||||
case 2:
|
||||
// set notification on for weight measurement history
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC);
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 3:
|
||||
// Set on history weight measurement
|
||||
@@ -153,11 +153,11 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
||||
switch (stateNr) {
|
||||
case 0:
|
||||
// set notification on for weight measurement
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC);
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 1:
|
||||
// set notification on for weight measurement history
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC);
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 2:
|
||||
// configure scale to get only last measurements
|
||||
@@ -168,11 +168,11 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
||||
break;
|
||||
case 3:
|
||||
// set notification off for weight measurement history
|
||||
setNotificationOff(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC);
|
||||
setNotificationOff(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 4:
|
||||
// set notification on for weight measurement history
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC);
|
||||
setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
|
||||
break;
|
||||
case 5:
|
||||
// invoke receiving history data
|
||||
|
Reference in New Issue
Block a user