live mission details in footer implemented
This commit is contained in:
@@ -26,3 +26,75 @@ MissionStats computeMissionStats(List<Waypoint> waypoints) {
|
||||
}
|
||||
return MissionStats(distanceM: totalDist, durationSec: totalDur);
|
||||
}
|
||||
|
||||
/// Live-Missionsstatus im Fly-Modus fuer die Details-Pille (Doku: "aktiver
|
||||
/// Wegpunkt (z.B. 3/23), Distanz und Zeit zum naechsten Wegpunkt" statt der
|
||||
/// statischen Plan-Werte). MSP liefert das nicht direkt - `MSP_COMP_GPS`
|
||||
/// gibt nur Distanz/Richtung zum HOME-Punkt (`GPS_distanceToHome`/
|
||||
/// `GPS_directionToHome`, iNAV `fc_msp.c`), und obwohl iNAV intern fuer sein
|
||||
/// eigenes OSD bereits eine Distanz zum aktiven Wegpunkt berechnet
|
||||
/// (`posControl.wpDistance`/`posControl.activeWaypointIndex`/
|
||||
/// `posControl.geoWaypointCount` in `navigation.c`/`osd.c`, Format dort
|
||||
/// exakt "TO WP %u/%u (%s)"), ist das ueber keine MSP-Nachricht abrufbar -
|
||||
/// deshalb hier aus der aktuellen Position + den ohnehin bekannten
|
||||
/// Wegpunktkoordinaten selbst berechnet.
|
||||
class FlyMissionStatus {
|
||||
const FlyMissionStatus({
|
||||
required this.activeWaypointNumber,
|
||||
required this.waypointCount,
|
||||
this.distanceToActiveWaypointM,
|
||||
this.etaToActiveWaypointSec,
|
||||
});
|
||||
|
||||
/// 1-basiert fuer die Anzeige ("3/23"), waehrend der uebergebene
|
||||
/// activeWaypointIndex-Parameter (TelemetryFrame.activeWaypointIndex)
|
||||
/// intern 0-basiert ist.
|
||||
final int activeWaypointNumber;
|
||||
final int waypointCount;
|
||||
|
||||
/// Null, solange keine gueltige Position bekannt ist (kein GPS-Fix).
|
||||
final double? distanceToActiveWaypointM;
|
||||
|
||||
/// Null, solange keine Distanz oder keine hinreichende Geschwindigkeit
|
||||
/// bekannt ist (Division durch (nahe) Null wuerde sonst eine bedeutungs-
|
||||
/// lose Restzeit vortaeuschen).
|
||||
final double? etaToActiveWaypointSec;
|
||||
}
|
||||
|
||||
/// Vergleiche Klassendoku [FlyMissionStatus]. Liefert null, solange keine
|
||||
/// Mission aktiv ist oder [activeWaypointIndex] (0-basiert) ausserhalb der
|
||||
/// Wegpunktliste liegt (z.B. kurz nach Missionsende).
|
||||
FlyMissionStatus? computeFlyMissionStatus({
|
||||
required List<Waypoint> waypoints,
|
||||
required int? activeWaypointIndex,
|
||||
double? currentLat,
|
||||
double? currentLon,
|
||||
double? currentSpeedMs,
|
||||
}) {
|
||||
if (activeWaypointIndex == null ||
|
||||
activeWaypointIndex < 0 ||
|
||||
activeWaypointIndex >= waypoints.length) {
|
||||
return null;
|
||||
}
|
||||
final target = waypoints[activeWaypointIndex];
|
||||
|
||||
double? distance;
|
||||
if (currentLat != null && currentLon != null) {
|
||||
distance = _distance(LatLng(currentLat, currentLon), LatLng(target.lat, target.lon));
|
||||
}
|
||||
|
||||
double? eta;
|
||||
// Unter 0.5 m/s waere eine aus der Distanz hochgerechnete Restzeit nur
|
||||
// Sekunden bis Minuten vor einer erfundenen "fast unendlich" Anzeige -
|
||||
// dann lieber "-" zeigen (siehe UI) statt eines irrefuehrenden Werts.
|
||||
if (distance != null && currentSpeedMs != null && currentSpeedMs > 0.5) {
|
||||
eta = distance / currentSpeedMs;
|
||||
}
|
||||
|
||||
return FlyMissionStatus(
|
||||
activeWaypointNumber: activeWaypointIndex + 1,
|
||||
waypointCount: waypoints.length,
|
||||
distanceToActiveWaypointM: distance,
|
||||
etaToActiveWaypointSec: eta,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user