feat(companion): clock tools — alarm, countdown timer, stopwatch

Add a Clock Tools screen (Enter on the home Clock page) with three time
utilities, plus the engine that drives them from UITask::loop() so they
work regardless of the current screen / display state:

- Alarm: a single one-shot wake alarm. Persisted in NodePrefs as a local
  time-of-day; UITask schedules it as an ABSOLUTE fire instant recomputed
  from that time, so it survives RTC re-syncs (mesh/app/GPS/CLI all jump
  the clock) — small corrections still fire on time, a jump over the
  target still fires (late, up to 6 h). Disarms after firing. A bell
  icon signals an armed alarm on the clock face and the top status bar.
- Timer: a millis-based countdown (sync-immune), big HH:MM:SS readout,
  rings even when off-screen.
- Stopwatch: millis-based, keeps running in the background.

Numeric fields use the shared framework DigitEditor (digit-by-digit,
min/max enforced). The alarm/timer/ring engine lives in UITask alongside
the locator/live-share engines (no screen-cast for time-critical logic).

E-ink: live readouts refresh coarsely (and on any key); timing is exact
regardless, and the countdown's buzzer fires on time. Rings override mute
and are dismissed by any key (auto-stop after 1 min). Cannot wake from a
full Shutdown (CPU/RAM powered down).

NodePrefs: +alarm_on/alarm_hour/alarm_min (fit existing tail padding,
sizeof unchanged 2488), SCHEMA_SENTINEL 0xC0DE0016 -> 0xC0DE0017,
DataStore read/clamp/write in lockstep.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MarekZegare4
2026-06-30 09:01:03 +02:00
co-authored by Claude Opus 4.8
parent 59d1722207
commit 9ce04835da
7 changed files with 509 additions and 2 deletions
+13 -1
View File
@@ -270,6 +270,18 @@ struct NodePrefs { // persisted to file
// Index into gpsAvgSecs(). [Tools Trail Settings Mark avg]
uint8_t gps_avg_idx;
// Alarm clock — a single one-shot wake alarm, configured from the Clock page
// (Enter Alarm). Stored as a local time-of-day; the actual fire instant is
// (re)computed as an absolute time in tickBackground(), which is what makes it
// robust to RTC re-syncs: the mesh (every inbound packet), the companion app,
// GPS and the CLI can all jump getCurrentTime() at any moment, but an absolute
// target instant stays correct across small corrections and still fires (late)
// if the clock jumps over it. Fires once, then alarm_on clears. The minutnik
// (countdown) and stoper (stopwatch) are runtime-only and not persisted.
uint8_t alarm_on; // 0=off (default), 1=armed (one-shot)
uint8_t alarm_hour; // 0-23, local time
uint8_t alarm_min; // 0-59
// Single source of truth for the live-share option tables (shared by the Map
// UI labels and the auto-send engine in UITask).
static const uint8_t LOC_SHARE_MOVE_COUNT = 4;
@@ -332,7 +344,7 @@ struct NodePrefs { // persisted to file
// adding/removing/reordering fields in DataStore::savePrefs/loadPrefsInt so
// older saves are detected on load and skipped (zero-init defaults kept).
// High 24 bits identify the file format; low byte is the schema revision.
static const uint32_t SCHEMA_SENTINEL = 0xC0DE0016;
static const uint32_t SCHEMA_SENTINEL = 0xC0DE0017;
// Bit-index for each home page. Used by page_order (entries store bit+1) and
// by home_pages_mask. Single source of truth — both HomeScreen::pageBit/bitToPage