The GO 4-style HUD needs far more live data than the bridge sent, and pushing every SDK callback straight to Dart would rebuild the screen dozens of times a second. This is the telemetry foundation (plan P1). On the Kotlin side, every source now writes into a TelemetryHub that emits one telemetry event per tick: flight-controller state, gimbal and vision at up to 10 Hz, battery, links, RC, storage and camera settings folded in at up to 2 Hz. Each event carries the full latest snapshot, so a consumer that drops packets never loses a slow group. New bridges cover batteries (every pack, cell voltages, warning thresholds), link quality and RC battery, diagnostics, and obstacle sensing per sensor. KeyBridge adds generic getKey/setKey/listenKey over KeyManager for the settings rows to come. The flight controller also gains smart-RTH confirmation and simulator start/stop. On the Dart side, FlightModel now owns one ChangeNotifier per subsystem (aircraft, battery, links, camera, gimbal, vision, alerts, mission), so a HUD widget can listen to just the one it draws. TelemetryReducer routes events into them, only notifies groups that changed, and gives FlightModel one notification per tick. Flat getters keep the existing screens working. Diagnostics become graded, de-duplicated alerts. Settings > About > Telemetry inspector shows every field live and can start the simulator. Battery no longer arrives as its own event, so the API Server reads the percentage from the telemetry snapshot (the old event is still accepted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import 'package:flutter/foundation.dart';
|
||
|
||
import 'parse.dart';
|
||
|
||
/// Radio links and the remote controller's battery. Fed from the `links` and
|
||
/// `rc` groups of the telemetry tick (≤2 Hz).
|
||
class LinkState extends ChangeNotifier {
|
||
/// `ocusync` / `lightbridge` / `wifi` as the air link reports it at runtime.
|
||
String? kind;
|
||
|
||
/// RC → aircraft control-link quality, 0–100.
|
||
int? uplinkQuality;
|
||
|
||
/// Aircraft → RC video-link quality, 0–100.
|
||
int? downlinkQuality;
|
||
|
||
int? rcBatteryPercent;
|
||
int? rcBatteryMah;
|
||
bool? rcCharging;
|
||
|
||
DateTime? updatedAt;
|
||
|
||
/// 0–5 bars, the way the top bar draws a 0–100 quality.
|
||
static int bars(int? quality) => quality == null ? 0 : ((quality.clamp(0, 100) + 19) ~/ 20);
|
||
|
||
void apply({Map<String, dynamic>? links, Map<String, dynamic>? rc}) {
|
||
kind = asString(links?['kind']);
|
||
uplinkQuality = asInt(links?['uplinkQuality']);
|
||
downlinkQuality = asInt(links?['downlinkQuality']);
|
||
rcBatteryPercent = asInt(rc?['batteryPercent']);
|
||
rcBatteryMah = asInt(rc?['batteryMah']);
|
||
rcCharging = asBool(rc?['isCharging']);
|
||
updatedAt = DateTime.now();
|
||
notifyListeners();
|
||
}
|
||
|
||
void clear() {
|
||
kind = null;
|
||
uplinkQuality = downlinkQuality = rcBatteryPercent = rcBatteryMah = null;
|
||
rcCharging = null;
|
||
updatedAt = null;
|
||
notifyListeners();
|
||
}
|
||
}
|