BLE sensors: clear data when disconnected.

Part of #1027.
This commit is contained in:
Dennis Guse
2021-11-18 23:02:47 +01:00
parent 1f0a99c49a
commit d93e025963
@@ -69,6 +69,8 @@ public abstract class BluetoothConnectionManager<DataType> {
case BluetoothProfile.STATE_DISCONNECTED: case BluetoothProfile.STATE_DISCONNECTED:
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice()); Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
clearData();
break; break;
} }
} }
@@ -130,14 +132,18 @@ public abstract class BluetoothConnectionManager<DataType> {
observer.onChanged(sensorData); observer.onChanged(sensorData);
} }
private synchronized void clearData() {
observer.onDisconnecting(createEmptySensorData(bluetoothGatt.getDevice().getAddress()));
}
synchronized void disconnect() { synchronized void disconnect() {
if (bluetoothGatt == null) { if (bluetoothGatt == null) {
Log.w(TAG, "Cannot disconnect if not connected."); Log.w(TAG, "Cannot disconnect if not connected.");
return; return;
} }
bluetoothGatt.close(); bluetoothGatt.close();
observer.onDisconnecting(createEmptySensorData(bluetoothGatt.getDevice().getAddress())); clearData();
bluetoothGatt = null; bluetoothGatt = null;
} }