diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 5590fa9cf..d542b21cf 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -104,7 +104,7 @@ bool MeshService::reloadConfig() // 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); + configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc nodeDB.saveToDisk(); return didReset; diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 7d8115878..20a687769 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -359,6 +359,16 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_ return okay; } +void NodeDB::saveChannelsToDisk() +{ + if (!devicestate.no_save) { +#ifdef FS + FS.mkdir("/prefs"); +#endif + saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); + } +} + void NodeDB::saveToDisk() { if (!devicestate.no_save) { @@ -367,7 +377,7 @@ void NodeDB::saveToDisk() #endif bool okay = saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); okay &= saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); - okay &= saveProto(channelfile, ChannelFile_size, sizeof(ChannelFile), ChannelFile_fields, &channelFile); + saveChannelsToDisk(); // remove any pre 1.2 pref files, turn on after 1.2 is in beta // if(okay) FS.remove(preffileOld); diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index d29837543..bd7346455 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -43,7 +43,7 @@ class NodeDB void init(); /// write to flash - void saveToDisk(); + void saveToDisk(), saveChannelsToDisk(); /** Reinit radio config if needed, because either: * a) sometimes a buggy android app might send us bogus settings or diff --git a/src/plugins/AdminPlugin.cpp b/src/plugins/AdminPlugin.cpp index 0d3f7a4dc..875b06236 100644 --- a/src/plugins/AdminPlugin.cpp +++ b/src/plugins/AdminPlugin.cpp @@ -96,21 +96,22 @@ void AdminPlugin::handleSetChannel(const Channel &cc) { channels.setChannel(cc); - bool didReset = service.reloadConfig(); - /* FIXME - do we need this still? - if (didReset) { - state = STATE_SEND_MY_INFO; // Squirt a completely new set of configs to the client - } */ + // Just update and save the channels - no need to update the radio for ! primary channel changes + if (cc.index == 0) { + // FIXME, this updates the user preferences also, which isn't needed - we really just want to notify on configChanged + service.reloadConfig(); + } + else { + channels.onConfigChanged(); // tell the radios about this change + nodeDB.saveChannelsToDisk(); + } } void AdminPlugin::handleSetRadio(const RadioConfig &r) { radioConfig = r; - bool didReset = service.reloadConfig(); - /* FIXME - do we need this still? if (didReset) { - state = STATE_SEND_MY_INFO; // Squirt a completely new set of configs to the client - } */ + service.reloadConfig(); } MeshPacket *AdminPlugin::allocReply()