From fcdacaa3bc8cc6c9ebb0562483548d6a2c7e0eab Mon Sep 17 00:00:00 2001 From: MarekZegare4 Date: Sun, 14 Jun 2026 12:49:15 +0200 Subject: [PATCH] fix: GPS shutdown active-level, buzzer octave-8 consistency, waypoint header read checks - UITask::shutdown(): power GPS off using !PIN_GPS_EN_ACTIVE instead of hardcoded LOW, matching MicroNMEALocationProvider::stop() (still LOW on current active-high devices, but correct for a future active-low GPS). - buzzer _noteFreq(): clamp octave to 8 instead of 7 so the parser's accepted range (4-8) is fully consumed; previously an octave-8 digit was clamped away and could leak into the stream as the next note's duration. - Waypoint::readFrom(): check read() return for version/reserved/count header bytes so a truncated file is rejected instead of using garbage count. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/Waypoint.h | 6 +++--- examples/companion_radio/ui-new/UITask.cpp | 6 +++++- src/helpers/ui/buzzer.cpp | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/companion_radio/Waypoint.h b/examples/companion_radio/Waypoint.h index 23c58cbd..ba57d1cb 100644 --- a/examples/companion_radio/Waypoint.h +++ b/examples/companion_radio/Waypoint.h @@ -74,9 +74,9 @@ public: if (magic != SAVE_MAGIC) return false; uint8_t ver = 0, res = 0; uint16_t cnt = 0; - file.read(&ver, 1); - file.read(&res, 1); - file.read((uint8_t*)&cnt, sizeof(cnt)); + if (file.read(&ver, 1) != 1) return false; + if (file.read(&res, 1) != 1) return false; + if (file.read((uint8_t*)&cnt, sizeof(cnt)) != (int)sizeof(cnt)) return false; if (ver != SAVE_VERSION) return false; if (cnt > CAPACITY) cnt = CAPACITY; _count = 0; diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 449a152a..01f867bd 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -1523,8 +1523,12 @@ void UITask::shutdown(bool restart){ // Power off GPS before SYSTEMOFF — GPIO pins retain state in NRF52 SYSTEMOFF, // so without this the GPS stays powered and drains the battery. // gps_enabled is already persisted to flash; applyGpsPrefs() restores it on next boot. + // Use the same active level as MicroNMEALocationProvider::stop() (default active-high). + #ifndef PIN_GPS_EN_ACTIVE + #define PIN_GPS_EN_ACTIVE HIGH + #endif pinMode(PIN_GPS_EN, OUTPUT); - digitalWrite(PIN_GPS_EN, LOW); + digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE); #endif _board->powerOff(); } diff --git a/src/helpers/ui/buzzer.cpp b/src/helpers/ui/buzzer.cpp index 0aa4066d..02deb5da 100644 --- a/src/helpers/ui/buzzer.cpp +++ b/src/helpers/ui/buzzer.cpp @@ -41,7 +41,7 @@ uint16_t genericBuzzer::_noteFreq(char letter, bool sharp, uint8_t octave) { uint8_t idx = NOTE_IDX[letter - 'a']; if (sharp) { if (++idx >= 12) { idx = 0; octave++; } } if (octave < 4) octave = 4; - if (octave > 7) octave = 7; + if (octave > 8) octave = 8; // parser accepts octaves 4-8; B8 (~7.9 kHz) is within range uint32_t f = (uint32_t)CHROM4[idx] << (octave - 4); return (uint16_t)(f > 25000 ? 25000 : f); }