mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-20 07:14:34 +01:00
Remove the run/walk toggle: every recording uses the 25 km/h running filter and writes a Running TCX; decodeTcx still reads walking files. Add the optional pace target (stepper, 30 s current pace, band, throttled cues, persisted). The idle map follows the user's fix; refused location shows only the red icon, no map and no start. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZ9CKZsNxtD5Jr9bYD
49 lines
1.5 KiB
Dart
49 lines
1.5 KiB
Dart
/// The pace target's running state: current pace, band and throttled cues.
|
|
library;
|
|
|
|
import 'package:workout_app/models/run_track.dart';
|
|
import 'package:workout_app/services/pace_band.dart';
|
|
|
|
/// Tracks the current pace as accepted points arrive and fires [onCue] when
|
|
/// the runner is off the target (see [PaceCueThrottle]).
|
|
class PaceCoach {
|
|
/// Creates a coach with no target; [onCue] hears each cue that passes.
|
|
PaceCoach({this.onCue});
|
|
|
|
/// Called with the cue to give.
|
|
final void Function(PaceCue cue)? onCue;
|
|
|
|
final _throttle = PaceCueThrottle();
|
|
int _from = 0;
|
|
|
|
/// The target in seconds per kilometre, or null when off.
|
|
int? target;
|
|
|
|
/// Pace over the last 30 s of accepted fixes, once warmed up.
|
|
double? pace;
|
|
|
|
/// Where [pace] stands against [target]; null with no target or no pace.
|
|
PaceBand? get band =>
|
|
target == null ? null : paceBandOf(current: pace, target: target!);
|
|
|
|
/// Sets the target (null turns it off); the next off-pace fix cues at once.
|
|
void setTarget(int? seconds) {
|
|
target = seconds;
|
|
_throttle.reset();
|
|
}
|
|
|
|
/// Starts a fresh window at [index] (the first point after a resume), so
|
|
/// the time spent paused never reads as slow running.
|
|
void restartAt(int index) {
|
|
_from = index;
|
|
pace = null;
|
|
}
|
|
|
|
/// Folds in the newest of [points] (accepted, oldest first).
|
|
void update(List<RunPoint> points) {
|
|
pace = currentPaceSeconds(points, from: _from);
|
|
final cue = _throttle.cueFor(band, points.last.time);
|
|
if (cue != null) onCue?.call(cue);
|
|
}
|
|
}
|