From 718dbdbe74544e649e373aed3b3f6d6004af3db8 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 3 Sep 2026 22:17:08 +0200 Subject: [PATCH] fix(sim): live RTC restore + add sim_test_show_all_home_pages() hook DataStore::restoreRTCTime() runs on every boot and, if a prior save exists, overwrites RTCClock with that stale timestamp. Correct on real hardware (no other way to know the time before a GPS fix or a phone/CLI sync), but SimRTCClock is already backed by the real host wall clock from construction -- overwriting it with an old IDBFS-persisted save made a returning meshcore-solo-site visitor's on-screen clock drift away from their own real time instead of just showing it. Guarded behind #ifndef SIM_PLATFORM. sim_test_show_all_home_pages() is a new sim-only test hook, same shape as the existing sim_test_* hooks in this file: real hardware ships with a curated 5-page Home carousel (NodePrefs::HP_DEFAULT) so a first-time user isn't handed 13 pages to joystick through, with the rest opt-in via Settings > Home Pages. meshcore-solo-site calls this once after boot to show the whole feature set instead, without touching the real-hardware default. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_018iubftDmKNWmkNnhJRz8UH --- examples/companion_radio/DataStore.cpp | 10 ++++++++++ examples/companion_radio/main.cpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index fa3c65ad..d2d541d9 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -862,7 +862,17 @@ void DataStore::restoreRTCTime() { uint32_t t = 0; file.read((uint8_t *)&t, sizeof(t)); file.close(); +#ifndef SIM_PLATFORM + // Real hardware has no other way to know the time before a GPS fix or + // a phone/CLI sync, so restoring the last-known saved time is the + // right call there. The sim's RTCClock (SimRTCClock.h) is already + // backed by the real host wall clock (time(NULL)) from the moment it's + // constructed -- overwriting that with a stale save from a previous + // visit (persisted via IDBFS, see the site's "returning visitor" note) + // would make a returning instance's on-screen clock drift away from + // the visitor's own real time instead of just showing it. if (t > 1000000000UL) _clock->setCurrentTime(t); +#endif } } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index d3ab73bf..2e9d9d37 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -409,6 +409,22 @@ extern "C" EMSCRIPTEN_KEEPALIVE int sim_test_get_num_contacts() { return the_mesh.getNumContacts(); } +// Real hardware ships with NodePrefs::HP_DEFAULT -- a curated 5-page Home +// carousel (Clock/Tools/Shutdown/Favourites/Map) -- so a first-time user +// isn't handed 13 pages to joystick through; the rest (Recent/Radio/ +// Bluetooth/Advert/GPS/Sensors) are opt-in via Settings > Home Pages. The +// demo site exists specifically to show off the whole feature set, so it +// calls this once right after boot to opt every instance into all of them +// instead -- 0 means "all visible" (see the home_pages_mask comment in +// NodePrefs.h), same as an as-yet-unset field on a factory-fresh device. +extern "C" EMSCRIPTEN_KEEPALIVE int sim_test_show_all_home_pages() { + if (!g_sim_ready) return 0; + NodePrefs* prefs = the_mesh.getNodePrefs(); + if (!prefs) return 0; + prefs->home_pages_mask = 0; + return 1; +} + #ifdef DISPLAY_CLASS // Jumps the on-device UI straight to the DM thread with the first known // ADV_TYPE_CHAT contact (UITask::openContactDM() -- the exact same real