mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
Squash merge of feat/location-beacon-alerts-autopause (v1.21). Features: - Live Location Sharing — broadcast position as movement-gated [LOC] messages to a channel or contact; live shares show as map pins with distance/bearing in Nearby Nodes and a status-bar indicator. [LOC] is parsed in DMs, channel messages and room messages; DM shares name the sender. - Locator (geofence) — arm a geofence around a saved waypoint or a person (live [LOC] or last-known position), alert on arrive/leave or near/far, with an optional homing beeper (gated to arrive/both modes). Arm from Tools > Locator, Nearby Nodes, or Waypoints; target picker lists favourites first, clearable via a "None" entry. Active target is drawn as a flag on the map. - One active target shared across Locator / Navigate / Map via a single resolver (resolvePersonPos / activeTargetPos) that prefers a live [LOC] share over the last-advertised GPS fix. - Follow live contacts — Navigate to a live-sharing contact follows them as they move and adds an ETA line; quick-share your own position from the Map. - Map & status-bar upgrades — home mini-map gets a north marker, scale tick, and a connected trail line (was disconnected dots); status line shows tracked-node count, an arrow + distance to the active Locator/Nav target (falling back to the nearest live-tracked contact); GPS fix icon in the top status bar, shown only on GPS boards with GPS enabled. - Trail auto-pause — recording freezes on stops (banking elapsed time, breaking the map line across the idle gap) and resumes on movement without ending the session. - Streaming trail simplification — GPS points are simplified in-stream via a fixed-corridor (Reumann-Witkam) pass tuned for fidelity: straight runs collapse to their endpoints, curves stay bounded to the Min-dist tolerance, so the 512-point buffer covers a far longer route than a flat point budget would suggest. - Collapsible Tools (Location / Comms / System sections, fold-in-place like Settings) and page-indicator icons on the home carousel. - Waypoint coordinate editor — add a waypoint by scroll-editing lat/lon digit by digit. Fixes: - Critical: low-heap hang and contact loss on RAM-tight builds. Halved message-history scrollback rings (recovering ~14 KB free heap) and made contacts/channels/prefs persistence atomic (temp file + rename), so an interrupted save can no longer corrupt or wipe the store. - Serial.write() bounded so a stalled USB host can't hang the device. - Nearby Nodes: live [LOC] senders respect the type filter, sort by shared position, and the list refreshes so live shares bubble up. - Map: live contacts are labelled before waypoints. - GPS status icon hidden when GPS is off in Settings. - Splash screen no longer truncates a pre-release tag's own dash (e.g. v1.21-rc1) when stripping the build's commit-hash suffix. - Null-guarded the Locator target picker; clamped loc-share channel index on load. Under the hood: - -Os size optimisation on the e-ink and GAT562 30S solo envs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
176 lines
7.2 KiB
C++
176 lines
7.2 KiB
C++
#pragma once
|
||
// Live location sharing config tool. Tools › Live Share.
|
||
// One place for both directions of position sharing:
|
||
// Track loc — receive [LOC] shares from others (LiveTrackStore).
|
||
// Auto share — periodically broadcast my own [LOC] to a channel/contact
|
||
// while moving (movement-gated engine in UITask).
|
||
// Independent of (and able to run alongside) the 0-hop Auto-Advert. The
|
||
// one-shot "Share my pos" lives on the Map screen.
|
||
// Included by UITask.cpp after AutoAdvertScreen.h.
|
||
|
||
#include "../NodePrefs.h"
|
||
#include "icons.h" // drawList (shared scrolling-list helper)
|
||
|
||
class LiveShareScreen : public UIScreen {
|
||
UITask* _task;
|
||
NodePrefs* _prefs;
|
||
bool _dirty = false;
|
||
int _sel = 0;
|
||
int _scroll = 0;
|
||
|
||
enum Kind : uint8_t { K_TRACK, K_AUTO, K_TARGET, K_MOVE, K_GAP, K_HB };
|
||
struct Row { Kind kind; const char* label; };
|
||
static const int ROW_COUNT = 6;
|
||
static Row rows(int i) {
|
||
static const Row R[ROW_COUNT] = {
|
||
{ K_TRACK, "Track loc" },
|
||
{ K_AUTO, "Auto share" },
|
||
{ K_TARGET, "To" },
|
||
{ K_MOVE, "Move" },
|
||
{ K_GAP, "Min gap" },
|
||
{ K_HB, "Heartbeat" },
|
||
};
|
||
return R[i];
|
||
}
|
||
|
||
public:
|
||
LiveShareScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
|
||
|
||
void enter() { _dirty = false; _sel = 0; _scroll = 0; }
|
||
|
||
// Resolve the configured target's display name (channel name or contact name).
|
||
void currentTargetName(char* buf, int n) {
|
||
if (!_prefs) { snprintf(buf, n, "none"); return; }
|
||
if (_prefs->loc_share_target_type == 0) {
|
||
ChannelDetails ch;
|
||
if (the_mesh.getChannel(_prefs->loc_share_channel_idx, ch) && ch.name[0])
|
||
snprintf(buf, n, "%s", ch.name);
|
||
else
|
||
snprintf(buf, n, "Ch %d", (int)_prefs->loc_share_channel_idx);
|
||
} else {
|
||
ContactInfo* c = the_mesh.lookupContactByPubKey(_prefs->loc_share_dm_prefix, NodePrefs::FAVOURITE_PREFIX_LEN);
|
||
if (c) snprintf(buf, n, "%s", c->name);
|
||
else snprintf(buf, n, "(contact?)");
|
||
}
|
||
}
|
||
|
||
void valueLabel(Kind k, char* buf, int n) {
|
||
switch (k) {
|
||
case K_TRACK:
|
||
snprintf(buf, n, "%s", (_prefs && _prefs->track_shared_loc) ? "ON" : "OFF");
|
||
break;
|
||
case K_AUTO:
|
||
snprintf(buf, n, "%s", (_prefs && _prefs->loc_share_enabled) ? "ON" : "OFF");
|
||
break;
|
||
case K_TARGET:
|
||
currentTargetName(buf, n);
|
||
break;
|
||
case K_MOVE:
|
||
snprintf(buf, n, "%um", (unsigned)NodePrefs::locShareMoveMeters(_prefs ? _prefs->loc_share_move_idx : 1));
|
||
break;
|
||
case K_GAP: {
|
||
uint16_t s = NodePrefs::locShareIntervalSecs(_prefs ? _prefs->loc_share_interval_idx : 1);
|
||
if (s < 60) snprintf(buf, n, "%us", (unsigned)s);
|
||
else snprintf(buf, n, "%um", (unsigned)(s / 60));
|
||
break;
|
||
}
|
||
case K_HB: {
|
||
uint16_t s = NodePrefs::locShareHeartbeatSecs(_prefs ? _prefs->loc_share_heartbeat_idx : 0);
|
||
if (s == 0) snprintf(buf, n, "OFF");
|
||
else snprintf(buf, n, "%um", (unsigned)(s / 60));
|
||
break;
|
||
}
|
||
default: buf[0] = '\0';
|
||
}
|
||
}
|
||
|
||
int render(DisplayDriver& display) override {
|
||
display.setTextSize(1);
|
||
display.setColor(DisplayDriver::LIGHT);
|
||
display.drawCenteredHeader("LIVE SHARE");
|
||
|
||
const int valx = display.width() / 2 + 6;
|
||
drawList(display, ROW_COUNT, _sel, _scroll, [&](int i, int y, bool sel, int reserve) {
|
||
Row r = rows(i);
|
||
display.drawSelectionRow(0, y - 1, display.width() - reserve, display.lineStep() - 1, sel);
|
||
display.setCursor(4, y);
|
||
display.print(r.label);
|
||
char val[24];
|
||
valueLabel(r.kind, val, sizeof(val));
|
||
if (val[0]) display.drawTextEllipsized(valx, y, display.width() - valx - reserve, val);
|
||
});
|
||
return 500;
|
||
}
|
||
|
||
void moveSel(int dir) { _sel = (_sel + dir + ROW_COUNT) % ROW_COUNT; }
|
||
|
||
// Cycle/act on the selected row. `enter` opens the target picker (vs LEFT/RIGHT
|
||
// value cycling).
|
||
void activate(int dir, bool enter) {
|
||
if (!_prefs) return;
|
||
switch (rows(_sel).kind) {
|
||
case K_TRACK: _prefs->track_shared_loc ^= 1; _dirty = true; break;
|
||
case K_AUTO: _prefs->loc_share_enabled ^= 1; _dirty = true; break;
|
||
case K_TARGET:
|
||
if (enter) { _task->pickLocShareTarget(); return; } // full chooser
|
||
cycleTarget(dir); _dirty = true; // L/R quick cycle
|
||
break;
|
||
case K_MOVE:
|
||
_prefs->loc_share_move_idx = (uint8_t)((_prefs->loc_share_move_idx + (dir >= 0 ? 1 : NodePrefs::LOC_SHARE_MOVE_COUNT - 1)) % NodePrefs::LOC_SHARE_MOVE_COUNT);
|
||
_dirty = true; break;
|
||
case K_GAP:
|
||
_prefs->loc_share_interval_idx = (uint8_t)((_prefs->loc_share_interval_idx + (dir >= 0 ? 1 : NodePrefs::LOC_SHARE_INTERVAL_COUNT - 1)) % NodePrefs::LOC_SHARE_INTERVAL_COUNT);
|
||
_dirty = true; break;
|
||
case K_HB:
|
||
_prefs->loc_share_heartbeat_idx = (uint8_t)((_prefs->loc_share_heartbeat_idx + (dir >= 0 ? 1 : NodePrefs::LOC_SHARE_HEARTBEAT_COUNT - 1)) % NodePrefs::LOC_SHARE_HEARTBEAT_COUNT);
|
||
_dirty = true; break;
|
||
}
|
||
}
|
||
|
||
void cycleTarget(int dir) {
|
||
struct T { uint8_t type, ch; uint8_t prefix[NodePrefs::FAVOURITE_PREFIX_LEN]; } list[24];
|
||
int n = 0;
|
||
ChannelDetails ch;
|
||
for (int i = 0; i < 64 && n < 24; i++) {
|
||
if (!the_mesh.getChannel(i, ch) || ch.name[0] == '\0') continue;
|
||
list[n].type = 0; list[n].ch = (uint8_t)i; n++;
|
||
}
|
||
for (int i = 0; i < NodePrefs::FAVOURITES_COUNT && n < 24; i++) {
|
||
const uint8_t* pre = _prefs->favourite_contacts[i];
|
||
bool empty = true;
|
||
for (int b = 0; b < NodePrefs::FAVOURITE_PREFIX_LEN; b++) if (pre[b]) { empty = false; break; }
|
||
ContactInfo* fc = the_mesh.lookupContactByPubKey(pre, NodePrefs::FAVOURITE_PREFIX_LEN);
|
||
// Skip room servers: a [LOC] DM to a room server isn't reposted to the
|
||
// room's members, so it can't serve as a live-share broadcast target.
|
||
if (empty || !fc || fc->type == ADV_TYPE_ROOM) continue;
|
||
list[n].type = 1; list[n].ch = 0;
|
||
memcpy(list[n].prefix, pre, NodePrefs::FAVOURITE_PREFIX_LEN); n++;
|
||
}
|
||
if (n == 0) { _task->showAlert("No channels/favs", 1200); return; }
|
||
int cur = -1;
|
||
for (int i = 0; i < n; i++) {
|
||
if (list[i].type != _prefs->loc_share_target_type) continue;
|
||
if (list[i].type == 0) { if (list[i].ch == _prefs->loc_share_channel_idx) { cur = i; break; } }
|
||
else if (memcmp(list[i].prefix, _prefs->loc_share_dm_prefix, NodePrefs::FAVOURITE_PREFIX_LEN) == 0) { cur = i; break; }
|
||
}
|
||
int nx = (cur < 0) ? 0 : ((cur + (dir >= 0 ? 1 : n - 1)) % n);
|
||
_prefs->loc_share_target_type = list[nx].type;
|
||
if (list[nx].type == 0) _prefs->loc_share_channel_idx = list[nx].ch;
|
||
else memcpy(_prefs->loc_share_dm_prefix, list[nx].prefix, NodePrefs::FAVOURITE_PREFIX_LEN);
|
||
}
|
||
|
||
bool handleInput(char c) override {
|
||
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
|
||
if (_dirty) { the_mesh.savePrefs(); _dirty = false; }
|
||
_task->gotoToolsScreen();
|
||
return true;
|
||
}
|
||
if (c == KEY_UP) { moveSel(-1); return true; }
|
||
if (c == KEY_DOWN) { moveSel(+1); return true; }
|
||
if (keyIsPrev(c)) { activate(-1, false); return true; }
|
||
if (keyIsNext(c)) { activate(+1, false); return true; }
|
||
if (c == KEY_ENTER) { activate(+1, true); return true; }
|
||
return false;
|
||
}
|
||
};
|