feat(ui): GPS breadcrumb phase 1 — storage, sampling, Summary view

Adds Tools › Breadcrumb. Enter on the screen toggles tracking; while
active, UITask::loop samples GPS at the cadence chosen in settings
(default 1 min) and drops the point into a 256-entry RAM ring guarded
by a min-distance gate (default 25 m). A "G" indicator joins "A" in
the status bar with the same blink convention.

New storage:
- examples/companion_radio/Breadcrumb.h — BreadcrumbStore class
- 256 × 12 B = 3 KB RAM (survives auto-off, lost on reboot — explicit
  flash-slot save comes in phase 4)
- Haversine min-delta gate, total distance, elapsed seconds, current
  km/h, bounding-box helper

New screen:
- examples/companion_radio/ui-new/BreadcrumbScreen.h — Summary view
  with Status, Points, Dist (m or km), Time (h:mm), Speed; Enter
  toggles tracking, Esc returns to Tools

Schema bump 0xC0DE0002 → 0xC0DE0003 for two new NodePrefs bytes:
breadcrumb_interval_idx (1min default) and breadcrumb_min_delta_idx
(25m default). Older saves leave both at zero, which matches the new
defaults. DataStore::loadPrefsInt/savePrefs read/write the pair.

Logging on/off is a runtime flag inside BreadcrumbStore — not a
preference — so reboot returns to the off state cleanly; the user
will be able to persist a snapshot to a slot in phase 4.

