From 874d308b505c56943788964cbfd473c26851edbd Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 3 Aug 2022 07:16:41 -0500 Subject: [PATCH] Only save devicestate on GPS reset (#1587) --- src/gps/GPS.cpp | 2 +- src/mesh/NodeDB.cpp | 10 ++++++++++ src/mesh/NodeDB.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index b0a8164d0..f8bff1dfd 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -330,7 +330,7 @@ int32_t GPS::runOnce() if(devicestate.did_gps_reset && (millis() > 60000) && !hasFlow()) { DEBUG_MSG("GPS is not communicating, trying factory reset on next bootup.\n"); devicestate.did_gps_reset = false; - nodeDB.saveToDisk(); + nodeDB.saveDeviceStateToDisk(); } #endif } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 63d67871e..cb4c625db 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -435,6 +435,16 @@ void NodeDB::saveChannelsToDisk() } } +void NodeDB::saveDeviceStateToDisk() +{ + if (!devicestate.no_save) { +#ifdef FSCom + FSCom.mkdir("/prefs"); +#endif + saveProto(prefFileName, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); + } +} + void NodeDB::saveToDisk() { if (!devicestate.no_save) { diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 0a2a5bdb7..a96fe22c2 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -44,7 +44,7 @@ class NodeDB void init(); /// write to flash - void saveToDisk(), saveChannelsToDisk(); + void saveToDisk(), saveChannelsToDisk(), saveDeviceStateToDisk(); /** Reinit radio config if needed, because either: * a) sometimes a buggy android app might send us bogus settings or