Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions main/rf/RFConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ void RFConfiguration::saveOnStorage() {
* is not found, a notice is logged, and the RF receiver is enabled with
* default settings.
*
* @param reinitReceiver If true (default), disables and re-enables the receiver.
* If false, only loads the configuration without reinitialization.
*
* @note This function has specific behavior for ESP32 platforms. On ESP32,
* it uses the Preferences library to access stored configuration data.
* For other platforms, it directly enables the active receiver.
*/
void RFConfiguration::loadFromStorage() {
void RFConfiguration::loadFromStorage(bool reinitReceiver) {
#ifdef ESP32
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
preferences.begin(Gateway_Short_Name, true);
Expand All @@ -159,11 +162,13 @@ void RFConfiguration::loadFromStorage() {
} else {
preferences.end();
Log.notice(F("RF Config not found using default" CR));
iRFReceiver.enable();
}
#else
iRFReceiver.enable();
#endif
// Disable and re-enable the receiver to ensure proper initialization
if (reinitReceiver) {
iRFReceiver.disable();
iRFReceiver.enable();
}
}

/**
Expand Down Expand Up @@ -193,8 +198,8 @@ void RFConfiguration::loadFromMessage(JsonObject& RFdata) {
// Restore the default (initial) configuration
reInit();
} else if (RFdata.containsKey("load") && RFdata["load"].as<bool>()) {
// Load the saved configuration, if not initialised
loadFromStorage();
// Load the saved configuration from storage (without receiver reinitialization)
loadFromStorage(false);
}

fromJson(RFdata);
Expand Down
5 changes: 4 additions & 1 deletion main/rf/RFConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ class RFConfiguration {
/**
* Loads the RF configuration from persistent storage and applies it.
*
* @param reinitReceiver If true (default), disables and re-enables the receiver.
* If false, only loads the configuration without reinitialization.
*
* @note This function has specific behavior for ESP32 platforms. On ESP32,
* it uses the Preferences library to access stored configuration data.
* For other platforms, it directly enables the active receiver.
*/
void loadFromStorage();
void loadFromStorage(bool reinitReceiver = true);

/**
* Loads the RF configuration from a JSON object and applies it.
Expand Down