This commit is contained in:
Dennis Guse
2019-10-29 23:05:17 +01:00
parent 9e877e4762
commit e52b1188a3
4 changed files with 16 additions and 22 deletions
@@ -32,6 +32,7 @@ import java.util.UUID;
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.content.sensor.SensorState;
import de.dennisguse.opentracks.util.BluetoothUtils;
/**
* Manages connection to Bluetooth LE heart rate monitor.
@@ -103,7 +104,7 @@ public class BluetoothConnectionManager {
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic) {
int heartRate = BluetoothLEUtils.parseHeartRate(characteristic);
int heartRate = BluetoothUtils.parseHeartRate(characteristic);
Log.d(TAG, "Received heart beat rate: " + heartRate);
SensorDataSet sensorDataSet = new SensorDataSet(heartRate, gatt.getDevice().getName(), gatt.getDevice().getAddress());
@@ -1,17 +0,0 @@
package de.dennisguse.opentracks.services.sensors;
import android.bluetooth.BluetoothGattCharacteristic;
final class BluetoothLEUtils {
private BluetoothLEUtils() {
}
static int parseHeartRate(BluetoothGattCharacteristic characteristic) {
//DOCUMENTATION https://www.bluetooth.com/specifications/gatt/characteristics/
byte[] raw = characteristic.getValue();
int index = ((raw[0] & 0x1) == 1) ? 2 : 1;
int format = (index == 1) ? BluetoothGattCharacteristic.FORMAT_UINT8 : BluetoothGattCharacteristic.FORMAT_UINT16;
return characteristic.getIntValue(format, index);
}
}