mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-29 16:28:11 +00:00
Add a single "Units" choice (Settings › System: Metric / Imperial) that governs every distance and speed shown in Tools — Nearby Nodes, the Trail views, and the navigate-to-point screen. - NodePrefs: units_imperial (global) + trail_show_pace (Trail readout mode), schema bumped 0xC0DE0005 → 0006. The old combined trail_units_idx is kept for file-layout stability but no longer drives anything; upgraders default to metric + speed. - geo::fmtDist gains an imperial mode (ft below ~1000 ft, then miles). - NavView / Nearby / Trail (waypoint list, Summary distance, List deltas, map scale-bar label) all format through the global preference. - Trail's action-menu "Units" row becomes a Speed/Pace readout toggle; the km-vs-mi unit now follows the global setting instead of being one of four combined options. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
#pragma once
|
|
// Shared "navigate to a point" view. The target is just a (lat, lon, label)
|
|
// triple, so the same screen serves Waypoints, trail Backtrack and Nearby
|
|
// node navigation. No magnetometer: we show two *absolute* bearings — the
|
|
// target's bearing and the user's course over ground — and let the user
|
|
// compare them ("target 145°, I'm heading 090° → bear right").
|
|
//
|
|
// Pure render helper; the caller supplies its own GPS fix + COG (from UITask).
|
|
|
|
#include <helpers/ui/DisplayDriver.h>
|
|
#include "../GeoUtils.h"
|
|
|
|
namespace navview {
|
|
|
|
// own_valid : is there a usable GPS fix for the device right now
|
|
// cog_valid : is there a stable course-over-ground (UITask::currentCourse)
|
|
inline void draw(DisplayDriver& d,
|
|
bool own_valid, int32_t own_lat, int32_t own_lon,
|
|
int32_t tgt_lat, int32_t tgt_lon,
|
|
const char* label,
|
|
bool cog_valid, int cog_deg,
|
|
bool imperial) {
|
|
const int cx = d.width() / 2;
|
|
const int hdr = d.headerH();
|
|
|
|
// Title bar: label, inverted (matches the Nearby/discover detail style).
|
|
char title[24];
|
|
d.translateUTF8ToBlocks(title, (label && label[0]) ? label : "Navigate", sizeof(title));
|
|
d.setColor(DisplayDriver::LIGHT);
|
|
d.fillRect(0, 0, d.width(), hdr - 1);
|
|
d.setColor(DisplayDriver::DARK);
|
|
d.drawTextEllipsized(2, 1, d.width() - 4, title);
|
|
d.setColor(DisplayDriver::LIGHT);
|
|
d.fillRect(0, hdr - 1, d.width(), d.sepH());
|
|
|
|
if (!own_valid) {
|
|
d.drawTextCentered(cx, hdr + (d.height() - hdr) / 2 - d.getLineHeight(), "No GPS fix");
|
|
return;
|
|
}
|
|
|
|
int to_deg = geo::bearingDeg(own_lat, own_lon, tgt_lat, tgt_lon);
|
|
float dist_km = geo::haversineKm(own_lat, own_lon, tgt_lat, tgt_lon);
|
|
char dist[12];
|
|
geo::fmtDist(dist, sizeof(dist), dist_km, imperial);
|
|
|
|
const int step = d.lineStep();
|
|
int y = hdr + 2;
|
|
|
|
// Distance — emphasised at size 2.
|
|
d.setTextSize(2);
|
|
d.drawTextCentered(cx, y, dist);
|
|
y += d.getLineHeight() + 3;
|
|
d.setTextSize(1);
|
|
|
|
char line[20];
|
|
snprintf(line, sizeof(line), "To: %d %s", to_deg, geo::bearingCardinal(to_deg));
|
|
d.drawTextLeftAlign(2, y, line); y += step;
|
|
|
|
if (cog_valid) snprintf(line, sizeof(line), "Hdg: %d %s", cog_deg, geo::bearingCardinal(cog_deg));
|
|
else snprintf(line, sizeof(line), "Hdg: --");
|
|
d.drawTextLeftAlign(2, y, line); y += step;
|
|
}
|
|
|
|
} // namespace navview
|