diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index fcffb0eb..ebe2bc5d 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -31,9 +31,6 @@ #ifdef HAS_RGB_LED #include "modules/others/led_control.h" #endif -#ifdef USE_CC1101_VIA_SPI -#include -#endif /********************************************************************** @@ -187,18 +184,13 @@ void configOptions(){ {"Ir RX Pin", [=]() { gsetIrRxPin(true); saveConfigs();}}, {"RF TX Pin", [=]() { gsetRfTxPin(true); saveConfigs();}}, {"RF RX Pin", [=]() { gsetRfRxPin(true); saveConfigs();}}, + {"RF Module", [=]() { setRFModuleMenu(); saveConfigs();}}, + {"RF Frequency", [=]() { setRFFreqMenu(); saveConfigs();}}, {"Sleep", [=]() { setSleepMode(); }}, {"Restart", [=]() { ESP.restart(); }}, {"Main Menu", [=]() { backToMenu(); }}, }; -#ifdef USE_CC1101_VIA_SPI - if(ELECHOUSE_cc1101.getCC1101()) { // show these options only if the cc1101 is detected - options.push_back({"RF Module", [=]() { setRFModuleMenu(); saveConfigs();}}); - options.push_back({"RF Frequency", [=]() { setRFFreqMenu(); saveConfigs();}}); - } -#endif - delay(200); loopOptions(options,false,true,"Config"); } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 22342f51..87713557 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -245,13 +245,30 @@ void setRFModuleMenu() { options = { {"M5 RF433T/R", [&]() { result = 0; }}, +#ifdef USE_CC1101_VIA_SPI {"CC1101 on SPI", [&]() { result = 1; }}, +#endif +/* WIP: + * #ifdef USE_CC1101_VIA_PCA9554 + * {"CC1101+PCA955", [&]() { result = 2; }}, + * #endif +*/ }; delay(200); - loopOptions(options); + loopOptions(options); // TODO: pre-select current value of RfModule? delay(200); - RfModule=result; + if(result == 1) { + // try to init again + if(initRfModule("rx", RfFreq)) { // try to init in rx mode and check if successfull + RfModule=1; + return; + } + // else display a warning + displayError("CC1101 init error"); + } + // fallback to "M5 RF433T/R on errors + RfModule=0; } /********************************************************************* @@ -261,8 +278,9 @@ void setRFModuleMenu() { void setRFFreqMenu() { // TODO: save the setting in the EEPROM too? float result = 433.92; - String freq_str = keyboard("433.92", 10, "Default frequency:"); + String freq_str = keyboard(String(RfFreq), 10, "Default frequency:"); if(freq_str.length()>1) + { if(sscanf(freq_str.c_str(), "%f", &result)==1) { if(RfModule!=1 && result>100 && result<1000 ) @@ -281,6 +299,7 @@ void setRFFreqMenu() { } } } + } // else displayError("Invalid frequency"); } diff --git a/src/main.cpp b/src/main.cpp index ec87b1b3..e401a53f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ int IrTx; int IrRx; int RfTx; int RfRx; -int RfModule=0; // 0 - single-pinned, 1 - CC1101 +int RfModule=0; // 0 - single-pinned, 1 - CC1101+SPI float RfFreq=433.92; int dimmerSet; int bright=100; @@ -373,7 +373,6 @@ void loop() { void loop() { setupSdCard(); getConfigs(); - if(RfModule==1) initCC1101once(); if(!wifiConnected) { Serial.println("wifiConnect");