Hide settings rows whose key the aircraft cannot read
The Mavic Pro remote reports GIMBAL_CONTROL_SPEED_COEFFICIENT as supported but fails every read, so "Gimbal dial speed" sat on "—" forever. The key bridge now reports a failed seeding read, and the row hides like an unsupported one until a value does arrive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a813648b75
commit
e3917e6f25
4 files changed
+31
-2
No files matched your search
@@ -113,7 +113,11 @@ class KeyBridge(private val ctx: BridgeCtx) : SubBridge {
|
|||||||
ctx.emit(mapOf("type" to "key", "id" to id, "value" to KeyValues.toDart(value)))
|
ctx.emit(mapOf("type" to "key", "id" to id, "value" to KeyValues.toDart(value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(error: DJIError) = Unit
|
// Supported but unreadable (the Mavic Pro remote's gimbal dial
|
||||||
|
// speed): say so, or the row waits on "—" forever.
|
||||||
|
override fun onFailure(error: DJIError) {
|
||||||
|
ctx.emit(mapOf("type" to "key", "id" to id, "unreadable" to true))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
result.success(id)
|
result.success(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,17 @@ class KeyState extends ChangeNotifier with SettingsOverlay {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A key the aircraft calls supported but will not read: hidden like an
|
||||||
|
/// unsupported one, until a value turns up after all.
|
||||||
|
void markUnreadable(String id) {
|
||||||
|
if (_supported[id] == false || reportedSettings.containsKey(id)) return;
|
||||||
|
_supported[id] = false;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
/// One `key` event: `{id, value}`.
|
/// One `key` event: `{id, value}`.
|
||||||
void apply(String id, Object? value) {
|
void apply(String id, Object? value) {
|
||||||
|
if (_supported[id] == false) _supported.remove(id);
|
||||||
replaceReported(<String, dynamic>{...reportedSettings, id: value});
|
replaceReported(<String, dynamic>{...reportedSettings, id: value});
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,12 @@ class TelemetryReducer {
|
|||||||
return true;
|
return true;
|
||||||
case 'key':
|
case 'key':
|
||||||
final String? id = asString(event['id']);
|
final String? id = asString(event['id']);
|
||||||
if (model.connected && id != null) model.keys.apply(id, event['value']);
|
if (!model.connected || id == null) return true;
|
||||||
|
if (event['unreadable'] == true) {
|
||||||
|
model.keys.markUnreadable(id);
|
||||||
|
} else {
|
||||||
|
model.keys.apply(id, event['value']);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
case 'mission':
|
case 'mission':
|
||||||
model.mission.apply(event);
|
model.mission.apply(event);
|
||||||
|
|||||||
@@ -146,6 +146,17 @@ void main() {
|
|||||||
expect(m.keys.value(SettingsKeys.novice), isNull);
|
expect(m.keys.value(SettingsKeys.novice), isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a supported key that cannot be read hides its row until a value arrives', () {
|
||||||
|
final FlightModel m = connectedModel(phantom4);
|
||||||
|
final TelemetryReducer r = TelemetryReducer(m);
|
||||||
|
m.keys.setSupported(SettingsKeys.gimbalDialSpeed, true);
|
||||||
|
r.apply(<String, dynamic>{'type': 'key', 'id': SettingsKeys.gimbalDialSpeed.id, 'unreadable': true});
|
||||||
|
expect(m.keys.supported(SettingsKeys.gimbalDialSpeed), isFalse);
|
||||||
|
r.apply(<String, dynamic>{'type': 'key', 'id': SettingsKeys.gimbalDialSpeed.id, 'value': 40});
|
||||||
|
expect(m.keys.supported(SettingsKeys.gimbalDialSpeed), isNot(isFalse));
|
||||||
|
expect(m.keys.value(SettingsKeys.gimbalDialSpeed), 40);
|
||||||
|
});
|
||||||
|
|
||||||
test('subscriptions listen only to supported keys and cancel on dispose', () async {
|
test('subscriptions listen only to supported keys and cancel on dispose', () async {
|
||||||
final FakeDjiService dji = FakeDjiService()..unsupportedKeys.add('ESC_BEEPING_ENABLED');
|
final FakeDjiService dji = FakeDjiService()..unsupportedKeys.add('ESC_BEEPING_ENABLED');
|
||||||
final KeyState s = KeyState();
|
final KeyState s = KeyState();
|
||||||
|
|||||||
Reference in new issue
Block a user