mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
feat(home-pages): make Map and Shutdown reorderable; v1.22 notes
The Map page had no Settings entry and Shutdown was pinned to the end of the carousel because page_order held only 11 slots — full in the common GPS+SENSORS config, so both pages fell back to being appended at nav time and couldn't be moved. Grow page_order to 13 (== HPB_COUNT) so every page has a reorderable slot, and add Map + Shutdown to the default order and the required-append list. To keep the persisted format backward-compatible (page_order sits mid-record, not at the tail), the on-disk head stays the original 11 bytes at its existing offset and the 2 new slots are appended at the file tail, matching the append-only schema design. Bump SCHEMA_SENTINEL to 0xC0DE0019; on a pre-0x19 save the tail bytes are the old sentinel/EOF, so they're clamped to 0 and ensurePageOrderInit re-appends Map/Shutdown into the freed slots on first use. Drop the now-dead Shutdown-eviction path (13 slots fit all pages). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -319,7 +319,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
||||
rd(&_prefs.clock_12h, sizeof(_prefs.clock_12h));
|
||||
rd(&_prefs.use_lemon_font, sizeof(_prefs.use_lemon_font));
|
||||
rd(&_prefs.display_rotation, sizeof(_prefs.display_rotation));
|
||||
rd(_prefs.page_order, sizeof(_prefs.page_order));
|
||||
rd(_prefs.page_order, NodePrefs::PAGE_ORDER_LEN_V1); // tail slots read below (append-only)
|
||||
rd(&_prefs.joystick_rotation, sizeof(_prefs.joystick_rotation));
|
||||
#if !FEAT_JOYSTICK_ROTATION_SETTING
|
||||
// No UI to change it on this build, so force the default — this also corrects
|
||||
@@ -461,6 +461,17 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
||||
// which is out of range — fall back to the default of 2 resends.
|
||||
if (_prefs.dm_resend_count > 5) _prefs.dm_resend_count = 2;
|
||||
|
||||
// → 0xC0DE0019: page_order grew 11 → 13 so Shutdown and Map become reorderable.
|
||||
// The extra slots are appended here at the tail (not inline) so a pre-0x19 save,
|
||||
// whose order ended right after the old 11 bytes, still loads without shifting
|
||||
// every field after it. On such files these bytes are the old sentinel tail or
|
||||
// EOF, so clamp anything out of range back to 0 (empty); ensurePageOrderInit
|
||||
// then appends the missing pages into the freed slots.
|
||||
for (uint8_t i = NodePrefs::PAGE_ORDER_LEN_V1; i < NodePrefs::PAGE_ORDER_LEN; i++) {
|
||||
rd(&_prefs.page_order[i], sizeof(_prefs.page_order[i]));
|
||||
if (_prefs.page_order[i] > NodePrefs::HPB_COUNT) _prefs.page_order[i] = 0;
|
||||
}
|
||||
|
||||
// Schema sentinel: bumped on layout changes. Mismatch means an older file
|
||||
// (or a different schema); rd() already zero-inits any fields not present,
|
||||
// so we just log it — next savePrefs writes the current sentinel.
|
||||
@@ -586,7 +597,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
||||
file.write((uint8_t *)&_prefs.clock_12h, sizeof(_prefs.clock_12h));
|
||||
file.write((uint8_t *)&_prefs.use_lemon_font, sizeof(_prefs.use_lemon_font));
|
||||
file.write((uint8_t *)&_prefs.display_rotation, sizeof(_prefs.display_rotation));
|
||||
file.write((uint8_t *)_prefs.page_order, sizeof(_prefs.page_order));
|
||||
file.write((uint8_t *)_prefs.page_order, NodePrefs::PAGE_ORDER_LEN_V1); // head; tail slots written below
|
||||
file.write((uint8_t *)&_prefs.joystick_rotation, sizeof(_prefs.joystick_rotation));
|
||||
file.write((uint8_t *)&_prefs.eink_full_refresh_every, sizeof(_prefs.eink_full_refresh_every));
|
||||
file.write((uint8_t *)&_prefs.page_order_set, sizeof(_prefs.page_order_set));
|
||||
@@ -641,6 +652,10 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
||||
file.write((uint8_t *)&_prefs.alarm_on, sizeof(_prefs.alarm_on));
|
||||
file.write((uint8_t *)&_prefs.alarm_hour, sizeof(_prefs.alarm_hour));
|
||||
file.write((uint8_t *)&_prefs.alarm_min, sizeof(_prefs.alarm_min));
|
||||
// page_order tail slots (see loadPrefsInt): entries beyond PAGE_ORDER_LEN_V1,
|
||||
// appended here so the on-disk head stays the original 11 bytes.
|
||||
file.write((uint8_t *)&_prefs.page_order[NodePrefs::PAGE_ORDER_LEN_V1],
|
||||
NodePrefs::PAGE_ORDER_LEN - NodePrefs::PAGE_ORDER_LEN_V1);
|
||||
|
||||
// Tail sentinel — must be last. See NodePrefs::SCHEMA_SENTINEL. Its write is
|
||||
// the one we check: once the flash fills, writes return 0, so a good
|
||||
|
||||
Reference in New Issue
Block a user