From cfcb62bd18683ee5158333cc3645b6fd63cf355d Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 29 Oct 2020 13:26:36 +0800 Subject: [PATCH] Make region changes take effect immedately --- src/mesh/MeshService.cpp | 3 +++ src/mesh/NodeDB.cpp | 6 +++--- src/mesh/RadioInterface.cpp | 14 ++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 5be9feb8..77c0f2c9 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -198,7 +198,10 @@ void MeshService::loop() bool MeshService::reloadConfig() { // If we can successfully set this radio to these settings, save them to disk + + // This will also update the region as needed bool didReset = nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings + configChanged.notifyObservers(NULL); nodeDB.saveToDisk(); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1febc0ae..3714f403 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -150,6 +150,9 @@ bool NodeDB::resetRadioConfig() radioConfig.preferences.region = RegionCode_TW; } + // Update the global myRegion + initRegion(); + return didFactoryReset; } @@ -245,9 +248,6 @@ void NodeDB::init() } } - // Update the global myRegion - initRegion(); - strncpy(myNodeInfo.firmware_version, optstr(APP_VERSION), sizeof(myNodeInfo.firmware_version)); strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model)); diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index c35075c6..83bf5aa3 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -30,15 +30,13 @@ const RegionInfo *myRegion; void initRegion() { - if (!myRegion) { - const RegionInfo *r = regions; - for (; r->code != RegionCode_Unset && r->code != radioConfig.preferences.region; r++) - ; - myRegion = r; - DEBUG_MSG("Wanted region %d, using %s\n", radioConfig.preferences.region, r->name); + const RegionInfo *r = regions; + for (; r->code != RegionCode_Unset && r->code != radioConfig.preferences.region; r++) + ; + myRegion = r; + DEBUG_MSG("Wanted region %d, using %s\n", radioConfig.preferences.region, r->name); - myNodeInfo.num_channels = myRegion->numChannels; // Tell our android app how many channels we have - } + myNodeInfo.num_channels = myRegion->numChannels; // Tell our android app how many channels we have } /**