forked from upstream-mirrors/OpenTracks
Created TemperatureHandler.
This commit is contained in:
@@ -51,7 +51,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
private final TrackPointCreator observer;
|
private final TrackPointCreator observer;
|
||||||
|
|
||||||
private HeartRateHandler heartRateHandler;
|
private HeartRateHandler heartRateHandler;
|
||||||
private BluetoothConnectionManager temperatureManager;
|
private TemperatureHandler temperatureHandler;
|
||||||
private BluetoothConnectionManager cyclingCadenceManager;
|
private BluetoothConnectionManager cyclingCadenceManager;
|
||||||
private BluetoothConnectionManager cyclingSpeedManager;
|
private BluetoothConnectionManager cyclingSpeedManager;
|
||||||
private BluetoothConnectionManager cyclingPowerManager;
|
private BluetoothConnectionManager cyclingPowerManager;
|
||||||
@@ -76,11 +76,11 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
|
|
||||||
gpsManager = new GpsManager(observer, this);
|
gpsManager = new GpsManager(observer, this);
|
||||||
altitudeSumManager = new GainManager(this);
|
altitudeSumManager = new GainManager(this);
|
||||||
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(context);
|
|
||||||
this.heartRateHandler = new HeartRateHandler(this);
|
this.heartRateHandler = new HeartRateHandler(this);
|
||||||
|
this.temperatureHandler = new TemperatureHandler(this);
|
||||||
|
|
||||||
|
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(context);
|
||||||
new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerHeartRate());
|
new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerHeartRate());
|
||||||
this.temperatureManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerTemperature());
|
|
||||||
this.cyclingCadenceManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingCadence());
|
this.cyclingCadenceManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingCadence());
|
||||||
this.cyclingSpeedManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingDistanceSpeed());
|
this.cyclingSpeedManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingDistanceSpeed());
|
||||||
this.cyclingPowerManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingPower());
|
this.cyclingPowerManager = new BluetoothConnectionManager(bluetoothAdapter, this, new BluetoothHandlerCyclingPower());
|
||||||
@@ -88,6 +88,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
|
|
||||||
altitudeSumManager.start(context, handler);
|
altitudeSumManager.start(context, handler);
|
||||||
heartRateHandler.start(context, handler);
|
heartRateHandler.start(context, handler);
|
||||||
|
temperatureHandler.start(context, handler);
|
||||||
onSharedPreferenceChanged(null, null);
|
onSharedPreferenceChanged(null, null);
|
||||||
|
|
||||||
gpsManager.start(context, handler);
|
gpsManager.start(context, handler);
|
||||||
@@ -99,8 +100,8 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
heartRateHandler.stop();
|
heartRateHandler.stop();
|
||||||
heartRateHandler = null;
|
heartRateHandler = null;
|
||||||
|
|
||||||
temperatureManager.disconnect();
|
temperatureHandler.stop();
|
||||||
temperatureManager = null;
|
temperatureHandler = null;
|
||||||
|
|
||||||
cyclingCadenceManager.disconnect();
|
cyclingCadenceManager.disconnect();
|
||||||
cyclingCadenceManager = null;
|
cyclingCadenceManager = null;
|
||||||
@@ -135,7 +136,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
Log.i(TAG, "Resetting data");
|
Log.i(TAG, "Resetting data");
|
||||||
|
|
||||||
if (heartRateHandler.getAggregator() != null) heartRateHandler.getAggregator().resetAggregated();
|
if (heartRateHandler.getAggregator() != null) heartRateHandler.getAggregator().resetAggregated();
|
||||||
if (temperature != null) temperature.resetAggregated();
|
if (temperatureHandler.getAggregator() != null) temperatureHandler.getAggregator().resetAggregated();
|
||||||
if (cyclingCadence != null) cyclingCadence.resetAggregated();
|
if (cyclingCadence != null) cyclingCadence.resetAggregated();
|
||||||
if (cyclingDistanceSpeed != null) cyclingDistanceSpeed.resetAggregated();
|
if (cyclingDistanceSpeed != null) cyclingDistanceSpeed.resetAggregated();
|
||||||
if (cyclingPower != null) cyclingPower.resetAggregated();
|
if (cyclingPower != null) cyclingPower.resetAggregated();
|
||||||
@@ -177,9 +178,8 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
heartRateHandler.connect();
|
heartRateHandler.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PreferencesUtils.isKey(R.string.settings_sensor_bluetooth_temperature_key, key)) {
|
if (PreferencesUtils.isKey(temperatureHandler.getSensorPreferenceKey(), key)) {
|
||||||
String address = PreferencesUtils.getBluetoothTemperatureSensorAddress();
|
temperatureHandler.connect();
|
||||||
connect(temperatureManager, address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PreferencesUtils.isKey(R.string.settings_sensor_bluetooth_cycling_cadence_key, key)) {
|
if (PreferencesUtils.isKey(R.string.settings_sensor_bluetooth_cycling_cadence_key, key)) {
|
||||||
@@ -227,9 +227,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
return observer.getNow();
|
return observer.getNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public AggregatorTemperature temperature;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public AggregatorCyclingCadence cyclingCadence;
|
public AggregatorCyclingCadence cyclingCadence;
|
||||||
|
|
||||||
@@ -300,6 +297,10 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
heartRateHandler.setAggregator((AggregatorHeartRate) data);
|
heartRateHandler.setAggregator((AggregatorHeartRate) data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (data instanceof AggregatorTemperature) {
|
||||||
|
temperatureHandler.setAggregator((AggregatorTemperature) data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
set(data, data);
|
set(data, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,11 +319,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
private void update(@NonNull Record value) {
|
private void update(@NonNull Record value) {
|
||||||
Instant now = getNow();
|
Instant now = getNow();
|
||||||
|
|
||||||
if (value instanceof Temperature) {
|
|
||||||
this.temperature.add(now, (Temperature) value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value instanceof BluetoothHandlerCyclingCadence.CrankData) {
|
if (value instanceof BluetoothHandlerCyclingCadence.CrankData) {
|
||||||
this.cyclingCadence.add(now, (BluetoothHandlerCyclingCadence.CrankData) value);
|
this.cyclingCadence.add(now, (BluetoothHandlerCyclingCadence.CrankData) value);
|
||||||
return;
|
return;
|
||||||
@@ -354,7 +350,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void clear() {
|
public void clear() {
|
||||||
Log.i(TAG, "Removing all aggregators");
|
Log.i(TAG, "Removing all aggregators");
|
||||||
this.temperature = null;
|
|
||||||
this.cyclingCadence = null;
|
this.cyclingCadence = null;
|
||||||
this.cyclingDistanceSpeed = null;
|
this.cyclingDistanceSpeed = null;
|
||||||
this.cyclingPower = null;
|
this.cyclingPower = null;
|
||||||
@@ -367,6 +362,9 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
if (this.heartRateHandler != null) {
|
if (this.heartRateHandler != null) {
|
||||||
this.heartRateHandler.setAggregator(null);
|
this.heartRateHandler.setAggregator(null);
|
||||||
}
|
}
|
||||||
|
if (this.temperatureHandler != null) {
|
||||||
|
this.temperatureHandler.setAggregator(null);
|
||||||
|
}
|
||||||
if (this.gpsManager != null) {
|
if (this.gpsManager != null) {
|
||||||
this.gpsManager.setAggregatorGPS();
|
this.gpsManager.setAggregatorGPS();
|
||||||
}
|
}
|
||||||
@@ -381,7 +379,7 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
getSpeed(now),
|
getSpeed(now),
|
||||||
getDistance(now),
|
getDistance(now),
|
||||||
getHeartRate(now),
|
getHeartRate(now),
|
||||||
temperature != null && temperature.hasReceivedData() ? temperature.getAggregatedValueWithSensorName(now) : null,
|
temperatureHandler.getAggregator() != null && temperatureHandler.getAggregator().hasReceivedData() ? (SensorData<Temperature>) temperatureHandler.getAggregator().getAggregatedValueWithSensorName(now) : null,
|
||||||
getCadence(now),
|
getCadence(now),
|
||||||
cyclingPower != null && cyclingPower.hasReceivedData() ? cyclingPower.getAggregatedValueWithSensorName(now) : null,
|
cyclingPower != null && cyclingPower.hasReceivedData() ? cyclingPower.getAggregatedValueWithSensorName(now) : null,
|
||||||
barometer != null && barometer.hasReceivedData() ? barometer.getAggregatedValueWithSensorName(now) : null
|
barometer != null && barometer.hasReceivedData() ? barometer.getAggregatedValueWithSensorName(now) : null
|
||||||
@@ -392,10 +390,6 @@ public class SensorManager implements SharedPreferences.OnSharedPreferenceChange
|
|||||||
private void set(@NonNull Aggregator<?, ?> type, @Nullable Aggregator<?, ?> sensorData) {
|
private void set(@NonNull Aggregator<?, ?> type, @Nullable Aggregator<?, ?> sensorData) {
|
||||||
Log.i(TAG, "Setting aggregator " + type.getClass().getCanonicalName() + " to " + sensorData);
|
Log.i(TAG, "Setting aggregator " + type.getClass().getCanonicalName() + " to " + sensorData);
|
||||||
|
|
||||||
if (type instanceof AggregatorTemperature) {
|
|
||||||
temperature = (AggregatorTemperature) sensorData;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type instanceof AggregatorCyclingCadence) {
|
if (type instanceof AggregatorCyclingCadence) {
|
||||||
cyclingCadence = (AggregatorCyclingCadence) sensorData;
|
cyclingCadence = (AggregatorCyclingCadence) sensorData;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.dennisguse.opentracks.sensors;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.data.models.Temperature;
|
||||||
|
import de.dennisguse.opentracks.sensors.driver.Driver;
|
||||||
|
import de.dennisguse.opentracks.sensors.driver.DriverObserver0;
|
||||||
|
import de.dennisguse.opentracks.sensors.sensorData.Aggregator;
|
||||||
|
import de.dennisguse.opentracks.sensors.sensorData.AggregatorTemperature;
|
||||||
|
|
||||||
|
public class TemperatureHandler extends SensorHandler<Temperature> {
|
||||||
|
|
||||||
|
protected TemperatureHandler(SensorManager sensorManager) {
|
||||||
|
super(sensorManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected Driver createDriverBluetooth(String address) {
|
||||||
|
return new BluetoothConnectionManager(
|
||||||
|
BluetoothUtils.getAdapter(getContext()),
|
||||||
|
new DriverObserver0() {
|
||||||
|
@Override
|
||||||
|
public void onConnect(Aggregator<?, ?> emptySensorData) {
|
||||||
|
driverObserver.onConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect(Aggregator<?, ?> emptySensorData) {
|
||||||
|
driverObserver.onDisconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemove(Aggregator<?, ?> emptySensorData) {
|
||||||
|
driverObserver.onRemove();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(Record value) {
|
||||||
|
driverObserver.onData((Temperature) value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BluetoothHandlerTemperature()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
protected Aggregator<Temperature, ?> createAggregator() {
|
||||||
|
return new AggregatorTemperature("", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getSensorPreferenceKey() {
|
||||||
|
return R.string.settings_sensor_bluetooth_temperature_key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -264,14 +264,6 @@ public class PreferencesUtils {
|
|||||||
.orElse(SensorType.REMOTE);
|
.orElse(SensorType.REMOTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBluetoothHeartRateSensorAddress() {
|
|
||||||
return getString(R.string.settings_sensor_bluetooth_heart_rate_key, getBluetoothSensorAddressNone());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBluetoothTemperatureSensorAddress() {
|
|
||||||
return getString(R.string.settings_sensor_bluetooth_temperature_key, getBluetoothSensorAddressNone());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getBluetoothCyclingCadenceSensorAddress() {
|
public static String getBluetoothCyclingCadenceSensorAddress() {
|
||||||
return getString(R.string.settings_sensor_bluetooth_cycling_cadence_key, getBluetoothSensorAddressNone());
|
return getString(R.string.settings_sensor_bluetooth_cycling_cadence_key, getBluetoothSensorAddressNone());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user