Add 12h/AM-PM clock format for Imperial units, add miles to distance display
The header clock now shows 12-hour time with AM/PM when Imperial units are selected (Menu > Units), instead of always using 24-hour format - the clock-clear region was widened from 50px to 80px to fully erase the longer "12:59PM"-style text. The aircraft detail panel's distance line now also shows miles alongside km and nautical miles (e.g. "12km / 6nm / 7mi"), since nm alone wasn't self-explanatory for lay users from Imperial-unit countries. Also fixes the radar screen's range button, which still always showed a fixed "km" label regardless of the Metric/Imperial setting - it now shows mi (converted) when Imperial is selected, matching the pattern already used by the altitude legend. Refreshes firmware.bin to match this build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
21
src/main.cpp
21
src/main.cpp
@@ -320,7 +320,12 @@ void updateStatusLine() {
|
|||||||
// NUR unter der Uhrzeit einen hoeheren Bereich loeschen - nicht die
|
// NUR unter der Uhrzeit einen hoeheren Bereich loeschen - nicht die
|
||||||
// ganze Zeile, sonst wuerde das jede Sekunde in den Menu-Button
|
// ganze Zeile, sonst wuerde das jede Sekunde in den Menu-Button
|
||||||
// hineinschneiden, der bis y=25 reicht.
|
// hineinschneiden, der bis y=25 reicht.
|
||||||
constexpr int16_t CLOCK_CLEAR_W = 50;
|
// Auf 80px verbreitert (vorher 50) - das 12h-Format mit AM/PM (siehe
|
||||||
|
// unten) ist mit bis zu 7 Zeichen ("12:59PM") laenger als das feste
|
||||||
|
// 5-Zeichen-24h-Format ("23:12") und wurde sonst nicht vollstaendig
|
||||||
|
// geloescht (Ziffernreste blieben stehen). Der Bereich rechts daneben
|
||||||
|
// war hier ohnehin leer, daher unkritisch.
|
||||||
|
constexpr int16_t CLOCK_CLEAR_W = 80;
|
||||||
constexpr int16_t CLOCK_CLEAR_TOP = HEADER_TITLE_H - 10;
|
constexpr int16_t CLOCK_CLEAR_TOP = HEADER_TITLE_H - 10;
|
||||||
tft.fillRect(0, CLOCK_CLEAR_TOP, CLOCK_CLEAR_W, CONTENT_TOP - CLOCK_CLEAR_TOP, TFT_BLACK);
|
tft.fillRect(0, CLOCK_CLEAR_TOP, CLOCK_CLEAR_W, CONTENT_TOP - CLOCK_CLEAR_TOP, TFT_BLACK);
|
||||||
tft.fillRect(CLOCK_CLEAR_W, HEADER_TITLE_H, Config::SCREEN_WIDTH - CLOCK_CLEAR_W, STATUS_LINE_H, TFT_BLACK);
|
tft.fillRect(CLOCK_CLEAR_W, HEADER_TITLE_H, Config::SCREEN_WIDTH - CLOCK_CLEAR_W, STATUS_LINE_H, TFT_BLACK);
|
||||||
@@ -330,8 +335,18 @@ void updateStatusLine() {
|
|||||||
if (now > 8 * 3600 * 2) {
|
if (now > 8 * 3600 * 2) {
|
||||||
struct tm tmNow;
|
struct tm tmNow;
|
||||||
localtime_r(&now, &tmNow);
|
localtime_r(&now, &tmNow);
|
||||||
char timeBuf[6];
|
char timeBuf[9];
|
||||||
snprintf(timeBuf, sizeof(timeBuf), "%02d:%02d", tmNow.tm_hour, tmNow.tm_min);
|
// 12h mit AM/PM bei Imperial (in den USA ueblich), 24h bei
|
||||||
|
// Metrisch - dieselbe Einheiten-Einstellung (Menue > Einheiten),
|
||||||
|
// die sonst Distanz/Hoehe steuert. Vorher immer fest 24h.
|
||||||
|
if (LocationManager::useMetricUnits()) {
|
||||||
|
snprintf(timeBuf, sizeof(timeBuf), "%02d:%02d", tmNow.tm_hour, tmNow.tm_min);
|
||||||
|
} else {
|
||||||
|
int hour12 = tmNow.tm_hour % 12;
|
||||||
|
if (hour12 == 0) hour12 = 12;
|
||||||
|
snprintf(timeBuf, sizeof(timeBuf), "%d:%02d%s", hour12, tmNow.tm_min,
|
||||||
|
tmNow.tm_hour < 12 ? "AM" : "PM");
|
||||||
|
}
|
||||||
tft.setCursor(6, HEADER_TITLE_H + 2);
|
tft.setCursor(6, HEADER_TITLE_H + 2);
|
||||||
tft.print(timeBuf);
|
tft.print(timeBuf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,8 +541,14 @@ namespace {
|
|||||||
updateLine(gfx, y, LINE_H, textMaxWidth, TFT_GREEN, lastPanel.climbText, climbLine, forceFull);
|
updateLine(gfx, y, LINE_H, textMaxWidth, TFT_GREEN, lastPanel.climbText, climbLine, forceFull);
|
||||||
y += LINE_H;
|
y += LINE_H;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s%.0fkm / %.0fnm %s%.0f", I18n::t(StringId::DETAIL_DIST),
|
// Zusaetzlich zu km/nm auch Meilen (mi) - nm allein war fuer
|
||||||
a.distanceKm, Units::kmToNm(a.distanceKm), I18n::t(StringId::DETAIL_HDG), a.headingDeg);
|
// Laien-Nutzer aus Ländern mit imperialen Einheiten (v.a. USA)
|
||||||
|
// nicht selbsterklaerend, "Meilen" sind dort die gebraeuchlichere
|
||||||
|
// Alltags-Distanzeinheit (nm bleibt trotzdem stehen, da es zur
|
||||||
|
// Geschwindigkeit in kt passt: 1 kt = 1 nm/h).
|
||||||
|
snprintf(buf, sizeof(buf), "%s%.0fkm / %.0fnm / %.0fmi %s%.0f", I18n::t(StringId::DETAIL_DIST),
|
||||||
|
a.distanceKm, Units::kmToNm(a.distanceKm), Units::kmToMi(a.distanceKm),
|
||||||
|
I18n::t(StringId::DETAIL_HDG), a.headingDeg);
|
||||||
updateLine(gfx, y, LINE_H, textMaxWidth, TFT_GREEN, lastPanel.distHeadingText, String(buf), forceFull);
|
updateLine(gfx, y, LINE_H, textMaxWidth, TFT_GREEN, lastPanel.distHeadingText, String(buf), forceFull);
|
||||||
y += LINE_H;
|
y += LINE_H;
|
||||||
|
|
||||||
@@ -750,7 +756,14 @@ void render(TFT_eSPI& tft, int16_t top) {
|
|||||||
drawInfoMarquee(tft, INFO_TEXT_X, infoTextY, infoTextW);
|
drawInfoMarquee(tft, INFO_TEXT_X, infoTextY, infoTextW);
|
||||||
|
|
||||||
char rangeLabel[8];
|
char rangeLabel[8];
|
||||||
snprintf(rangeLabel, sizeof(rangeLabel), "%.0fkm", rangeKm);
|
// Zeigt km bei Metrisch, mi bei Imperial (Menue > Einheiten) -
|
||||||
|
// gleiches Muster wie drawLegend() weiter oben, statt fest immer
|
||||||
|
// km anzuzeigen.
|
||||||
|
if (LocationManager::useMetricUnits()) {
|
||||||
|
snprintf(rangeLabel, sizeof(rangeLabel), "%.0fkm", rangeKm);
|
||||||
|
} else {
|
||||||
|
snprintf(rangeLabel, sizeof(rangeLabel), "%.0fmi", Units::kmToMi(rangeKm));
|
||||||
|
}
|
||||||
drawButton(tft, L.rangeBtn, rangeLabel);
|
drawButton(tft, L.rangeBtn, rangeLabel);
|
||||||
|
|
||||||
drawLegend(tft, infoTop + 44);
|
drawLegend(tft, infoTop + 44);
|
||||||
|
|||||||
@@ -9,8 +9,14 @@ namespace Units {
|
|||||||
constexpr float FT_TO_M = 0.3048f;
|
constexpr float FT_TO_M = 0.3048f;
|
||||||
constexpr float KT_TO_KMH = 1.852f;
|
constexpr float KT_TO_KMH = 1.852f;
|
||||||
constexpr float KM_TO_NM = 1.0f / 1.852f;
|
constexpr float KM_TO_NM = 1.0f / 1.852f;
|
||||||
|
constexpr float KM_TO_MI = 0.621371f;
|
||||||
|
|
||||||
inline float feetToMeters(float ft) { return ft * FT_TO_M; }
|
inline float feetToMeters(float ft) { return ft * FT_TO_M; }
|
||||||
inline float ktToKmh(float kt) { return kt * KT_TO_KMH; }
|
inline float ktToKmh(float kt) { return kt * KT_TO_KMH; }
|
||||||
inline float kmToNm(float km) { return km * KM_TO_NM; }
|
inline float kmToNm(float km) { return km * KM_TO_NM; }
|
||||||
|
// Statute miles (not nautical miles) - added alongside km/nm in the
|
||||||
|
// aircraft detail panel so a lay US user sees a distance they
|
||||||
|
// recognize, while nm stays for consistency with the kt speed unit
|
||||||
|
// (1 kt = 1 nm/h).
|
||||||
|
inline float kmToMi(float km) { return km * KM_TO_MI; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user