Phase 2 (map view), 3 (point list), 4 (slot save/load, GPX export over
USB), and 5 (settings UI) follow incrementally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-25 08:22:12 +02:00
co-authored by Claude Sonnet 4.6
parent ccf45f0c0c
commit adef2fceb9
8 changed files with 289 additions and 7 deletions
@@ -0,0 +1,80 @@
#pragma once
// GPS breadcrumb viewer. Tools Breadcrumb.
// Phase 1: Summary view only. Phases 2/3 add Map and List views.
// Included by UITask.cpp after Breadcrumb store + ToolsScreen.
#include "../Breadcrumb.h"
class BreadcrumbScreen : public UIScreen {
UITask* _task;
BreadcrumbStore* _store;
public:
BreadcrumbScreen(UITask* task, BreadcrumbStore* store) : _task(task), _store(store) {}
void enter() { /* nothing to reset; live trail stays */ }
int render(DisplayDriver& display) override {
display.setTextSize(1);
display.setColor(DisplayDriver::LIGHT);
display.drawTextCentered(display.width() / 2, 0, "BREADCRUMB");
display.fillRect(0, display.headerH() - 1, display.width(), display.sepH());
const int y0 = display.listStart();
const int step = display.lineStep();
char buf[28];
// Status line: ON/OFF and point count.
snprintf(buf, sizeof(buf), "Status: %s",
_store->isActive() ? "tracking" : "stopped");
display.setCursor(2, y0);
display.print(buf);
snprintf(buf, sizeof(buf), "Points: %d / %d", _store->count(), BreadcrumbStore::CAPACITY);
display.setCursor(2, y0 + step);
display.print(buf);
// Distance — show m below 1 km, km otherwise.
uint32_t dist = _store->totalDistanceMeters();
if (dist < 1000) snprintf(buf, sizeof(buf), "Dist: %lu m", (unsigned long)dist);
else snprintf(buf, sizeof(buf), "Dist: %lu.%02lu km",
(unsigned long)(dist / 1000),
(unsigned long)((dist % 1000) / 10));
display.setCursor(2, y0 + step * 2);
display.print(buf);
// Elapsed — h:mm format.
uint32_t es = _store->elapsedSeconds();
snprintf(buf, sizeof(buf), "Time: %lu:%02lu",
(unsigned long)(es / 3600),
(unsigned long)((es % 3600) / 60));
display.setCursor(2, y0 + step * 3);
display.print(buf);
// Speed — current km/h.
snprintf(buf, sizeof(buf), "Speed: %u km/h", (unsigned)_store->currentSpeedKmh());
display.setCursor(2, y0 + step * 4);
display.print(buf);
// Hint at the bottom.
int hint_y = display.height() - step;
display.setCursor(2, hint_y);
display.print(_store->isActive() ? "[Ent] stop [Esc] back" : "[Ent] start [Esc] back");
return _store->isActive() ? 2000 : 5000;
}
bool handleInput(char c) override {
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
_task->gotoToolsScreen();
return true;
}
if (c == KEY_ENTER) {
_store->setActive(!_store->isActive());
_task->showAlert(_store->isActive() ? "Tracking started" : "Tracking stopped", 800);
return true;
}
return false;
}
};
@@ -6,7 +6,7 @@ class ToolsScreen : public UIScreen {
UITask* _task;
int _sel;
static const int ITEM_COUNT = 4;
static const int ITEM_COUNT = 5;
static const char* ITEMS[ITEM_COUNT];
public:
@@ -44,8 +44,9 @@ public:
if (_sel == 1) { _task->gotoBotScreen(); return true; }
if (_sel == 2) { _task->gotoNearbyScreen(); return true; }
if (_sel == 3) { _task->gotoAutoAdvertScreen(); return true; }
if (_sel == 4) { _task->gotoBreadcrumbScreen(); return true; }
}
return false;
}
};
const char* ToolsScreen::ITEMS[4] = { "Ringtone Editor", "Auto-Reply Bot", "Nearby Nodes", "Auto-Advert" };
const char* ToolsScreen::ITEMS[5] = { "Ringtone Editor", "Auto-Reply Bot", "Nearby Nodes", "Auto-Advert", "Breadcrumb" };
@@ -116,6 +116,7 @@ static const int QUICK_MSGS_MAX = 10;
#include "NearbyScreen.h"
#include "DashboardConfigScreen.h"
#include "AutoAdvertScreen.h"
#include "BreadcrumbScreen.h"
#include "ToolsScreen.h"
// ── HomeScreen ────────────────────────────────────────────────────────────────
@@ -401,6 +402,21 @@ class HomeScreen : public UIScreen {
}
leftmostX = aX - 1;
}
// "G" indicator — GPS breadcrumb logging active. Same blink convention.
if (_task->breadcrumb().isActive()) {
int gX = leftmostX - ind;
bool show_g = Features::BLINK_INDICATORS ? ((millis() % 4000) < 2000) : true;
if (show_g) {
display.setColor(DisplayDriver::LIGHT);
display.fillRect(gX, 0, ind, ind_h);
display.setColor(DisplayDriver::DARK);
display.setCursor(gX + 1, 0);
display.print("G");
display.setColor(DisplayDriver::LIGHT);
}
leftmostX = gX - 1;
}
}
return leftmostX;
}
@@ -1072,6 +1088,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
nearby_screen = new NearbyScreen(this);
dashboard_config = new DashboardConfigScreen(this, node_prefs);
auto_advert_screen = new AutoAdvertScreen(this, node_prefs);
breadcrumb_screen = new BreadcrumbScreen(this, &_breadcrumb);
applyBrightness();
applyFont();
applyRotation();
@@ -1108,6 +1125,11 @@ void UITask::gotoDashboardConfig() {
setCurrScreen(dashboard_config);
}
void UITask::gotoBreadcrumbScreen() {
((BreadcrumbScreen*)breadcrumb_screen)->enter();
setCurrScreen(breadcrumb_screen);
}
void UITask::gotoAutoAdvertScreen() {
((AutoAdvertScreen*)auto_advert_screen)->enter();
setCurrScreen(auto_advert_screen);
@@ -1724,6 +1746,22 @@ void UITask::loop() {
}
next_batt_chck = millis() + 8000;
}
// GPS breadcrumb sampling — runs in the background while the trail is
// active, independent of which screen is shown. Skips silently if no GPS
// fix; min-delta gate inside addPoint() avoids near-stationary spam.
if (_breadcrumb.isActive() && _node_prefs != NULL
&& (int32_t)(millis() - _next_breadcrumb_sample_ms) >= 0) {
uint16_t interval_s = BreadcrumbStore::intervalSecs(_node_prefs->breadcrumb_interval_idx);
_next_breadcrumb_sample_ms = millis() + (uint32_t)interval_s * 1000UL;
LocationProvider* loc = _sensors ? _sensors->getLocationProvider() : nullptr;
if (loc && loc->isValid()) {
uint16_t md = BreadcrumbStore::minDeltaMeters(_node_prefs->breadcrumb_min_delta_idx);
_breadcrumb.addPoint((int32_t)loc->getLatitude(),
(int32_t)loc->getLongitude(),
(uint32_t)rtc_clock.getCurrentTime(), md);
}
}
}
char UITask::checkDisplayOn(char c) {
+6
View File
@@ -22,6 +22,7 @@
#include "../AbstractUITask.h"
#include "../NodePrefs.h"
#include "../Breadcrumb.h"
class UITask : public AbstractUITask {
DisplayDriver* _display;
@@ -73,8 +74,11 @@ class UITask : public AbstractUITask {
UIScreen* nearby_screen;
UIScreen* dashboard_config;
UIScreen* auto_advert_screen;
UIScreen* breadcrumb_screen;
UIScreen* curr;
CayenneLPP _dash_lpp;
BreadcrumbStore _breadcrumb;
uint32_t _next_breadcrumb_sample_ms = 0;
void userLedHandler();
@@ -117,6 +121,8 @@ public:
void gotoNearbyScreen();
void gotoDashboardConfig();
void gotoAutoAdvertScreen();
void gotoBreadcrumbScreen();
BreadcrumbStore& breadcrumb() { return _breadcrumb; }
void playMelody(const char* melody);
void stopMelody();
bool isMelodyPlaying();