mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-01 02:02:33 +01:00
fix(trainingpeaks): direction and face buttons now reach the app
The TPV profile mapped navigationUp and the coloured face buttons to a keyboard key / touch position only. _handleDirectConnect forwards a KeyPair solely when it carries an inGameAction, so those presses never left the phone — and an actionless default is worse than no default at all, because it shadows the action the button would otherwise inherit from ControllerButton.action via Keymap.addNewButtons (which is exactly why navigationDown, absent from the profile, worked). Same gap hit the HUD-toggle and difficulty defaults. Steer Left/Right are added to defaultObpSupportedButtons as well: TPV advertises them in its live app-info frame, but without them the button editor hid steering before a connection. Reported by a rider on Android with TPV on an iPad, whose log showed "Sent Down button press" next to "No connection method active". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,10 @@ class TrainingPeaks extends SupportedApp {
|
||||
0x14, // Select/Confirm
|
||||
0x15, // Back/Cancel
|
||||
0x16, // Menu
|
||||
// TPV advertises Steer Left/Right over OBP (seen in a live app-info frame);
|
||||
// without them here the button editor hides steering before a connection.
|
||||
0x18, // Steer Left
|
||||
0x19, // Steer Right
|
||||
0x21, // Push to Talk
|
||||
0x30, // Increase Difficulty
|
||||
0x31, // Decrease Difficulty
|
||||
@@ -129,32 +133,42 @@ class TrainingPeaks extends SupportedApp {
|
||||
buttons: [ZwiftButtons.navigationUp],
|
||||
physicalKey: PhysicalKeyboardKey.arrowUp,
|
||||
logicalKey: LogicalKeyboardKey.arrowUp,
|
||||
inGameAction: InGameAction.up,
|
||||
touchPosition: Offset(42.28406293368177, 92.61854987939971),
|
||||
),
|
||||
|
||||
// Face buttons with touch positions and keyboard fallbacks where sensible
|
||||
// Face buttons with touch positions and keyboard fallbacks where sensible.
|
||||
// Every entry needs its [InGameAction] too: a key/touch-only default is
|
||||
// strictly worse than no entry at all, because it shadows the action the
|
||||
// button would otherwise inherit from [ControllerButton.action] via
|
||||
// [Keymap.addNewButtons] — and only in-game actions reach TPV over OBP
|
||||
// (BLE / DirCon), which is the whole point on a second device.
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.z, EliteSquareButtons.z],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.pause,
|
||||
touchPosition: Offset(33.993890038715456, 92.43667306401531),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.a, EliteSquareButtons.a],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.select,
|
||||
touchPosition: Offset(47.37191097597044, 92.86963594239016),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.b, EliteSquareButtons.b],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.back,
|
||||
touchPosition: Offset(41.12364102683652, 83.72743323236598),
|
||||
),
|
||||
KeyPair(
|
||||
buttons: [ZwiftButtons.y, EliteSquareButtons.y],
|
||||
physicalKey: null,
|
||||
logicalKey: null,
|
||||
inGameAction: InGameAction.menu,
|
||||
touchPosition: Offset(58.52936866684111, 84.31131200977018),
|
||||
),
|
||||
|
||||
@@ -166,6 +180,7 @@ class TrainingPeaks extends SupportedApp {
|
||||
buttons: [b],
|
||||
physicalKey: PhysicalKeyboardKey.keyH,
|
||||
logicalKey: LogicalKeyboardKey.keyH,
|
||||
inGameAction: InGameAction.toggleUi,
|
||||
),
|
||||
),
|
||||
...ControllerButton.values
|
||||
@@ -175,6 +190,7 @@ class TrainingPeaks extends SupportedApp {
|
||||
buttons: [b],
|
||||
physicalKey: PhysicalKeyboardKey.pageUp,
|
||||
logicalKey: LogicalKeyboardKey.pageUp,
|
||||
inGameAction: InGameAction.increaseResistance,
|
||||
),
|
||||
),
|
||||
...ControllerButton.values
|
||||
@@ -184,6 +200,7 @@ class TrainingPeaks extends SupportedApp {
|
||||
buttons: [b],
|
||||
physicalKey: PhysicalKeyboardKey.pageDown,
|
||||
logicalKey: LogicalKeyboardKey.pageDown,
|
||||
inGameAction: InGameAction.decreaseResistance,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
65
test/utils/keymap/training_peaks_keymap_test.dart
Normal file
65
test/utils/keymap/training_peaks_keymap_test.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:bike_control/bluetooth/devices/elite/elite_square.dart';
|
||||
import 'package:bike_control/bluetooth/devices/zwift/constants.dart';
|
||||
import 'package:bike_control/utils/keymap/apps/training_peaks.dart';
|
||||
import 'package:bike_control/utils/keymap/buttons.dart';
|
||||
import 'package:bike_control/utils/keymap/keymap.dart';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// TrainingPeaks Virtual is reached over OpenBikeControl (BLE / DirCon), and
|
||||
/// `BaseActions._handleDirectConnect` only forwards a [KeyPair] that carries an
|
||||
/// [InGameAction]. A default that maps a button to a keyboard key or a touch
|
||||
/// position *only* is therefore worse than shipping no default at all: it
|
||||
/// shadows the action the button would otherwise inherit from
|
||||
/// [ControllerButton.action] via [Keymap.addNewButtons], and the press can
|
||||
/// never leave the phone.
|
||||
void main() {
|
||||
final app = TrainingPeaks();
|
||||
final supportedActions = app.defaultObpSupportedButtons.mapNotNull((b) => b.action).toSet();
|
||||
|
||||
test('every default key pair carries an in-game action', () {
|
||||
final actionless = app.keymap.keyPairs
|
||||
.where((k) => k.inGameAction == null)
|
||||
.expand((k) => k.buttons)
|
||||
.map((b) => b.name)
|
||||
.toList();
|
||||
|
||||
expect(actionless, isEmpty, reason: 'these buttons can never reach TPV over OBP: $actionless');
|
||||
});
|
||||
|
||||
test('every default in-game action is one TPV accepts over OBP', () {
|
||||
for (final keyPair in app.keymap.keyPairs) {
|
||||
expect(
|
||||
supportedActions,
|
||||
contains(keyPair.inGameAction),
|
||||
reason: '${keyPair.buttons.first.name} → ${keyPair.inGameAction} is not in defaultObpSupportedButtons',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('navigation and face buttons keep their conventional actions', () {
|
||||
InGameAction? actionFor(ControllerButton button) =>
|
||||
app.keymap.getKeyPair(button, trigger: ButtonTrigger.singleClick)?.inGameAction;
|
||||
|
||||
expect(actionFor(ZwiftButtons.navigationUp), InGameAction.up);
|
||||
expect(actionFor(ZwiftButtons.navigationLeft), InGameAction.steerLeft);
|
||||
expect(actionFor(ZwiftButtons.navigationRight), InGameAction.steerRight);
|
||||
expect(actionFor(ZwiftButtons.a), InGameAction.select);
|
||||
expect(actionFor(ZwiftButtons.b), InGameAction.back);
|
||||
expect(actionFor(ZwiftButtons.y), InGameAction.menu);
|
||||
expect(actionFor(ZwiftButtons.z), InGameAction.pause);
|
||||
|
||||
// The Elite Square shares the face-button key pairs.
|
||||
expect(actionFor(EliteSquareButtons.a), InGameAction.select);
|
||||
expect(actionFor(EliteSquareButtons.y), InGameAction.menu);
|
||||
});
|
||||
|
||||
test('navigation down inherits its default action instead of being shadowed', () {
|
||||
// Not in the profile at all — [Keymap.addNewButtons] seeds it from the
|
||||
// button itself when a controller connects. This is the behaviour the
|
||||
// explicit defaults above have to match.
|
||||
expect(app.keymap.getKeyPair(ZwiftButtons.navigationDown), isNull);
|
||||
expect(ZwiftButtons.navigationDown.action, InGameAction.down);
|
||||
expect(supportedActions, contains(InGameAction.down));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user