Merge remote-tracking branch 'origin/wio-unified' into wio-unified

# Conflicts:
#	examples/companion_radio/DataStore.cpp
This commit is contained in:
Jakub
2026-06-04 17:13:49 +02:00
7 changed files with 52 additions and 19 deletions

View File

@@ -317,10 +317,12 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
rd(&_prefs.trail_units_idx, sizeof(_prefs.trail_units_idx));
rd(&_prefs.ch_fav_bitmask, sizeof(_prefs.ch_fav_bitmask));
rd(&_prefs.ch_fav_only, sizeof(_prefs.ch_fav_only));
rd(&_prefs.notif_melody_ad, sizeof(_prefs.notif_melody_ad));
rd(&_prefs.units_imperial, sizeof(_prefs.units_imperial));
rd(&_prefs.trail_show_pace, sizeof(_prefs.trail_show_pace));
// Both are booleans: an older file leaves stray bytes here (the old tail
// sentinel gets partly consumed), so clamp anything other than 0/1 to 0.
// These three were appended together; an older file leaves stray bytes here
// (the old tail sentinel gets partly consumed), so clamp out-of-range values.
if (_prefs.notif_melody_ad > 2) _prefs.notif_melody_ad = 0;
if (_prefs.units_imperial > 1) _prefs.units_imperial = 0;
if (_prefs.trail_show_pace > 1) _prefs.trail_show_pace = 0;
@@ -341,14 +343,16 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
// 0xC0DE0003 → 0xC0DE0004: trail_units_idx added after trail_min_delta_idx.
// On a 0xC0DE0003 file the sentinel bytes sit where trail_units_idx is now,
// so rd() picks up 0x03 (low byte of the old sentinel) — reset just that
// case to default 0. Newer mismatches (e.g. 0xC0DE0004 → 0xC0DE0005) had
// case to default 0. Newer mismatches (e.g. 0xC0DE0005 → 0xC0DE0006) had
// the field saved correctly and must not be clobbered.
if (sentinel == 0xC0DE0003) {
_prefs.trail_units_idx = 0;
}
// 0xC0DE0005 → 0xC0DE0006: units_imperial + trail_show_pace replaced the
// combined trail_units_idx. The new bytes overlap the old tail sentinel and
// are already clamped to 0 above, so upgraders default to metric + speed.
// 0xC0DE0007: merge of two parallel 0xC0DE0006 layouts — notif_melody_ad
// (advert sound) and units_imperial + trail_show_pace were appended after
// ch_fav_only. Any older file (incl. either single-feature 0006) leaves
// stray/old bytes in these fields; they're clamped above, so upgraders fall
// back to built-in advert sound + metric + speed.
}
file.close();
@@ -437,6 +441,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
file.write((uint8_t *)&_prefs.trail_units_idx, sizeof(_prefs.trail_units_idx));
file.write((uint8_t *)&_prefs.ch_fav_bitmask, sizeof(_prefs.ch_fav_bitmask));
file.write((uint8_t *)&_prefs.ch_fav_only, sizeof(_prefs.ch_fav_only));
file.write((uint8_t *)&_prefs.notif_melody_ad, sizeof(_prefs.notif_melody_ad));
file.write((uint8_t *)&_prefs.units_imperial, sizeof(_prefs.units_imperial));
file.write((uint8_t *)&_prefs.trail_show_pace, sizeof(_prefs.trail_show_pace));