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 <noreply@anthropic.com>
This commit is contained in:
MarekZegare4
2026-06-14 12:49:15 +02:00
parent 6c5a40a8ce
commit fcdacaa3bc
3 changed files with 9 additions and 5 deletions

View File

@@ -74,9 +74,9 @@ public:
if (magic != SAVE_MAGIC) return false; if (magic != SAVE_MAGIC) return false;
uint8_t ver = 0, res = 0; uint8_t ver = 0, res = 0;
uint16_t cnt = 0; uint16_t cnt = 0;
file.read(&ver, 1); if (file.read(&ver, 1) != 1) return false;
file.read(&res, 1); if (file.read(&res, 1) != 1) return false;
file.read((uint8_t*)&cnt, sizeof(cnt)); if (file.read((uint8_t*)&cnt, sizeof(cnt)) != (int)sizeof(cnt)) return false;
if (ver != SAVE_VERSION) return false; if (ver != SAVE_VERSION) return false;
if (cnt > CAPACITY) cnt = CAPACITY; if (cnt > CAPACITY) cnt = CAPACITY;
_count = 0; _count = 0;

View File

@@ -1523,8 +1523,12 @@ void UITask::shutdown(bool restart){
// Power off GPS before SYSTEMOFF — GPIO pins retain state in NRF52 SYSTEMOFF, // Power off GPS before SYSTEMOFF — GPIO pins retain state in NRF52 SYSTEMOFF,
// so without this the GPS stays powered and drains the battery. // so without this the GPS stays powered and drains the battery.
// gps_enabled is already persisted to flash; applyGpsPrefs() restores it on next boot. // 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); pinMode(PIN_GPS_EN, OUTPUT);
digitalWrite(PIN_GPS_EN, LOW); digitalWrite(PIN_GPS_EN, !PIN_GPS_EN_ACTIVE);
#endif #endif
_board->powerOff(); _board->powerOff();
} }

View File

@@ -41,7 +41,7 @@ uint16_t genericBuzzer::_noteFreq(char letter, bool sharp, uint8_t octave) {
uint8_t idx = NOTE_IDX[letter - 'a']; uint8_t idx = NOTE_IDX[letter - 'a'];
if (sharp) { if (++idx >= 12) { idx = 0; octave++; } } if (sharp) { if (++idx >= 12) { idx = 0; octave++; } }
if (octave < 4) octave = 4; 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); uint32_t f = (uint32_t)CHROM4[idx] << (octave - 4);
return (uint16_t)(f > 25000 ? 25000 : f); return (uint16_t)(f > 25000 ? 25000 : f);
} }