feat(m1): local time display and three-button monitoring (#6)
## Summary Two M1 firmware enhancements on the Waveshare ESP32-S3-RLCD-4.2: **Local-time display (UTC+8, fixed offset — China has no DST).** Internal time stays strictly UTC (RTC chip, JSONL `utc`, console `--json` keep the `Z`-suffixed machine format). Only human-facing surfaces convert via the new `board::kLocalUtcOffsetSeconds`: - display RTC line renders `unix + 8*3600` labeled `UTC+8` (split after the date: measured montserrat16 widths 157px + 119px fit the 179px status column; the old one-line layout was already 223px and overflowed) - text `status` and `rtc status` show the labeled UTC+8 line and keep both the raw unix and a UTC line - `rtc set` now takes UTC+8 local time (validates the local calendar round-trip, converts -8h before `set_rtc_time`); help/usage/README updated **Three buttons.** - KEY (GPIO18) unchanged (short <1s / long 1-3s / >=3s portal). - BOOT (GPIO0, strapping pin — input + pull-up, runtime read only): mirrors the KEY 30ms debounce and release bands (short <1s, long >=1s), new `boot_short_presses` / `boot_long_presses`, no portal binding. - RST is hardwired to chip reset, so it is tracked as a persistent boot counter: NVS namespace `frame`, key `rst_cnt`, incremented once per boot after `nvs_flash_init`, exposed as `reset_count`. - Surfaces: display `KEY:a/b BOOT:c/d` + `RST:e` lines, console text + `--json` (`boot_short`, `boot_long`, `reset_count`), JSONL `boot_short`/`boot_long` only — measured 594B worst observed line vs the 640B buffer (46B headroom, gate was >=40B); `reset_count` is static per boot so it is `--json`-only. ## On-device verification (34/34 deterministic asserts PASS + user assist) Evidence: `.omo/evidence/m1wp/tz-buttons-finish-m1-wifi-provisioning.log` - Build 0 warnings; clang-format 18.1.8 clean on whole `main/`. - `rtc status`/text status UTC+8 lines match host `date` +8h (<=3s skew); `rtc set` with a UTC+8 local time round-trips (`1788157541 = 14:25:41 local - 8h`). - JSONL `utc` unchanged UTC-with-Z, crc32c intact, max line 594B < 640. - KEY short press: +1 with BOOT unchanged (user-assisted). BOOT short: +2 (user-assisted). BOOT long: not physically exercised this session — code path is the device-proven KEY band logic (same constants); noted in `.omo/notepads` for the next bench session. - RST/reset_count: host RTS-pulse reboot 3->4 with boot banner; `--json` agrees. - Regressions: wifi auto-connect CONNECTED, tf_logging true, selftest `wifi_config: ok` + `bad ignored`, `prov status` three-state. Co-authored-by: ania-lain <[email protected]>
This commit is contained in:
@@ -32,6 +32,8 @@ uint64_t volatile_signature(const status_snapshot& value) {
|
||||
};
|
||||
fold(value.key_short_presses);
|
||||
fold(value.key_long_presses);
|
||||
fold(value.boot_short_presses);
|
||||
fold(value.boot_long_presses);
|
||||
fold(value.key_pressed ? 1U : 0U);
|
||||
fold(static_cast<uint64_t>(value.wifi));
|
||||
fold(static_cast<uint64_t>(value.storage));
|
||||
@@ -43,20 +45,22 @@ uint64_t volatile_signature(const status_snapshot& value) {
|
||||
return signature;
|
||||
}
|
||||
|
||||
// Human-facing RTC line: local UTC+8 rendering (China has no DST, fixed offset).
|
||||
void format_rtc_time(const status_snapshot& value, char* output, std::size_t capacity) {
|
||||
output[0] = '\0';
|
||||
if (!value.rtc.valid) {
|
||||
return;
|
||||
}
|
||||
const time_t seconds = static_cast<time_t>(value.rtc.unix_seconds);
|
||||
struct tm utc_time {};
|
||||
if (gmtime_r(&seconds, &utc_time) != nullptr) {
|
||||
const unsigned year = static_cast<unsigned>(utc_time.tm_year + 1900);
|
||||
const time_t seconds =
|
||||
static_cast<time_t>(value.rtc.unix_seconds + board::kLocalUtcOffsetSeconds);
|
||||
struct tm local_time {};
|
||||
if (gmtime_r(&seconds, &local_time) != nullptr) {
|
||||
const unsigned year = static_cast<unsigned>(local_time.tm_year + 1900);
|
||||
std::snprintf(
|
||||
output, capacity, "%04u-%02u-%02u %02u:%02u:%02u", year,
|
||||
static_cast<unsigned>(utc_time.tm_mon + 1), static_cast<unsigned>(utc_time.tm_mday),
|
||||
static_cast<unsigned>(utc_time.tm_hour), static_cast<unsigned>(utc_time.tm_min),
|
||||
static_cast<unsigned>(utc_time.tm_sec));
|
||||
output, capacity, "%04u-%02u-%02u %02u:%02u:%02u UTC+8", year,
|
||||
static_cast<unsigned>(local_time.tm_mon + 1), static_cast<unsigned>(local_time.tm_mday),
|
||||
static_cast<unsigned>(local_time.tm_hour), static_cast<unsigned>(local_time.tm_min),
|
||||
static_cast<unsigned>(local_time.tm_sec));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,14 +190,21 @@ void display_service::render_status(const status_snapshot& value) {
|
||||
value.psram_ok ? "OK" : "FAIL", value.partitions_ok ? "OK" : "FAIL");
|
||||
char rtc_text[32]{};
|
||||
format_rtc_time(value, rtc_text, sizeof(rtc_text));
|
||||
// The ~179px status column cannot hold "YYYY-MM-DD HH:MM:SS UTC+8" on one line
|
||||
// (montserrat16: 210px); break after the date so both lines fit without clipping.
|
||||
char* time_break = std::strchr(rtc_text, ' ');
|
||||
if (time_break != nullptr) {
|
||||
*time_break = '\n';
|
||||
}
|
||||
lv_label_set_text_fmt(
|
||||
peripherals_label_,
|
||||
"Display: %s\nTF: %s / log:%s\nRTC: %s %s\nSHTC3: %s\n"
|
||||
"KEY short:%" PRIu64 " long:%" PRIu64,
|
||||
"KEY:%" PRIu64 "/%" PRIu64 " BOOT:%" PRIu64 "/%" PRIu64 "\nRST:%" PRIu32,
|
||||
value.display_error == ESP_OK ? "OK" : "FAIL",
|
||||
hardware_status::sd_state_name(value.storage), value.tf_logging_ok ? "OK" : "WAIT",
|
||||
value.rtc_present ? "OK" : "MISS", rtc_text[0] == '\0' ? "-" : rtc_text,
|
||||
value.sensor_present ? "OK" : "MISS", value.key_short_presses, value.key_long_presses);
|
||||
value.sensor_present ? "OK" : "MISS", value.key_short_presses, value.key_long_presses,
|
||||
value.boot_short_presses, value.boot_long_presses, value.reset_count);
|
||||
lv_label_set_text_fmt(
|
||||
network_label_, "WiFi: %s\nSSID: %s\nIPv4: %s\nCredentials: system_fs (dev)",
|
||||
value.ap_active ? "AP-SETUP 192.168.4.1" : hardware_status::wifi_state_name(value.wifi),
|
||||
|
||||
Reference in New Issue
Block a user