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:
@@ -23,10 +23,27 @@ hotspot; such a hold is a portal command and does not count as a button press.
|
||||
|
||||
## Buttons
|
||||
|
||||
The only monitored button is the board's **KEY** button (GPIO18, active-low): a release under 1
|
||||
second counts as a short press, 1-3 seconds as a long press, and 3 seconds or more requests the
|
||||
setup hotspot. Both counters appear on the display and in `status`. The **RST** button resets the
|
||||
board, and **BOOT** (GPIO0) is not monitored — pressing either does not change any counter.
|
||||
The board's three buttons are all observable:
|
||||
|
||||
- **KEY** (GPIO18, active-low): a release under 1 second counts as a short press, 1-3 seconds
|
||||
as a long press, and 3 seconds or more requests the setup hotspot (a portal command, not a
|
||||
press). Both counters appear on the display and in `status` as `KEY: short/long`.
|
||||
- **BOOT** (GPIO0, active-low with the internal pull-up): the same release bands, under 1
|
||||
second short and 1 second or more long, counted as `BOOT: short/long`. It is a strapping
|
||||
pin, so the firmware only reads it at runtime and never drives it, and it has no portal
|
||||
binding.
|
||||
- **RST**: hardwired to the chip reset line, so it cannot be sampled as a GPIO. Instead the
|
||||
firmware increments a persistent boot counter once per boot (NVS namespace `frame`, key
|
||||
`rst_cnt`) and reports it as `RST: count` / `reset_count`; pressing RST reboots the board
|
||||
and increments the counter.
|
||||
|
||||
## Timezone
|
||||
|
||||
Internal time handling is strictly UTC: the RTC chip, JSONL telemetry, and the machine `utc`
|
||||
fields all carry UTC with a `Z` suffix. Only human-facing surfaces convert to local time —
|
||||
China Standard Time (UTC+8, no daylight-saving transitions): the display RTC line, the text
|
||||
`status` output, and `rtc status` render local time labeled `UTC+8`, and `rtc set` interprets
|
||||
its argument as UTC+8 local time (the firmware converts it to UTC before writing the chip).
|
||||
|
||||
## Real-Time Clock
|
||||
|
||||
@@ -38,7 +55,8 @@ display (`-`) and in JSONL (`"utc":""`). The firmware now provides two time sour
|
||||
`ntp.aliyun.com` and `pool.ntp.org`, and on the first successful sync writes the UTC time to
|
||||
the RTC (log line `rtc synced from sntp`). SNTP keeps running; periodic re-syncs update the
|
||||
system clock.
|
||||
- **Console:** `rtc set` writes the chip manually (UTC is assumed).
|
||||
- **Console:** `rtc set` writes the chip manually (the argument is UTC+8 local time; see
|
||||
[Timezone](#timezone)).
|
||||
|
||||
A CR1220 coin cell on the board keeps the RTC running across power-off. Without a battery (or
|
||||
with an empty one) every boot loses the time and the OS flag returns — install a fresh cell for
|
||||
@@ -71,9 +89,10 @@ storage status
|
||||
selftest
|
||||
```
|
||||
|
||||
`rtc status` reports validity, unix time, formatted UTC, and the OS-bit state; `rtc raw` dumps
|
||||
PCF85063 registers 0x00-0x0A with a decode; `rtc set` parses `YYYY-MM-DD HH:MM:SS` as UTC,
|
||||
validates the ranges, writes the chip, and re-reads it to confirm.
|
||||
`rtc status` reports validity, unix time, formatted UTC, formatted UTC+8 local time, and the
|
||||
OS-bit state; `rtc raw` dumps PCF85063 registers 0x00-0x0A with a decode; `rtc set` parses
|
||||
`YYYY-MM-DD HH:MM:SS` as UTC+8 local time, validates the ranges (calendar round-trip), converts
|
||||
to UTC, writes the chip, and re-reads it to confirm.
|
||||
|
||||
Do not place real credentials in command transcripts or committed evidence. `wifi set` asks for the
|
||||
password after parsing the command so it is not stored in command history; terminal software must
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "display_service.hh"
|
||||
#include "esp_log.h"
|
||||
#include "hardware_status.hh"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "sd_service.hh"
|
||||
#include "time_sync.hh"
|
||||
@@ -15,6 +16,27 @@ namespace {
|
||||
|
||||
constexpr char kTag[] = "frame-m1";
|
||||
|
||||
// RST is hardwired to the chip reset line and cannot be sampled as a GPIO; this persistent
|
||||
// NVS boot counter (namespace "frame", key "rst_cnt") is the observable RST-press proxy.
|
||||
uint32_t count_boot_and_store(frame::m1::hardware_status& status) {
|
||||
nvs_handle_t handle = 0;
|
||||
if (nvs_open("frame", NVS_READWRITE, &handle) != ESP_OK) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t stored = 0;
|
||||
const esp_err_t read_result = nvs_get_u32(handle, "rst_cnt", &stored);
|
||||
const uint32_t count =
|
||||
read_result == ESP_OK || read_result == ESP_ERR_NVS_NOT_FOUND ? stored + 1U : 0U;
|
||||
if (count != 0U && nvs_set_u32(handle, "rst_cnt", count) == ESP_OK) {
|
||||
nvs_commit(handle);
|
||||
}
|
||||
nvs_close(handle);
|
||||
if (count != 0U) {
|
||||
status.update([count](frame::m1::status_snapshot& value) { value.reset_count = count; });
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" void app_main(void) {
|
||||
@@ -38,6 +60,8 @@ extern "C" void app_main(void) {
|
||||
ESP_LOGW(kTag, "NVS unavailable; Wi-Fi credentials will remain RAM-only: %s",
|
||||
esp_err_to_name(nvs_result));
|
||||
}
|
||||
const uint32_t reset_count = count_boot_and_store(status);
|
||||
ESP_LOGI(kTag, "reset_count=%" PRIu32, reset_count);
|
||||
|
||||
static board_service board(status);
|
||||
static sd_service storage(status);
|
||||
|
||||
@@ -37,6 +37,12 @@ inline constexpr uint16_t kRtcAddress = 0x51;
|
||||
inline constexpr uint16_t kSensorAddress = 0x70;
|
||||
|
||||
inline constexpr gpio_num_t kKey = GPIO_NUM_18;
|
||||
// BOOT is a strapping pin; runtime config is input + pull-up read-only, never driven.
|
||||
inline constexpr gpio_num_t kBoot = GPIO_NUM_0;
|
||||
|
||||
// Human-facing local time offset: China Standard Time (UTC+8), no daylight-saving transitions.
|
||||
// Internal storage, JSONL, and machine `utc` fields stay strictly UTC.
|
||||
inline constexpr int32_t kLocalUtcOffsetSeconds = 8 * 3600;
|
||||
|
||||
inline constexpr gpio_num_t kSdClock = GPIO_NUM_38;
|
||||
inline constexpr gpio_num_t kSdCommand = GPIO_NUM_21;
|
||||
|
||||
@@ -18,6 +18,7 @@ constexpr uint8_t kRtcSecondsRegister = 0x04;
|
||||
constexpr uint8_t kRtcFirstRegister = 0x00;
|
||||
constexpr std::size_t kRtcRegisterCount = 11;
|
||||
// KEY release bands: <1s short press, 1s..<3s long press, >=3s provisioning portal command.
|
||||
// BOOT release bands: <1s short press, >=1s long press (no portal binding).
|
||||
constexpr int64_t kKeyLongPressUs = 1000000;
|
||||
constexpr int64_t kKeyPortalHoldUs = 3000000;
|
||||
|
||||
@@ -54,12 +55,12 @@ board_service::~board_service() {
|
||||
}
|
||||
|
||||
esp_err_t board_service::start() {
|
||||
gpio_config_t key_config{};
|
||||
key_config.pin_bit_mask = UINT64_C(1) << board::kKey;
|
||||
key_config.mode = GPIO_MODE_INPUT;
|
||||
key_config.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
key_config.intr_type = GPIO_INTR_DISABLE;
|
||||
esp_err_t result = gpio_config(&key_config);
|
||||
gpio_config_t buttons_config{};
|
||||
buttons_config.pin_bit_mask = (UINT64_C(1) << board::kKey) | (UINT64_C(1) << board::kBoot);
|
||||
buttons_config.mode = GPIO_MODE_INPUT;
|
||||
buttons_config.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
buttons_config.intr_type = GPIO_INTR_DISABLE;
|
||||
esp_err_t result = gpio_config(&buttons_config);
|
||||
if (result != ESP_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -296,6 +297,10 @@ void board_service::run() {
|
||||
bool stable_pressed = last_pressed;
|
||||
int64_t changed_at = esp_timer_get_time();
|
||||
int64_t pressed_at = stable_pressed ? changed_at : 0;
|
||||
bool boot_last_pressed = gpio_get_level(board::kBoot) == 0;
|
||||
bool boot_stable_pressed = boot_last_pressed;
|
||||
int64_t boot_changed_at = esp_timer_get_time();
|
||||
int64_t boot_pressed_at = boot_stable_pressed ? boot_changed_at : 0;
|
||||
int64_t next_sensor_at = 0;
|
||||
|
||||
while (true) {
|
||||
@@ -328,6 +333,28 @@ void board_service::run() {
|
||||
}
|
||||
}
|
||||
|
||||
const bool boot_pressed = gpio_get_level(board::kBoot) == 0;
|
||||
if (boot_pressed != boot_last_pressed) {
|
||||
boot_last_pressed = boot_pressed;
|
||||
boot_changed_at = now;
|
||||
}
|
||||
if (boot_pressed != boot_stable_pressed && now - boot_changed_at >= 30000) {
|
||||
boot_stable_pressed = boot_pressed;
|
||||
if (boot_pressed) {
|
||||
boot_pressed_at = now;
|
||||
} else if (boot_pressed_at != 0) {
|
||||
const int64_t boot_held_us = now - boot_pressed_at;
|
||||
status_.update([&](status_snapshot& value) {
|
||||
if (boot_held_us >= kKeyLongPressUs) {
|
||||
++value.boot_long_presses;
|
||||
} else {
|
||||
++value.boot_short_presses;
|
||||
}
|
||||
});
|
||||
boot_pressed_at = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (now >= next_sensor_at) {
|
||||
const esp_err_t sensor_result = sample_sensor();
|
||||
if (sensor_result != ESP_OK) {
|
||||
|
||||
@@ -19,6 +19,21 @@ uint8_t from_bcd(uint8_t value) {
|
||||
return static_cast<uint8_t>((value >> 4U) * 10U + (value & 0x0FU));
|
||||
}
|
||||
|
||||
// Renders unix seconds (already offset by the caller) as "YYYY-MM-DD HH:MM:SS".
|
||||
void format_unix_datetime(int64_t unix_seconds, char* output, std::size_t capacity) {
|
||||
output[0] = '\0';
|
||||
const time_t seconds = static_cast<time_t>(unix_seconds);
|
||||
struct tm utc_time {};
|
||||
if (gmtime_r(&seconds, &utc_time) != nullptr) {
|
||||
const unsigned year = static_cast<unsigned>(utc_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));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
esp_err_t console_service::start() {
|
||||
@@ -75,7 +90,7 @@ esp_err_t console_service::start() {
|
||||
};
|
||||
const esp_console_cmd_t rtc_cmd{
|
||||
.command = "rtc",
|
||||
.help = "rtc status | rtc raw | rtc set YYYY-MM-DD HH:MM:SS (UTC)",
|
||||
.help = "rtc status | rtc raw | rtc set YYYY-MM-DD HH:MM:SS (UTC+8 local)",
|
||||
.hint = nullptr,
|
||||
.func = &console_service::rtc_command,
|
||||
.argtable = nullptr,
|
||||
@@ -244,7 +259,7 @@ int console_service::rtc_command(int argc, char** argv) {
|
||||
if (argc == 4 && std::strcmp(argv[1], "set") == 0) {
|
||||
return instance_->run_rtc_set(argv[2], argv[3]);
|
||||
}
|
||||
std::printf("usage: rtc status | rtc raw | rtc set YYYY-MM-DD HH:MM:SS\n");
|
||||
std::printf("usage: rtc status | rtc raw | rtc set YYYY-MM-DD HH:MM:SS (UTC+8 local)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -262,19 +277,14 @@ void console_service::print_rtc_status() const {
|
||||
value.rtc.unix_seconds);
|
||||
|
||||
char utc[32]{};
|
||||
char local[32]{};
|
||||
if (value.rtc.valid) {
|
||||
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);
|
||||
std::snprintf(
|
||||
utc, sizeof(utc), "%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));
|
||||
}
|
||||
format_unix_datetime(value.rtc.unix_seconds, utc, sizeof(utc));
|
||||
format_unix_datetime(value.rtc.unix_seconds + board::kLocalUtcOffsetSeconds, local,
|
||||
sizeof(local));
|
||||
}
|
||||
std::printf("utc: %s\n", utc[0] == '\0' ? "-" : utc);
|
||||
std::printf("local: %s UTC+8\n", local[0] == '\0' ? "-" : local);
|
||||
std::printf("OS bit: %s\n", os_state);
|
||||
}
|
||||
|
||||
@@ -309,7 +319,7 @@ int console_service::run_rtc_set(const char* date_text, const char* time_text) {
|
||||
}
|
||||
struct tm parsed {};
|
||||
if (strptime(text, "%Y-%m-%d %H:%M:%S", &parsed) == nullptr) {
|
||||
std::printf("rtc set: unparseable, expected YYYY-MM-DD HH:MM:SS (UTC)\n");
|
||||
std::printf("rtc set: unparseable, expected YYYY-MM-DD HH:MM:SS (UTC+8 local)\n");
|
||||
return 1;
|
||||
}
|
||||
const int year = parsed.tm_year + 1900;
|
||||
@@ -320,10 +330,11 @@ int console_service::run_rtc_set(const char* date_text, const char* time_text) {
|
||||
std::printf("rtc set: value out of range\n");
|
||||
return 1;
|
||||
}
|
||||
const int64_t unix_seconds = board_service::unix_from_utc(
|
||||
// Input is UTC+8 local time; validate the local calendar, then shift to UTC for the chip.
|
||||
const int64_t local_seconds = board_service::unix_from_utc(
|
||||
year, month, static_cast<unsigned>(parsed.tm_mday), static_cast<unsigned>(parsed.tm_hour),
|
||||
static_cast<unsigned>(parsed.tm_min), static_cast<unsigned>(parsed.tm_sec));
|
||||
time_t check_seconds = static_cast<time_t>(unix_seconds);
|
||||
time_t check_seconds = static_cast<time_t>(local_seconds);
|
||||
struct tm check {};
|
||||
if (gmtime_r(&check_seconds, &check) == nullptr || check.tm_year != parsed.tm_year ||
|
||||
check.tm_mon != parsed.tm_mon || check.tm_mday != parsed.tm_mday ||
|
||||
@@ -333,8 +344,10 @@ int console_service::run_rtc_set(const char* date_text, const char* time_text) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const int64_t unix_seconds = local_seconds - board::kLocalUtcOffsetSeconds;
|
||||
const esp_err_t result = board_.set_rtc_time(unix_seconds);
|
||||
std::printf("rtc set: %s (unix %" PRId64 ")\n", esp_err_to_name(result), unix_seconds);
|
||||
std::printf("rtc set: %s (local %s %s UTC+8 -> unix %" PRId64 ")\n", esp_err_to_name(result),
|
||||
date_text, time_text, unix_seconds);
|
||||
return result == ESP_OK ? 0 : 1;
|
||||
}
|
||||
|
||||
@@ -398,6 +411,7 @@ void console_service::print_status(bool json) const {
|
||||
"\"wifi\":\"%s\",\"ap_active\":%s,\"credentials_persisted\":%s,"
|
||||
"\"tf_logging\":%s,\"logging_error\":%d,\"temperature_tenths_c\":%d,"
|
||||
"\"humidity_tenths_percent\":%u,\"key_short\":%" PRIu64 ",\"key_long\":%" PRIu64
|
||||
",\"boot_short\":%" PRIu64 ",\"boot_long\":%" PRIu64 ",\"reset_count\":%" PRIu32
|
||||
",\"elf_sha256\":\"%s\",\"image_sha256\":\"%s\"}\n",
|
||||
board::kFirmwareVersion, board::kIdfTag, value.toolchain_version, value.device_id,
|
||||
health, value.target_ok ? "true" : "false", value.cpu_cores,
|
||||
@@ -411,22 +425,17 @@ void console_service::print_status(bool json) const {
|
||||
value.tf_logging_ok ? "true" : "false", static_cast<int>(value.logging_error),
|
||||
value.sensor.valid ? static_cast<int>(value.sensor.temperature_tenths_celsius) : 0,
|
||||
value.sensor.valid ? static_cast<unsigned>(value.sensor.humidity_tenths_percent) : 0U,
|
||||
value.key_short_presses, value.key_long_presses, value.elf_sha256, value.image_sha256);
|
||||
value.key_short_presses, value.key_long_presses, value.boot_short_presses,
|
||||
value.boot_long_presses, value.reset_count, value.elf_sha256, value.image_sha256);
|
||||
return;
|
||||
}
|
||||
|
||||
char rtc_text[32]{};
|
||||
char local_text[32]{};
|
||||
char utc_text[32]{};
|
||||
if (value.rtc.valid) {
|
||||
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);
|
||||
std::snprintf(
|
||||
rtc_text, sizeof(rtc_text), "%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));
|
||||
}
|
||||
format_unix_datetime(value.rtc.unix_seconds + board::kLocalUtcOffsetSeconds, local_text,
|
||||
sizeof(local_text));
|
||||
format_unix_datetime(value.rtc.unix_seconds, utc_text, sizeof(utc_text));
|
||||
}
|
||||
std::printf("Frame M1 %s (%s)\n", board::kFirmwareVersion, health);
|
||||
std::printf(" device: %s image: %.16s\n IDF: %s toolchain: %s\n", value.device_id,
|
||||
@@ -439,10 +448,18 @@ void console_service::print_status(bool json) const {
|
||||
value.display_error == ESP_OK ? "OK" : "FAILED",
|
||||
hardware_status::sd_state_name(value.storage), value.tf_logging_ok ? "OK" : "WAIT",
|
||||
value.reset_reason);
|
||||
std::printf(" RTC: %s %s SHTC3: %s KEY: %" PRIu64 "/%" PRIu64 "\n",
|
||||
value.rtc_present ? "OK" : "MISS", rtc_text[0] == '\0' ? "-" : rtc_text,
|
||||
std::printf(" RTC: %s %s UTC+8\n", value.rtc_present ? "OK" : "MISS",
|
||||
local_text[0] == '\0' ? "-" : local_text);
|
||||
if (utc_text[0] == '\0') {
|
||||
std::printf(" utc: - unix: %" PRId64 "\n", value.rtc.unix_seconds);
|
||||
} else {
|
||||
std::printf(" utc: %sZ unix: %" PRId64 "\n", utc_text, value.rtc.unix_seconds);
|
||||
}
|
||||
std::printf(" SHTC3: %s KEY: %" PRIu64 "/%" PRIu64 " BOOT: %" PRIu64 "/%" PRIu64
|
||||
" RST: %" PRIu32 "\n",
|
||||
value.sensor_present ? "OK" : "MISS", value.key_short_presses,
|
||||
value.key_long_presses);
|
||||
value.key_long_presses, value.boot_short_presses, value.boot_long_presses,
|
||||
value.reset_count);
|
||||
std::printf(" WiFi: %s SSID: %s IPv4: %s credentials: system_fs (dev)\n",
|
||||
hardware_status::wifi_state_name(value.wifi), value.ssid_configured ? "set" : "-",
|
||||
value.ip_address[0] == '\0' ? "-" : value.ip_address);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -63,6 +63,9 @@ struct status_snapshot {
|
||||
uint32_t reset_reason{};
|
||||
uint64_t key_short_presses{};
|
||||
uint64_t key_long_presses{};
|
||||
uint64_t boot_short_presses{};
|
||||
uint64_t boot_long_presses{};
|
||||
uint32_t reset_count{};
|
||||
bool target_ok{};
|
||||
bool flash_ok{};
|
||||
bool psram_ok{};
|
||||
|
||||
@@ -142,7 +142,8 @@ void sd_service::unmount() {
|
||||
}
|
||||
|
||||
esp_err_t sd_service::append_status_log() {
|
||||
// Must exceed the ~550-byte payload: format_status_log returns 0 on truncation (= ESP_FAIL).
|
||||
// Must exceed the ~595-byte payload (measured with boot counters; re-measure before adding
|
||||
// JSONL fields): format_status_log returns 0 on truncation (= ESP_FAIL).
|
||||
char line[640];
|
||||
const status_snapshot snapshot = status_.snapshot();
|
||||
const std::size_t length =
|
||||
|
||||
@@ -52,7 +52,8 @@ std::size_t format_status_log(const status_snapshot& status, uint64_t sequence,
|
||||
"\"ap_setup\":%s,"
|
||||
"\"rtc\":%s,\"shtc3\":%s,\"sensor_valid\":%s,"
|
||||
"\"temperature_tenths_c\":%d,\"humidity_tenths_percent\":%u,"
|
||||
"\"key_short\":%" PRIu64 ",\"key_long\":%" PRIu64,
|
||||
"\"key_short\":%" PRIu64 ",\"key_long\":%" PRIu64 ",\"boot_short\":%" PRIu64
|
||||
",\"boot_long\":%" PRIu64,
|
||||
sequence, uptime_us, status.rtc.valid ? "true" : "false", utc, event, mode,
|
||||
hardware_status::health_name(hardware_status::overall_health(status)), status.device_id,
|
||||
status.app_version, status.idf_version, status.toolchain_version, status.image_sha256,
|
||||
@@ -63,7 +64,8 @@ std::size_t format_status_log(const status_snapshot& status, uint64_t sequence,
|
||||
status.sensor.valid ? "true" : "false",
|
||||
status.sensor.valid ? static_cast<int>(status.sensor.temperature_tenths_celsius) : 0,
|
||||
status.sensor.valid ? static_cast<unsigned>(status.sensor.humidity_tenths_percent) : 0U,
|
||||
status.key_short_presses, status.key_long_presses);
|
||||
status.key_short_presses, status.key_long_presses, status.boot_short_presses,
|
||||
status.boot_long_presses);
|
||||
if (payload_length < 0 || static_cast<std::size_t>(payload_length) >= capacity) {
|
||||
output[0] = '\0';
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user