1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-20 20:10:15 +02:00

Mi Band 8: Fix send gps location during workout

This commit is contained in:
José Rebelo 2023-11-05 19:03:38 +00:00
parent dad97f9e96
commit fa20bf66c6
2 changed files with 27 additions and 11 deletions

View File

@ -425,7 +425,13 @@ public class XiaomiHealthService extends AbstractXiaomiService {
} }
private void handleWorkoutOpen(final XiaomiProto.WorkoutOpenWatch workoutOpenWatch) { private void handleWorkoutOpen(final XiaomiProto.WorkoutOpenWatch workoutOpenWatch) {
LOG.debug("Workout open on watch: {}", workoutOpenWatch.getSport()); LOG.debug(
"Workout open on watch: {}, workoutStarted={}, gpsStarted={}, gpsFixAcquired={}",
workoutOpenWatch.getSport(),
workoutStarted,
gpsStarted,
gpsFixAcquired
);
workoutStarted = false; workoutStarted = false;
@ -455,7 +461,12 @@ public class XiaomiHealthService extends AbstractXiaomiService {
gpsTimeoutHandler.removeCallbacksAndMessages(null); gpsTimeoutHandler.removeCallbacksAndMessages(null);
// Timeout if the watch stops sending workout open // Timeout if the watch stops sending workout open
gpsTimeoutHandler.postDelayed(() -> GBLocationManager.stop(getSupport().getContext(), getSupport()), 5000); gpsTimeoutHandler.postDelayed(() -> {
LOG.debug("Timed out waiting for workout");
gpsStarted = false;
gpsFixAcquired = false;
GBLocationManager.stop(getSupport().getContext(), getSupport());
}, 5000);
} }
private void handleWorkoutStatus(final XiaomiProto.WorkoutStatusWatch workoutStatus) { private void handleWorkoutStatus(final XiaomiProto.WorkoutStatusWatch workoutStatus) {
@ -475,6 +486,8 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case WORKOUT_PAUSED: case WORKOUT_PAUSED:
break; break;
case WORKOUT_FINISHED: case WORKOUT_FINISHED:
gpsStarted = false;
gpsFixAcquired = false;
GBLocationManager.stop(getSupport().getContext(), getSupport()); GBLocationManager.stop(getSupport().getContext(), getSupport());
if (startOnPhone) { if (startOnPhone) {
OpenTracksController.stopRecording(getSupport().getContext()); OpenTracksController.stopRecording(getSupport().getContext());
@ -495,26 +508,29 @@ public class XiaomiHealthService extends AbstractXiaomiService {
XiaomiProto.WorkoutOpenReply.newBuilder() XiaomiProto.WorkoutOpenReply.newBuilder()
.setUnknown1(0) .setUnknown1(0)
.setUnknown2(2) .setUnknown2(2)
.setUnknown3(10) .setUnknown3(2)
)) ))
.build() .build()
); );
} }
if (workoutStarted) { if (workoutStarted) {
final XiaomiProto.WorkoutLocation.Builder workoutLocation = XiaomiProto.WorkoutLocation.newBuilder() final XiaomiProto.WorkoutLocation.Builder workoutLocation = XiaomiProto.WorkoutLocation.newBuilder()
.setNumSatellites(10) .setUnknown1(2)
.setTimestamp((int) (location.getTime() / 1000L)) .setTimestamp((int) (location.getTime() / 1000L))
.setLongitude(location.getLongitude()) .setLongitude(location.getLongitude())
.setLatitude(location.getLatitude()) .setLatitude(location.getLatitude())
.setAltitude(location.getAltitude()) .setAltitude(location.getAltitude())
.setSpeed(location.getSpeed()) .setSpeed(location.getSpeed())
.setBearing(location.getBearing()) .setBearing(location.getBearing());
.setHorizontalAccuracy(location.getAccuracy());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // FIXME: Check the value for these during actual workouts, but it seems to work without them
workoutLocation.setVerticalAccuracy(location.getVerticalAccuracyMeters()); //if (location.hasAccuracy() && location.getAccuracy() != 100) {
} // workoutLocation.setHorizontalAccuracy(location.getAccuracy());
//}
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && location.hasVerticalAccuracy() && location.getVerticalAccuracyMeters() != 100) {
// workoutLocation.setVerticalAccuracy(location.getVerticalAccuracyMeters());
//}
getSupport().sendCommand( getSupport().sendCommand(
"send gps location", "send gps location",

View File

@ -485,7 +485,7 @@ message WorkoutOpenReply {
} }
message WorkoutLocation { message WorkoutLocation {
optional uint32 numSatellites = 1; // 10, sometimes 2? optional uint32 unknown1 = 1; // 10, sometimes 2?
optional uint32 timestamp = 2; // seconds optional uint32 timestamp = 2; // seconds
optional double longitude = 3; optional double longitude = 3;
optional double latitude = 4; optional double latitude = 4;