feat(companion): live location sharing, Locator geofencing, trail auto-pause

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>
This commit is contained in:
MarekZegare4
2026-06-25 19:04:21 +02:00
co-authored by Claude Opus 4.8
parent c935287627
commit 57774d41f3
80 changed files with 2885 additions and 339 deletions
+36 -1
View File
@@ -1,5 +1,6 @@
#include "MyMesh.h"
#include "MsgExpand.h"
#include "GeoUtils.h"
#include "Features.h"
#include <Arduino.h> // needed for PlatformIO
@@ -484,7 +485,7 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
if (should_display && _ui) {
_ui->newMsg(path_len, from.name, text, offline_queue_len, from.type, from.id.pub_key);
_ui->notify(UIEventType::contactMessage);
_ui->notify(from.type == ADV_TYPE_ROOM ? UIEventType::roomMessage : UIEventType::contactMessage);
// Add to the on-device conversation history. Room servers (ADV_TYPE_ROOM) are
// viewed through the same history list as chat contacts (keyed by the server's
// pubkey), so their posts must be stored too — otherwise an incoming room
@@ -636,6 +637,12 @@ void MyMesh::onMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t
markConnectionActive(from); // in case this is from a server, and we have a connection
queueMessage(from, TXT_TYPE_PLAIN, pkt, sender_timestamp, NULL, 0, text);
// Live position share: a verified DM, so key the track by the sender's pubkey.
int32_t loc_lat, loc_lon;
if (_ui && geo::parseLocShare(text, loc_lat, loc_lon)) {
_ui->onSharedLocation(from.id.pub_key, from.name, loc_lat, loc_lon, sender_timestamp, true);
}
// hop count of the received message. getPathHashCount() (low 6 bits of path_len)
// is the number of repeaters traversed — the same value the mesh uses for flood
// retransmit priority. 0 = heard directly. (Raw path_len is a size/count
@@ -657,6 +664,17 @@ void MyMesh::onSignedMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uin
// from.sync_since change needs to be persisted
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
queueMessage(from, TXT_TYPE_SIGNED_PLAIN, pkt, sender_timestamp, sender_prefix, 4, text);
// Live position share inside a room (mirrors the DM and channel paths). The
// post's author is the signed sender_prefix, not the room server `from`, so
// resolve that 4-byte prefix to a contact name and track by name. Unverified:
// we only hold a 4-byte prefix here, not the full pubkey LiveTrack keys on.
int32_t loc_lat, loc_lon;
if (_ui && geo::parseLocShare(text, loc_lat, loc_lon)) {
ContactInfo* sc = sender_prefix ? lookupContactByPubKey(sender_prefix, 4) : nullptr;
const char* who = (sc && sc->name[0]) ? sc->name : from.name;
_ui->onSharedLocation(nullptr, who, loc_lat, loc_lon, sender_timestamp, false);
}
}
void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint32_t timestamp,
@@ -710,6 +728,23 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
channel_name = channel_details.name;
}
if (_ui) _ui->newMsg(path_len, channel_name, text, offline_queue_len, 0);
// Live position share on a channel. The sender's identity here is only the
// unsigned "name: msg" prefix (no pubkey), so track it by name — best-effort
// and unverified. parseLocShare requires an explicit [LOC] tag, so ordinary
// chatter is ignored.
int32_t loc_lat, loc_lon;
if (_ui && geo::parseLocShare(text, loc_lat, loc_lon)) {
char sender[32] = {0};
const char* sep = strstr(text, ": ");
if (sep && sep > text) {
int n = (int)(sep - text);
if (n > (int)sizeof(sender) - 1) n = sizeof(sender) - 1;
memcpy(sender, text, n);
sender[n] = '\0';
}
_ui->onSharedLocation(nullptr, sender[0] ? sender : "?", loc_lat, loc_lon, timestamp, false);
}
#endif
// hop count for !hops (see onMessageRecv); not the wire path_len above.