mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-06 04:06:12 +00:00
feat: add 12h/24h clock format setting (default 24h)
Toggle in Settings > Display > Format. In 12h mode the clock shows h:mm AM/PM (or h:mm:ss AM/PM with seconds, no space before AM/PM). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e0312c2b6b
commit
38cd0fada3
@@ -13,6 +13,7 @@ class SettingsScreen : public UIScreen {
|
||||
AUTO_LOCK,
|
||||
BATT_DISPLAY,
|
||||
CLOCK_SECONDS,
|
||||
CLOCK_FORMAT,
|
||||
// Sound section
|
||||
SECTION_SOUND,
|
||||
BUZZER,
|
||||
@@ -311,6 +312,10 @@ class SettingsScreen : public UIScreen {
|
||||
display.print("Seconds");
|
||||
display.setCursor(VAL_X, y);
|
||||
display.print((p && p->clock_hide_seconds) ? "OFF" : "ON");
|
||||
} else if (item == CLOCK_FORMAT) {
|
||||
display.print("Format");
|
||||
display.setCursor(VAL_X, y);
|
||||
display.print((p && p->clock_12h) ? "12h" : "24h");
|
||||
} else if (item == DM_FILTER) {
|
||||
display.print("DM");
|
||||
display.setCursor(VAL_X, y);
|
||||
@@ -496,6 +501,11 @@ public:
|
||||
_dirty = true;
|
||||
return true;
|
||||
}
|
||||
if (_selected == CLOCK_FORMAT && p && (left || right || enter)) {
|
||||
p->clock_12h ^= 1;
|
||||
_dirty = true;
|
||||
return true;
|
||||
}
|
||||
if (_selected == DM_FILTER && p && (left || right || enter)) {
|
||||
p->dm_show_all = p->dm_show_all ? 0 : 1;
|
||||
_dirty = true;
|
||||
|
||||
@@ -389,10 +389,16 @@ public:
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setTextSize(2);
|
||||
bool show_sec = !_node_prefs || !_node_prefs->clock_hide_seconds;
|
||||
if (show_sec)
|
||||
sprintf(buf, "%02d:%02d:%02d", ti->tm_hour, ti->tm_min, ti->tm_sec);
|
||||
else
|
||||
sprintf(buf, "%02d:%02d", ti->tm_hour, ti->tm_min);
|
||||
bool h12 = _node_prefs && _node_prefs->clock_12h;
|
||||
if (h12) {
|
||||
int h = ti->tm_hour % 12; if (h == 0) h = 12;
|
||||
const char* ap = ti->tm_hour < 12 ? "AM" : "PM";
|
||||
if (show_sec) sprintf(buf, "%d:%02d:%02d%s", h, ti->tm_min, ti->tm_sec, ap);
|
||||
else sprintf(buf, "%d:%02d %s", h, ti->tm_min, ap);
|
||||
} else {
|
||||
if (show_sec) sprintf(buf, "%02d:%02d:%02d", ti->tm_hour, ti->tm_min, ti->tm_sec);
|
||||
else sprintf(buf, "%02d:%02d", ti->tm_hour, ti->tm_min);
|
||||
}
|
||||
display.drawTextCentered(display.width() / 2, 0, buf);
|
||||
|
||||
display.setTextSize(1);
|
||||
@@ -1334,7 +1340,12 @@ void UITask::loop() {
|
||||
struct tm* ti = gmtime(&t);
|
||||
char buf[12];
|
||||
_display->setTextSize(2);
|
||||
sprintf(buf, "%02d:%02d", ti->tm_hour, ti->tm_min);
|
||||
if (_node_prefs && _node_prefs->clock_12h) {
|
||||
int h = ti->tm_hour % 12; if (h == 0) h = 12;
|
||||
sprintf(buf, "%d:%02d %s", h, ti->tm_min, ti->tm_hour < 12 ? "AM" : "PM");
|
||||
} else {
|
||||
sprintf(buf, "%02d:%02d", ti->tm_hour, ti->tm_min);
|
||||
}
|
||||
_display->drawTextCentered(_display->width() / 2, 8, buf);
|
||||
_display->setTextSize(1);
|
||||
static const char* wd[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
|
||||
|
||||
Reference in New Issue
Block a user