From 5c1184e671bfb62ee667d83cff9f08935a38b202 Mon Sep 17 00:00:00 2001 From: Martin Nowack Date: Fri, 4 Aug 2017 09:20:39 +0200 Subject: [PATCH] Refactor: Move scale-specific descriptor UUID into subclasses --- .../core/bluetooth/BluetoothCommunication.java | 13 ++++++------- .../core/bluetooth/BluetoothMedisanaBS444.java | 6 +++--- .../openscale/core/bluetooth/BluetoothMiScale.java | 10 +++++----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index 43c24e57..0c4a8118 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -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); } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java index 633f0bf0..f39b0e1c 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS444.java @@ -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 diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java index bb673eda..3dfec904 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java @@ -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