mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-06 19:43:06 +02:00
Bluetooth LE: implemented cycling cadence and speed sensors.
Cadence is working while speed still requires the wheel size.
This commit is contained in:
@@ -20,8 +20,6 @@ import android.location.LocationManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
|
||||
/**
|
||||
* This class extends the standard Android location with extra information.
|
||||
*
|
||||
@@ -39,17 +37,17 @@ public class TrackPoint {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public TrackPoint(@NonNull Location location, SensorDataSet sensorDataSet) {
|
||||
public TrackPoint(@NonNull Location location, TrackPointSensorDataSet sensorDataSet) {
|
||||
this.location = location;
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
public TrackPoint(@NonNull TrackPoint trackPoint, SensorDataSet sensorDataSet) {
|
||||
public TrackPoint(@NonNull TrackPoint trackPoint, TrackPointSensorDataSet sensorDataSet) {
|
||||
this.location = trackPoint.getLocation();
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
private SensorDataSet sensorDataSet = null;
|
||||
private TrackPointSensorDataSet sensorDataSet = null;
|
||||
|
||||
public TrackPoint(double latitude, double longitude, Double altitude, long time) {
|
||||
location = new Location(LocationManager.GPS_PROVIDER);
|
||||
@@ -90,11 +88,11 @@ public class TrackPoint {
|
||||
return location;
|
||||
}
|
||||
|
||||
public SensorDataSet getSensorDataSet() {
|
||||
public TrackPointSensorDataSet getSensorDataSet() {
|
||||
return sensorDataSet;
|
||||
}
|
||||
|
||||
public void setSensorDataSet(SensorDataSet sensorDataSet) {
|
||||
public void setSensorDataSet(TrackPointSensorDataSet sensorDataSet) {
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package de.dennisguse.opentracks.content.data;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
//TODO Rename.
|
||||
public final class TrackPointSensorDataSet {
|
||||
private long time_ms;
|
||||
|
||||
private Float heartRate_bpm = null;
|
||||
private Float cyclingCadence = null;
|
||||
private Float cyclingSpeed = null;
|
||||
private Float power = null;
|
||||
|
||||
public TrackPointSensorDataSet() {
|
||||
this(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public TrackPointSensorDataSet(long time_ms) {
|
||||
this.time_ms = time_ms;
|
||||
}
|
||||
|
||||
public boolean hasHeartRate() {
|
||||
return heartRate_bpm != null && heartRate_bpm > 0;
|
||||
}
|
||||
|
||||
public float getHeartRate_bpm() {
|
||||
return heartRate_bpm;
|
||||
}
|
||||
|
||||
public void setHeartRate_bpm(Float heartRate_bpm) {
|
||||
this.heartRate_bpm = heartRate_bpm;
|
||||
}
|
||||
|
||||
public boolean hasCyclingCadence() {
|
||||
return cyclingCadence != null;
|
||||
}
|
||||
|
||||
public Float getCyclingCadence_rpm() {
|
||||
return cyclingCadence;
|
||||
}
|
||||
|
||||
public void setCyclingCadence(Float cyclingCadence) {
|
||||
this.cyclingCadence = cyclingCadence;
|
||||
}
|
||||
|
||||
public void setCyclingCadence(Integer cyclingCadence) {
|
||||
this.cyclingCadence = cyclingCadence != null ? cyclingCadence.floatValue() : null;
|
||||
}
|
||||
|
||||
public boolean hasCyclingSpeed() {
|
||||
return cyclingSpeed != null;
|
||||
}
|
||||
|
||||
public Float getCyclingSpeed() {
|
||||
return cyclingSpeed;
|
||||
}
|
||||
|
||||
public void setCyclingSpeed(Float cyclingSpeed) {
|
||||
this.cyclingSpeed = cyclingSpeed;
|
||||
}
|
||||
|
||||
public boolean hasPower() {
|
||||
return power != null;
|
||||
}
|
||||
|
||||
public Float getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Float power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
public void setTime(long time_ms) {
|
||||
this.time_ms = time_ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the data recent considering the current time.
|
||||
*
|
||||
* @param maxAge the maximal age in milliseconds.
|
||||
*/
|
||||
public boolean isRecent(long maxAge) {
|
||||
return time_ms + maxAge > System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "time=" + getTime()
|
||||
+ (hasHeartRate() ? " heart=" + getHeartRate_bpm() : "")
|
||||
+ (hasCyclingCadence() ? " cyclingCad=" + getCyclingCadence_rpm() : "")
|
||||
+ (hasCyclingSpeed() ? " cyclingSpeed=" + getCyclingSpeed() : "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user