1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-02-06 17:13:36 +01:00

Refactor: Move scale-specific descriptor UUID into subclasses

This commit is contained in:
Martin Nowack 2017-08-04 09:20:39 +02:00
parent 73303c2eca
commit 5c1184e671
3 changed files with 14 additions and 15 deletions

View File

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

View File

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

View File

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