forked from upstream-mirrors/OpenTracks
@@ -50,8 +50,8 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.io.file.exporter.ExportServiceResultReceiver;
|
||||
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||
import de.dennisguse.opentracks.services.sensors.ElevationSumManager;
|
||||
import de.dennisguse.opentracks.services.tasks.AnnouncementPeriodicTaskFactory;
|
||||
import de.dennisguse.opentracks.services.tasks.PeriodicTaskExecutor;
|
||||
import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||
@@ -109,7 +109,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
// The following variables are set when recording:
|
||||
private WakeLock wakeLock;
|
||||
private BluetoothRemoteSensorManager remoteSensorManager;
|
||||
private ElevationSumManager elevationSumManager;
|
||||
private AltitudeSumManager altitudeSumManager;
|
||||
|
||||
private TrackStatisticsUpdater trackStatisticsUpdater;
|
||||
private TrackPoint lastTrackPoint;
|
||||
@@ -159,9 +159,9 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
remoteSensorManager = null;
|
||||
}
|
||||
|
||||
if (elevationSumManager != null) {
|
||||
elevationSumManager.stop(this);
|
||||
elevationSumManager = null;
|
||||
if (altitudeSumManager != null) {
|
||||
altitudeSumManager.stop(this);
|
||||
altitudeSumManager = null;
|
||||
}
|
||||
|
||||
// Reverse order from onCreate
|
||||
@@ -340,8 +340,8 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
remoteSensorManager = new BluetoothRemoteSensorManager(this);
|
||||
remoteSensorManager.start();
|
||||
|
||||
elevationSumManager = new ElevationSumManager();
|
||||
elevationSumManager.start(this);
|
||||
altitudeSumManager = new AltitudeSumManager();
|
||||
altitudeSumManager.start(this);
|
||||
|
||||
lastTrackPoint = null;
|
||||
isIdle = false;
|
||||
@@ -434,9 +434,9 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
remoteSensorManager.stop();
|
||||
remoteSensorManager = null;
|
||||
}
|
||||
if (elevationSumManager != null) {
|
||||
elevationSumManager.stop(this);
|
||||
elevationSumManager = null;
|
||||
if (altitudeSumManager != null) {
|
||||
altitudeSumManager.stop(this);
|
||||
altitudeSumManager = null;
|
||||
}
|
||||
|
||||
lastTrackPoint = null;
|
||||
@@ -592,10 +592,10 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
*/
|
||||
private void insertTrackPoint(@NonNull Track track, @NonNull TrackPoint trackPoint) {
|
||||
try {
|
||||
if (elevationSumManager != null) {
|
||||
trackPoint.setElevationGain(elevationSumManager.getElevationGain_m());
|
||||
trackPoint.setElevationLoss(elevationSumManager.getElevationLoss_m());
|
||||
elevationSumManager.reset();
|
||||
if (altitudeSumManager != null) {
|
||||
trackPoint.setAltitudeGain(altitudeSumManager.getAltitudeGain_m());
|
||||
trackPoint.setAltitudeLoss(altitudeSumManager.getAltitudeLoss_m());
|
||||
altitudeSumManager.reset();
|
||||
}
|
||||
if (remoteSensorManager != null) {
|
||||
fillWithSensorDataSet(trackPoint);
|
||||
@@ -632,25 +632,25 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative elevation gain (since last trackpoint).
|
||||
* Returns the relative altitude gain (since last trackpoint).
|
||||
*/
|
||||
Float getElevationGain_m() {
|
||||
if (elevationSumManager == null || !elevationSumManager.isConnected()) {
|
||||
Float getAltitudeGain_m() {
|
||||
if (altitudeSumManager == null || !altitudeSumManager.isConnected()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return elevationSumManager.getElevationGain_m();
|
||||
return altitudeSumManager.getAltitudeGain_m();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative elevation loss (since last trackpoint).
|
||||
* Returns the relative altitude loss (since last trackpoint).
|
||||
*/
|
||||
Float getElevationLoss_m() {
|
||||
if (elevationSumManager == null || !elevationSumManager.isConnected()) {
|
||||
Float getAltitudeLoss_m() {
|
||||
if (altitudeSumManager == null || !altitudeSumManager.isConnected()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return elevationSumManager.getElevationLoss_m();
|
||||
return altitudeSumManager.getAltitudeLoss_m();
|
||||
}
|
||||
|
||||
private void showNotification(boolean isGpsStarted) {
|
||||
|
||||
@@ -98,13 +98,13 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getElevationGain_m() {
|
||||
return trackRecordingService.getElevationGain_m();
|
||||
public Float getAltitudeGain_m() {
|
||||
return trackRecordingService.getAltitudeGain_m();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getElevationLoss_m() {
|
||||
return trackRecordingService.getElevationLoss_m();
|
||||
public Float getAltitudeLoss_m() {
|
||||
return trackRecordingService.getAltitudeLoss_m();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -74,18 +74,18 @@ public interface TrackRecordingServiceInterface {
|
||||
SensorDataSet getSensorData();
|
||||
|
||||
/**
|
||||
* Gets the current elevation gain.
|
||||
* Gets the current altitude gain.
|
||||
*
|
||||
* @return elevation gain in m or null.
|
||||
* @return altitude gain in m or null.
|
||||
*/
|
||||
Float getElevationGain_m();
|
||||
Float getAltitudeGain_m();
|
||||
|
||||
/**
|
||||
* Gets the current elevation loss.
|
||||
* Gets the current altitude loss.
|
||||
*
|
||||
* @return elevation loss in m or null.
|
||||
* @return altitude loss in m or null.
|
||||
*/
|
||||
Float getElevationLoss_m();
|
||||
Float getAltitudeLoss_m();
|
||||
|
||||
@VisibleForTesting
|
||||
void setRemoteSensorManager(BluetoothRemoteSensorManager remoteSensorManager);
|
||||
|
||||
+17
-17
@@ -14,11 +14,11 @@ import de.dennisguse.opentracks.util.PressureSensorUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
/**
|
||||
* Estimates the elevation gain and elevation loss using the device's pressure sensor (i.e., barometer).
|
||||
* Estimates the altitude gain and altitude loss using the device's pressure sensor (i.e., barometer).
|
||||
*/
|
||||
public class ElevationSumManager implements SensorEventListener {
|
||||
public class AltitudeSumManager implements SensorEventListener {
|
||||
|
||||
private static final String TAG = ElevationSumManager.class.getSimpleName();
|
||||
private static final String TAG = AltitudeSumManager.class.getSimpleName();
|
||||
|
||||
private static final int SAMPLING_RATE = 3 * (int) UnitConversions.ONE_SECOND_US;
|
||||
|
||||
@@ -28,8 +28,8 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
|
||||
private float lastSeenSensorValue_hPa;
|
||||
|
||||
private float elevationGain_m;
|
||||
private float elevationLoss_m;
|
||||
private float altitudeGain_m;
|
||||
private float altitudeLoss_m;
|
||||
|
||||
public void start(Context context) {
|
||||
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
@@ -66,19 +66,19 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
}
|
||||
|
||||
public @Nullable
|
||||
Float getElevationGain_m() {
|
||||
return isConnected ? elevationGain_m : null;
|
||||
Float getAltitudeGain_m() {
|
||||
return isConnected ? altitudeGain_m : null;
|
||||
}
|
||||
|
||||
public @Nullable
|
||||
Float getElevationLoss_m() {
|
||||
return isConnected ? elevationLoss_m : null;
|
||||
Float getAltitudeLoss_m() {
|
||||
return isConnected ? altitudeLoss_m : null;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
Log.d(TAG, "Reset");
|
||||
elevationGain_m = 0;
|
||||
elevationLoss_m = 0;
|
||||
altitudeGain_m = 0;
|
||||
altitudeLoss_m = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,15 +103,15 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
return;
|
||||
}
|
||||
|
||||
PressureSensorUtils.ElevationChange elevationChange = PressureSensorUtils.computeChangesWithSmoothing_m(lastAcceptedPressureValue_hPa, lastSeenSensorValue_hPa, value_hPa);
|
||||
if (elevationChange != null) {
|
||||
elevationGain_m += elevationChange.getElevationGain_m();
|
||||
elevationLoss_m += elevationChange.getElevationLoss_m();
|
||||
lastAcceptedPressureValue_hPa = elevationChange.getCurrentSensorValue_hPa();
|
||||
PressureSensorUtils.AltitudeChange altitudeChange = PressureSensorUtils.computeChangesWithSmoothing_m(lastAcceptedPressureValue_hPa, lastSeenSensorValue_hPa, value_hPa);
|
||||
if (altitudeChange != null) {
|
||||
altitudeGain_m += altitudeChange.getAltitudeGain_m();
|
||||
altitudeLoss_m += altitudeChange.getAltitudeLoss_m();
|
||||
lastAcceptedPressureValue_hPa = altitudeChange.getCurrentSensorValue_hPa();
|
||||
}
|
||||
|
||||
lastSeenSensorValue_hPa = value_hPa;
|
||||
|
||||
Log.v(TAG, "elevation gain: " + elevationGain_m + ", elevation loss: " + elevationLoss_m);
|
||||
Log.v(TAG, "altitude gain: " + altitudeGain_m + ", altitude loss: " + altitudeLoss_m);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user