BluetoothSensorManager: on initiate connect to sensor, report address to be shown on UI.

Fixes #64.
This commit is contained in:
Dennis Guse
2020-10-31 08:42:20 +01:00
parent 08b9cb31fa
commit b6850eb46f
6 changed files with 56 additions and 6 deletions
@@ -689,7 +689,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
}
SensorDataSet getSensorDataSet() {
if (remoteSensorManager == null || !remoteSensorManager.isEnabled()) {
if (remoteSensorManager == null) {
return null;
}
@@ -55,6 +55,7 @@ public abstract class BluetoothConnectionManager {
switch (newState) {
case BluetoothProfile.STATE_CONNECTING:
Log.d(TAG, "Connecting to sensor: " + gatt.getDevice());
break;
case BluetoothProfile.STATE_CONNECTED:
Log.d(TAG, "Connected to sensor: " + gatt.getDevice());
@@ -62,9 +63,11 @@ public abstract class BluetoothConnectionManager {
break;
case BluetoothProfile.STATE_DISCONNECTING:
Log.d(TAG, "Disconnecting from sensor: " + gatt.getDevice());
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.d(TAG, "Disconnected from sensor: " + gatt.getDevice());
break;
}
}
@@ -114,8 +117,9 @@ public abstract class BluetoothConnectionManager {
Log.d(TAG, "Connecting to: " + device);
bluetoothGatt = device.connectGatt(context, true, this.connectCallback);
bluetoothGatt = device.connectGatt(context, true, connectCallback);
SensorData sensorData = createPreConnectSensorData(bluetoothGatt.getDevice().getAddress());
observer.onChanged(sensorData);
}
synchronized void disconnect() {
@@ -135,10 +139,12 @@ public abstract class BluetoothConnectionManager {
return address.equals(bluetoothGatt.getDevice().getAddress());
}
protected abstract SensorData createPreConnectSensorData(String address);
/**
* @return null if data could not be parsed.
*/
protected abstract de.dennisguse.opentracks.content.sensor.SensorData parsePayload(String sensorName, String address, BluetoothGattCharacteristic characteristic);
protected abstract SensorData parsePayload(String sensorName, String address, BluetoothGattCharacteristic characteristic);
public static class HeartRate extends BluetoothConnectionManager {
@@ -146,6 +152,11 @@ public abstract class BluetoothConnectionManager {
super(BluetoothUtils.HEART_RATE_SERVICE_UUID, BluetoothUtils.HEART_RATE_MEASUREMENT_CHAR_UUID, observer);
}
@Override
protected SensorData createPreConnectSensorData(String address) {
return new SensorDataHeartRate(address);
}
@Override
protected SensorDataHeartRate parsePayload(String sensorName, String address, BluetoothGattCharacteristic characteristic) {
Integer heartRate = BluetoothUtils.parseHeartRate(characteristic);
@@ -160,6 +171,11 @@ public abstract class BluetoothConnectionManager {
super(BluetoothUtils.CYCLING_SPEED_CADENCE_SERVICE_UUID, BluetoothUtils.CYCLING_SPPED_CADENCE_MEASUREMENT_CHAR_UUID, observer);
}
@Override
protected SensorData createPreConnectSensorData(String address) {
return new SensorDataCycling.Cadence(address);
}
@Override
protected SensorDataCycling.Cadence parsePayload(String sensorName, String address, BluetoothGattCharacteristic characteristic) {
SensorDataCycling.CadenceAndSpeed cadenceAndSpeed = BluetoothUtils.parseCyclingCrankAndWheel(address, sensorName, characteristic);
@@ -186,6 +202,11 @@ public abstract class BluetoothConnectionManager {
super(BluetoothUtils.CYCLING_SPEED_CADENCE_SERVICE_UUID, BluetoothUtils.CYCLING_SPPED_CADENCE_MEASUREMENT_CHAR_UUID, observer);
}
@Override
protected SensorData createPreConnectSensorData(String address) {
return new SensorDataCycling.Speed(address);
}
@Override
protected SensorDataCycling.Speed parsePayload(String sensorName, String address, BluetoothGattCharacteristic characteristic) {
SensorDataCycling.CadenceAndSpeed cadenceAndSpeed = BluetoothUtils.parseCyclingCrankAndWheel(address, sensorName, characteristic);