Skip to content

Commit

Permalink
always show RF Module and RF Frequency menu (pr3y#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster committed Aug 9, 2024
1 parent 72474bf commit b84d201
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
12 changes: 2 additions & 10 deletions src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#ifdef HAS_RGB_LED
#include "modules/others/led_control.h"
#endif
#ifdef USE_CC1101_VIA_SPI
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#endif


/**********************************************************************
Expand Down Expand Up @@ -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");
}
Expand Down
25 changes: 22 additions & 3 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*********************************************************************
Expand All @@ -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 )
Expand All @@ -281,6 +299,7 @@ void setRFFreqMenu() {
}
}
}
}
// else
displayError("Invalid frequency");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -373,7 +373,6 @@ void loop() {
void loop() {
setupSdCard();
getConfigs();
if(RfModule==1) initCC1101once();

if(!wifiConnected) {
Serial.println("wifiConnect");
Expand Down

0 comments on commit b84d201

Please sign in to comment.