From 3148e7277d41cb1b102bb6376a4d0eb65f4a1a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 29 Mar 2025 14:14:24 +0100 Subject: [PATCH] Fix a couple of warnings (#6445) * Fix a couple of warnings * fix build error --------- Co-authored-by: Ben Meadors --- src/Power.cpp | 13 ++++++++----- src/gps/GPS.cpp | 11 ++++++----- src/mesh/NodeDB.cpp | 4 ++-- src/mesh/Router.cpp | 4 ++-- src/platform/stm32wl/STM32_LittleFS.h | 2 +- src/platform/stm32wl/STM32_LittleFS_File.cpp | 7 +++---- src/platform/stm32wl/STM32_LittleFS_File.h | 2 +- src/platform/stm32wl/littlefs/lfs.c | 6 +++--- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index ec3550869..0dec0fc21 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -533,6 +533,9 @@ Power::Power() : OSThread("Power") { statusHandler = {}; low_voltage_counter = 0; +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + low_voltage_counter_led3 = 0; +#endif #ifdef DEBUG_HEAP lastheap = memGet.getFreeHeap(); #endif @@ -668,12 +671,12 @@ void Power::readPowerStatus() int8_t batteryChargePercent = -1; OptionalBool usbPowered = OptUnknown; OptionalBool hasBattery = OptUnknown; // These must be static because NRF_APM code doesn't run every time - OptionalBool isCharging = OptUnknown; + OptionalBool isChargingNow = OptUnknown; if (batteryLevel) { hasBattery = batteryLevel->isBatteryConnect() ? OptTrue : OptFalse; usbPowered = batteryLevel->isVbusIn() ? OptTrue : OptFalse; - isCharging = batteryLevel->isCharging() ? OptTrue : OptFalse; + isChargingNow = batteryLevel->isCharging() ? OptTrue : OptFalse; if (hasBattery) { batteryVoltageMv = batteryLevel->getBattVoltage(); // If the AXP192 returns a valid battery percentage, use it @@ -702,15 +705,15 @@ void Power::readPowerStatus() // If changed to DISCONNECTED if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) - isCharging = usbPowered = OptFalse; + isChargingNow = usbPowered = OptFalse; // If changed to CONNECTED / READY else - isCharging = usbPowered = OptTrue; + isChargingNow = usbPowered = OptTrue; #endif // Notify any status instances that are observing us - const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isCharging, batteryVoltageMv, batteryChargePercent); + const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isChargingNow, batteryVoltageMv, batteryChargePercent); LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); #if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index c33cb2975..41a2ff980 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -981,15 +981,16 @@ void GPS::down() setPowerState(GPS_IDLE); else { - // Check whether the GPS hardware is capable of GPS_SOFTSLEEP - // If not, fallback to GPS_HARDSLEEP instead +// Check whether the GPS hardware is capable of GPS_SOFTSLEEP +// If not, fallback to GPS_HARDSLEEP instead +#ifdef PIN_GPS_STANDBY // L76B, L76K and clones have a standby pin + bool softsleepSupported = true; +#else bool softsleepSupported = false; +#endif // U-blox is supported via PMREQ if (IS_ONE_OF(gnssModel, GNSS_MODEL_UBLOX6, GNSS_MODEL_UBLOX7, GNSS_MODEL_UBLOX8, GNSS_MODEL_UBLOX9, GNSS_MODEL_UBLOX10)) softsleepSupported = true; -#ifdef PIN_GPS_STANDBY // L76B, L76K and clones have a standby pin - softsleepSupported = true; -#endif if (softsleepSupported) { // How long does gps_update_interval need to be, for GPS_HARDSLEEP to become more efficient than diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index df0fbcedd..3f79d18e6 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1061,8 +1061,8 @@ void NodeDB::loadFromDisk() // if (state != LoadFileResult::LOAD_SUCCESS) { // installDefaultDeviceState(); // Our in RAM copy might now be corrupt //} else { - if (devicestate.version < DEVICESTATE_MIN_VER) { - LOG_WARN("Devicestate %d is old, discard", devicestate.version); + if ((state != LoadFileResult::LOAD_SUCCESS) || (devicestate.version < DEVICESTATE_MIN_VER)) { + LOG_WARN("Devicestate %d is old or invalid, discard", devicestate.version); installDefaultDeviceState(); } else { LOG_INFO("Loaded saved devicestate version %d", devicestate.version); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 992f38ff4..b8b7ee610 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -188,7 +188,7 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) // don't override if a channel was requested and no need to set it when PKI is enforced if (!p->channel && !p->pki_encrypted && !isBroadcast(p->to)) { - meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(p->to); + meshtastic_NodeInfoLite const *node = nodeDB->getMeshNode(p->to); if (node) { p->channel = node->channel; LOG_DEBUG("localSend to channel %d", p->channel); @@ -688,7 +688,7 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) return; } - meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(p->from); + meshtastic_NodeInfoLite const *node = nodeDB->getMeshNode(p->from); if (node != NULL && node->is_ignored) { LOG_DEBUG("Ignore msg, 0x%x is ignored", p->from); packetPool.release(p); diff --git a/src/platform/stm32wl/STM32_LittleFS.h b/src/platform/stm32wl/STM32_LittleFS.h index 2ab531ee5..9460ffa81 100644 --- a/src/platform/stm32wl/STM32_LittleFS.h +++ b/src/platform/stm32wl/STM32_LittleFS.h @@ -37,7 +37,7 @@ class STM32_LittleFS { public: STM32_LittleFS(void); - STM32_LittleFS(struct lfs_config *cfg); + explicit STM32_LittleFS(struct lfs_config *cfg); virtual ~STM32_LittleFS(); bool begin(struct lfs_config *cfg = NULL); diff --git a/src/platform/stm32wl/STM32_LittleFS_File.cpp b/src/platform/stm32wl/STM32_LittleFS_File.cpp index 5e2d4c86c..349187a02 100644 --- a/src/platform/stm32wl/STM32_LittleFS_File.cpp +++ b/src/platform/stm32wl/STM32_LittleFS_File.cpp @@ -217,9 +217,9 @@ int File::available(void) _fs->_lockFS(); if (!this->_is_dir) { - uint32_t size = lfs_file_size(_fs->_getFS(), _file); + uint32_t file_size = lfs_file_size(_fs->_getFS(), _file); uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); - ret = size - pos; + ret = file_size - pos; } _fs->_unlockFS(); @@ -279,10 +279,9 @@ bool File::truncate(uint32_t pos) bool File::truncate(void) { int32_t ret = LFS_ERR_ISDIR; - uint32_t pos; _fs->_lockFS(); if (!this->_is_dir) { - pos = lfs_file_tell(_fs->_getFS(), _file); + uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); ret = lfs_file_truncate(_fs->_getFS(), _file, pos); } _fs->_unlockFS(); diff --git a/src/platform/stm32wl/STM32_LittleFS_File.h b/src/platform/stm32wl/STM32_LittleFS_File.h index 0a021dc54..2b48b02e0 100644 --- a/src/platform/stm32wl/STM32_LittleFS_File.h +++ b/src/platform/stm32wl/STM32_LittleFS_File.h @@ -42,7 +42,7 @@ enum { class File : public Stream { public: - File(STM32_LittleFS &fs); + explicit File(STM32_LittleFS &fs); File(char const *filename, uint8_t mode, STM32_LittleFS &fs); public: diff --git a/src/platform/stm32wl/littlefs/lfs.c b/src/platform/stm32wl/littlefs/lfs.c index 522614486..99c8b155e 100644 --- a/src/platform/stm32wl/littlefs/lfs.c +++ b/src/platform/stm32wl/littlefs/lfs.c @@ -863,7 +863,7 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry, const ch // check that entry has not been moved if (entry->d.type & 0x80) { int moved = lfs_moved(lfs, &entry->d.u); - if (moved < 0 || moved) { + if (moved) { return (moved < 0) ? moved : LFS_ERR_NOENT; } @@ -1057,7 +1057,7 @@ int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) return 0; } -lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir) +lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t const *dir) { (void)lfs; return dir->pos; @@ -1755,7 +1755,7 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) return 0; } -lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) +lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t const *file) { (void)lfs; return file->pos;