refactor: dedup persistence header, harden action menu, tidy small items

- Persist.h: shared writeHeader()/readHeader() for the magic+version+count
  on-disk header; Waypoint and Trail snapshots now share one implementation
  (byte layout unchanged; each keeps its own count clamp/reject + extra fields).
- TrailScreen: pushAction() guards _act_map / PopupMenu capacity, so adding a
  new action can't silently overrun the fixed array.
- PopupMenu: add count()/setSelected() accessors; replace the remaining direct
  _sel/_count field pokes in NearbyScreen, TrailScreen and QuickMsgScreen.
- Trail summary: unit-suffixed time ("1h 05m" / "5m 03s") so hours can't be
  misread as minutes.
- Trail::haversineMeters delegates to geo::haversineKm — single Haversine
  implementation (also trims a little flash).

Verified: GAT562 (SSD1306) and WioTrackerL1Eink (GxEPD) solo builds compile clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekZegare4
2026-06-14 13:37:03 +02:00
co-authored by Claude Sonnet 4.6
parent 151892e1ce
commit b8a7b5dcc0
7 changed files with 85 additions and 83 deletions
+3 -15
View File
@@ -6,6 +6,7 @@
#include <Arduino.h>
#include <string.h>
#include "Persist.h"
static const uint8_t WAYPOINT_LABEL_LEN = 12; // incl. NUL → 11 visible chars
@@ -54,13 +55,7 @@ public:
template <typename F>
bool writeTo(F& file) {
uint32_t magic = SAVE_MAGIC;
uint8_t ver = SAVE_VERSION, res = 0;
uint16_t cnt = (uint16_t)_count;
if (file.write((uint8_t*)&magic, sizeof(magic)) != sizeof(magic)) return false;
if (file.write(&ver, 1) != 1) return false;
if (file.write(&res, 1) != 1) return false;
if (file.write((uint8_t*)&cnt, sizeof(cnt)) != sizeof(cnt)) return false;
if (!persist::writeHeader(file, SAVE_MAGIC, SAVE_VERSION, (uint16_t)_count)) return false;
for (int i = 0; i < _count; i++) {
if (file.write((uint8_t*)&_wp[i], sizeof(Waypoint)) != sizeof(Waypoint)) return false;
}
@@ -69,15 +64,8 @@ public:
template <typename F>
bool readFrom(F& file) {
uint32_t magic = 0;
if (file.read((uint8_t*)&magic, sizeof(magic)) != (int)sizeof(magic)) return false;
if (magic != SAVE_MAGIC) return false;
uint8_t ver = 0, res = 0;
uint16_t cnt = 0;
if (file.read(&ver, 1) != 1) return false;
if (file.read(&res, 1) != 1) return false;
if (file.read((uint8_t*)&cnt, sizeof(cnt)) != (int)sizeof(cnt)) return false;
if (ver != SAVE_VERSION) return false;
if (!persist::readHeader(file, SAVE_MAGIC, SAVE_VERSION, cnt)) return false;
if (cnt > CAPACITY) cnt = CAPACITY;
_count = 0;
for (uint16_t i = 0; i < cnt; i++) {