Add per-routine target heart rate with live in-run indicator
Endurance routines (HIIT, cardio, cycling) can carry an optional target bpm (RoutineDocument.targetHeartRate, not schema-bumped — same preference-field rationale as restSeconds/autoAdvance), snapshotted onto the WorkoutDocument at plan time like the other pacing fields. During a run, the watch streams its live HR sample to the phone over a new best-effort liveHeartRate message — deliberately outside the LiveProgress machinery (no version bump, no staging/retry; a gauge, not a record), throttled to changed-bpm-or-10s in the watch bridge. LiveRunState holds the sample with a 30s staleness auto-clear so a dead stream never shows a frozen number. Both run screens show the reading only when the run carries a target: the phone's ExerciseProgressView as a top pill, the watch's in the top-trailing toolbar slot, each tinted by a shared ±5 bpm HeartRateBand with an arrow cue to push harder (low) or ease off (high) — e.g. dialing in a treadmill incline to hold a steady effort. Claude-Session: https://claude.ai/code/session_01Y7ZhkCYWNiTSAFhFCGnJ8n
This commit is contained in:
@@ -78,6 +78,31 @@ enum WorkoutActivityType: Int, CaseIterable, Codable, Sendable {
|
||||
case .mindAndBody: "figure.mind.and.body"
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a routine of this type can carry a target heart rate. Steady-state
|
||||
/// effort calibration ("raise the incline until you hit 140") only makes sense
|
||||
/// for the endurance types — a strength set's HR swings by design.
|
||||
var supportsHeartRateTarget: Bool {
|
||||
switch self {
|
||||
case .hiit, .cardio, .cycling: true
|
||||
default: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a live heart-rate reading sits relative to a routine's target rate, with a
|
||||
/// ±`tolerance` bpm dead band so the indicator doesn't flap around the boundary.
|
||||
/// Shared by the phone and watch run screens so both classify identically.
|
||||
enum HeartRateBand: Sendable {
|
||||
case low, inRange, high
|
||||
|
||||
static let tolerance = 5
|
||||
|
||||
init(bpm: Double, target: Int) {
|
||||
if bpm < Double(target - Self.tolerance) { self = .low }
|
||||
else if bpm > Double(target + Self.tolerance) { self = .high }
|
||||
else { self = .inRange }
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a workout's health metrics came from: real watch sensors, or — for records
|
||||
|
||||
Reference in New Issue
Block a user