forked from upstream-mirrors/OpenTracks
+4
-4
@@ -77,7 +77,7 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
||||
BluetoothGattService gattService = null;
|
||||
ServiceMeasurementUUID serviceMeasurement = null;
|
||||
for (ServiceMeasurementUUID s : serviceMeasurementUUIDs) {
|
||||
gattService = gatt.getService(s.getServiceUUID());
|
||||
gattService = gatt.getService(s.serviceUUID());
|
||||
if (gattService != null) {
|
||||
serviceMeasurement = s;
|
||||
break;
|
||||
@@ -89,9 +89,9 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
||||
return;
|
||||
}
|
||||
|
||||
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(serviceMeasurement.getMeasurementUUID());
|
||||
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(serviceMeasurement.measurementUUID());
|
||||
if (characteristic == null) {
|
||||
Log.e(TAG, "Could not get BluetoothCharacteristic for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement.getServiceUUID() + " characteristicUUID=" + serviceMeasurement.getMeasurementUUID());
|
||||
Log.e(TAG, "Could not get BluetoothCharacteristic for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement.serviceUUID() + " characteristicUUID=" + serviceMeasurement.measurementUUID());
|
||||
return;
|
||||
}
|
||||
gatt.setCharacteristicNotification(characteristic, true);
|
||||
@@ -113,7 +113,7 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
||||
UUID serviceUUID = characteristic.getService().getUuid();
|
||||
Log.d(TAG, "Received data from " + gatt.getDevice().getAddress() + " with service " + serviceUUID + " and characteristics " + characteristic.getUuid());
|
||||
Optional<ServiceMeasurementUUID> serviceMeasurementUUID = serviceMeasurementUUIDs.stream()
|
||||
.filter(s -> s.getServiceUUID().equals(characteristic.getService().getUuid())).findFirst();
|
||||
.filter(s -> s.serviceUUID().equals(characteristic.getService().getUuid())).findFirst();
|
||||
if (serviceMeasurementUUID.isEmpty()) {
|
||||
Log.e(TAG, "Unknown service UUID; not supported?");
|
||||
return;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class AltitudeSumManager implements SensorConnector {
|
||||
|
||||
altitudeLoss_m += altitudeChange.getAltitudeLoss_m();
|
||||
|
||||
lastAcceptedSensorValue = altitudeChange.getCurrentSensorValue();
|
||||
lastAcceptedSensorValue = altitudeChange.currentSensorValue();
|
||||
}
|
||||
|
||||
lastSeenSensorValue = currentSensorValue;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class BluetoothConnectionManagerCyclingCadence extends AbstractBluetoothC
|
||||
if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_POWER)) {
|
||||
SensorDataCyclingPower.Data data = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
||||
if (data!= null) {
|
||||
return data.getCadence();
|
||||
return data.cadence();
|
||||
}
|
||||
} else if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_SPEED_CADENCE)) {
|
||||
SensorDataCyclingCadenceAndDistanceSpeed cadenceAndSpeed = BluetoothUtils.parseCyclingCrankAndWheel(address, sensorName, characteristic);
|
||||
|
||||
+1
-1
@@ -22,6 +22,6 @@ public class BluetoothConnectionManagerCyclingPower extends AbstractBluetoothCon
|
||||
protected SensorDataCyclingPower parsePayload(@NonNull ServiceMeasurementUUID serviceMeasurementUUID, String sensorName, String address, BluetoothGattCharacteristic characteristic) {
|
||||
SensorDataCyclingPower.Data cyclingPower = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
||||
|
||||
return cyclingPower != null ? cyclingPower.getPower() : null;
|
||||
return cyclingPower != null ? cyclingPower.power() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ public class BluetoothUtils {
|
||||
);
|
||||
|
||||
// Used for device discovery in preferences
|
||||
public static final List<ServiceMeasurementUUID> HEART_RATE_SUPPORTING_DEVICES = Collections.unmodifiableList(Arrays.asList(
|
||||
public static final List<ServiceMeasurementUUID> HEART_RATE_SUPPORTING_DEVICES = List.of(
|
||||
HEARTRATE,
|
||||
//Devices that support HEART_RATE_SERVICE_UUID, but do not announce HEART_RATE_SERVICE_UUID in there BLE announcement messages (during device discovery).
|
||||
new ServiceMeasurementUUID(
|
||||
UUID.fromString("0000fee0-0000-1000-8000-00805f9b34fb"), //Miband3
|
||||
HEARTRATE.getMeasurementUUID()
|
||||
))
|
||||
HEARTRATE.measurementUUID()
|
||||
)
|
||||
);
|
||||
|
||||
private static final UUID ENVIRONMENTAL_SENSING_SERVICE = new UUID(0x181A00001000L, 0x800000805f9b34fbL);
|
||||
|
||||
@@ -18,24 +18,7 @@ public class PressureSensorUtils {
|
||||
private PressureSensorUtils() {
|
||||
}
|
||||
|
||||
public static class AltitudeChange {
|
||||
|
||||
private final AtmosphericPressure currentSensorValue;
|
||||
|
||||
private final float altitudeChange_m;
|
||||
|
||||
public AltitudeChange(AtmosphericPressure currentSensorValue, float altitudeChange_m) {
|
||||
this.currentSensorValue = currentSensorValue;
|
||||
this.altitudeChange_m = altitudeChange_m;
|
||||
}
|
||||
|
||||
public AtmosphericPressure getCurrentSensorValue() {
|
||||
return currentSensorValue;
|
||||
}
|
||||
|
||||
public float getAltitudeChange_m() {
|
||||
return altitudeChange_m;
|
||||
}
|
||||
public record AltitudeChange(AtmosphericPressure currentSensorValue, float altitudeChange_m) {
|
||||
|
||||
public float getAltitudeGain_m() {
|
||||
return altitudeChange_m > 0 ? altitudeChange_m : 0;
|
||||
@@ -67,7 +50,7 @@ public class PressureSensorUtils {
|
||||
|
||||
// Limit altitudeC change by ALTITUDE_CHANGE_DIFF and computes pressure value accordingly.
|
||||
AltitudeChange altitudeChange = new AltitudeChange(currentSensorValue, altitudeChange_m);
|
||||
if (altitudeChange.getAltitudeChange_m() > 0) {
|
||||
if (altitudeChange.altitudeChange_m() > 0) {
|
||||
return new AltitudeChange(getBarometricPressure(lastSensorValue_m + ALTITUDE_CHANGE_DIFF_M), ALTITUDE_CHANGE_DIFF_M);
|
||||
} else {
|
||||
return new AltitudeChange(getBarometricPressure(lastSensorValue_m - ALTITUDE_CHANGE_DIFF_M), -1 * ALTITUDE_CHANGE_DIFF_M);
|
||||
|
||||
@@ -5,43 +5,5 @@ import androidx.annotation.NonNull;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ServiceMeasurementUUID {
|
||||
|
||||
private final UUID serviceUUID;
|
||||
private final UUID measurementUUID;
|
||||
|
||||
public ServiceMeasurementUUID(UUID serviceUUID, UUID measurementUUID) {
|
||||
this.serviceUUID = serviceUUID;
|
||||
this.measurementUUID = measurementUUID;
|
||||
}
|
||||
|
||||
public UUID getServiceUUID() {
|
||||
return serviceUUID;
|
||||
}
|
||||
|
||||
public UUID getMeasurementUUID() {
|
||||
return measurementUUID;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServiceMeasurementUUID{" +
|
||||
"serviceUUID=" + serviceUUID +
|
||||
", measurementUUID=" + measurementUUID +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ServiceMeasurementUUID that = (ServiceMeasurementUUID) o;
|
||||
return Objects.equals(serviceUUID, that.serviceUUID) && Objects.equals(measurementUUID, that.measurementUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(serviceUUID, measurementUUID);
|
||||
}
|
||||
public record ServiceMeasurementUUID(UUID serviceUUID, UUID measurementUUID) {
|
||||
}
|
||||
|
||||
+13
-24
@@ -28,30 +28,19 @@ public class SensorDataCyclingPower extends SensorData<Power> {
|
||||
return super.toString() + " data=" + value;
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
private final SensorDataCyclingPower power;
|
||||
private final SensorDataCyclingCadence cadence;
|
||||
public record Data(SensorDataCyclingPower power, SensorDataCyclingCadence cadence) {
|
||||
public Data(SensorDataCyclingPower power, @Nullable SensorDataCyclingCadence cadence) {
|
||||
this.power = power;
|
||||
this.cadence = cadence;
|
||||
}
|
||||
|
||||
public Data(SensorDataCyclingPower power, @Nullable SensorDataCyclingCadence cadence) {
|
||||
this.power = power;
|
||||
this.cadence = cadence;
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Data{" +
|
||||
"power=" + power +
|
||||
", cadence=" + cadence +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public SensorDataCyclingPower getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public SensorDataCyclingCadence getCadence() {
|
||||
return cadence;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Data{" +
|
||||
"power=" + power +
|
||||
", cadence=" + cadence +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
|
||||
Distance overallDistance = null;
|
||||
if (previous != null && previous.hasTotalDistance()) {
|
||||
overallDistance = this.totalDistance.minus(previous.totalDistance);
|
||||
if (previous.hasValue() && previous.getValue().getDistance() != null) {
|
||||
overallDistance = overallDistance.plus(previous.getValue().getDistance());
|
||||
if (previous.hasValue() && previous.getValue().distance() != null) {
|
||||
overallDistance = overallDistance.plus(previous.getValue().distance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,41 +84,6 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
|
||||
}
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
private final Speed speed;
|
||||
private final Cadence cadence;
|
||||
|
||||
@Nullable
|
||||
private final Distance distance;
|
||||
|
||||
public Data(Speed speed, Cadence cadence, @Nullable Distance distance) {
|
||||
this.speed = speed;
|
||||
this.cadence = cadence;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public Speed getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public Cadence getCadence() {
|
||||
return cadence;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Distance getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Data{" +
|
||||
"speed=" + speed +
|
||||
", cadence=" + cadence +
|
||||
", distance=" + distance +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
public record Data(Speed speed, Cadence cadence, @Nullable Distance distance) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class SensorDataSet {
|
||||
return new Pair<>(cyclingDistanceSpeed.getValue().getSpeed(), cyclingDistanceSpeed.getSensorNameOrAddress());
|
||||
}
|
||||
|
||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().getSpeed() != null) {
|
||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().speed() != null) {
|
||||
return new Pair<>(runningDistanceSpeedCadence.getSpeed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public final class SensorDataSet {
|
||||
}
|
||||
|
||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) {
|
||||
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue().getDistance());
|
||||
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue().distance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user