Files
swiftcontrol/lib/utils/keymap/action_groups.dart
Jonas Acker c14c8d046d Zone mode engine: hold a limit in ERG, hand back to SIM
- ZoneModeEngine: once a second, 3 s power vs the range; outside it for
  the trigger time it holds the limit in sticky ERG (ramping up to a
  floor, straight to a ceiling) for the hold time, then hands back to the
  mode the rider came from (bump prop: exitErgMode can resume virtual
  shifting) and waits out 30 s. Pauses under 20 rpm, sleeps during ERG it
  did not set, yields to a rider who moves its target.
- Feedback: zone in/out chimes (own sound switch), phone buzz, toast, and
  a system notification while BikeControl is in the background
- "Trainer: Zone mode" button: back to SIM while holding, else on/off;
  shifts move the gear and SIM/ERG hands back while it holds; Power Lock's
  alert stays quiet for Zone mode's hold
- iOS Live Activity and PiP: ZONE pill with arrow, countdown, Back to SIM
- Controller loads its settings lazily

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 19:17:02 +01:00

120 lines
3.9 KiB
Dart

import 'package:bike_control/utils/keymap/buttons.dart';
/// What an action is for, the way a rider looks for it in the action picker:
/// by intent, not by the connection that carries it.
enum ActionGroup {
gears,
trainer,
workout,
ride,
navigate,
view,
controller,
system;
static ActionGroup of(InGameAction action) => switch (action) {
InGameAction.shiftUp ||
InGameAction.shiftDown ||
InGameAction.frontShift ||
InGameAction.gearSet => ActionGroup.gears,
InGameAction.trainerSwitchMode ||
InGameAction.zoneMode ||
InGameAction.trainerIntensityUp ||
InGameAction.trainerIntensityDown ||
InGameAction.increaseResistance ||
InGameAction.decreaseResistance ||
InGameAction.changeMode => ActionGroup.trainer,
InGameAction.workoutPauseResume ||
InGameAction.skipInterval ||
InGameAction.previousInterval ||
InGameAction.lap ||
InGameAction.pause ||
InGameAction.resume ||
InGameAction.takeBreak => ActionGroup.workout,
InGameAction.steerLeft ||
InGameAction.steerRight ||
InGameAction.uturn ||
InGameAction.tuck ||
InGameAction.brake ||
InGameAction.usePowerUp ||
InGameAction.rideOnBomb ||
InGameAction.kudos ||
InGameAction.emote ||
InGameAction.pushToTalk ||
InGameAction.joinRider ||
InGameAction.spectateRider ||
InGameAction.changeRoute => ActionGroup.ride,
InGameAction.up ||
InGameAction.down ||
InGameAction.navigateLeft ||
InGameAction.navigateRight ||
InGameAction.select ||
InGameAction.back ||
InGameAction.openActionBar ||
InGameAction.menu ||
InGameAction.home => ActionGroup.navigate,
InGameAction.cameraAngle || InGameAction.toggleUi || InGameAction.mapToggle => ActionGroup.view,
InGameAction.leftDropButton ||
InGameAction.rightDropButton ||
InGameAction.leftShiftButton2 ||
InGameAction.rightShiftButton2 => ActionGroup.controller,
InGameAction.headwindSpeed ||
InGameAction.headwindSpeedInc ||
InGameAction.headwindSpeedDec ||
InGameAction.headwindSpeedCyclicInc ||
InGameAction.headwindSpeedCyclicDec ||
InGameAction.headwindHeartRateMode ||
InGameAction.inclineIncrease ||
InGameAction.inclineDecrease ||
InGameAction.inclineZero ||
InGameAction.inclineAutoMode ||
InGameAction.calibratePhoneSteering ||
InGameAction.screenRecording => ActionGroup.system,
};
}
/// Where an action sits inside its group; anything not listed keeps the
/// order it came in, after these. Navigation reads like a d-pad.
const _displayOrder = <InGameAction>[
InGameAction.shiftUp,
InGameAction.shiftDown,
InGameAction.frontShift,
InGameAction.gearSet,
InGameAction.trainerSwitchMode,
InGameAction.zoneMode,
InGameAction.trainerIntensityUp,
InGameAction.trainerIntensityDown,
InGameAction.increaseResistance,
InGameAction.decreaseResistance,
InGameAction.changeMode,
InGameAction.workoutPauseResume,
InGameAction.pause,
InGameAction.resume,
InGameAction.skipInterval,
InGameAction.previousInterval,
InGameAction.lap,
InGameAction.takeBreak,
InGameAction.up,
InGameAction.down,
InGameAction.navigateLeft,
InGameAction.navigateRight,
InGameAction.select,
InGameAction.back,
];
/// [actions] (possibly offered by several connections, so with repeats)
/// sorted into their [ActionGroup]s, each action once, empty groups left out.
List<({ActionGroup group, List<InGameAction> actions})> groupActions(Iterable<InGameAction> actions) {
final unique = actions.toSet().toList();
int rank(InGameAction a) {
final i = _displayOrder.indexOf(a);
return i == -1 ? _displayOrder.length + unique.indexOf(a) : i;
}
return [
for (final group in ActionGroup.values)
if (unique.where((a) => ActionGroup.of(a) == group).toList() case final members when members.isNotEmpty)
(group: group, actions: members..sort((a, b) => rank(a).compareTo(rank(b)))),
];
}