From 7d19e9b0e292d3fbb32113203cee4d10ea8608a2 Mon Sep 17 00:00:00 2001 From: BBBits Date: Sat, 5 Dec 2020 23:51:57 +1300 Subject: [PATCH 1/3] RC-Switch Protocol Disable via Console --- lib/lib_rf/rc-switch/src/RCSwitch.cpp | 30 +++++++++++-- lib/lib_rf/rc-switch/src/RCSwitch.h | 19 +++++++++ tasmota/i18n.h | 6 ++- tasmota/support_command.ino | 11 ++++- tasmota/xdrv_17_rcswitch.ino | 61 ++++++++++++++++++++++++++- 5 files changed, 119 insertions(+), 8 deletions(-) diff --git a/lib/lib_rf/rc-switch/src/RCSwitch.cpp b/lib/lib_rf/rc-switch/src/RCSwitch.cpp index 6efd9f3e7..f5b628c53 100644 --- a/lib/lib_rf/rc-switch/src/RCSwitch.cpp +++ b/lib/lib_rf/rc-switch/src/RCSwitch.cpp @@ -133,6 +133,7 @@ enum { }; #if not defined( RCSwitchDisableReceiving ) + volatile unsigned long long RCSwitch::nReceivedValue = 0; volatile unsigned int RCSwitch::nReceivedBitlength = 0; volatile unsigned int RCSwitch::nReceivedDelay = 0; @@ -145,6 +146,10 @@ const unsigned int RCSwitch::nSeparationLimit = 2600; // 4300 default // should be set to the minimum value of pulselength * the sync signal unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES]; unsigned int RCSwitch::buftimings[4]; +#ifdef BAZMODS +uint64_t_t RCSwitch::enabled_protocol_mask; + +#endif #endif RCSwitch::RCSwitch() { @@ -155,9 +160,16 @@ RCSwitch::RCSwitch() { this->nReceiverInterrupt = -1; this->setReceiveTolerance(60); RCSwitch::nReceivedValue = 0; +#ifdef BAZMODS + RCSwitch::enabled_protocol_mask.value = (1ULL << numProto)-1 ;//pow(2,numProto)-1; +#endif #endif } - +#ifdef BAZMODS +uint8_t RCSwitch::getNumProtos(){ + return numProto; +} +#endif /** * Sets the protocol to send. */ @@ -833,11 +845,21 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() { repeatCount++; // при приеме второго повторного начинаем анализ принятого первым if (repeatCount == 1) { + #ifdef BAZMODS + unsigned long long thismask = 1; + #endif for(unsigned int i = 1; i <= numProto; i++) { - if (receiveProtocol(i, changeCount)) { - // receive succeeded for protocol i - break; + #ifdef BAZMODS + if(enabled_protocol_mask.value & thismask){ +#endif + if (receiveProtocol(i, changeCount)) { + // receive succeeded for protocol i + break; + } + #ifdef BAZMODS } + thismask <<= 1; +#endif } // очищаем количество повторных пакетов repeatCount = 0; diff --git a/lib/lib_rf/rc-switch/src/RCSwitch.h b/lib/lib_rf/rc-switch/src/RCSwitch.h index 0a1e9d821..5af50be16 100644 --- a/lib/lib_rf/rc-switch/src/RCSwitch.h +++ b/lib/lib_rf/rc-switch/src/RCSwitch.h @@ -61,6 +61,17 @@ // Для keeloq нужно увеличить RCSWITCH_MAX_CHANGES до 23+1+66*2+1=157 #define RCSWITCH_MAX_CHANGES 67 // default 67 +typedef union __uint64 +{ + uint64_t value; + struct + { + uint32_t low32; + uint32_t high32; + + } longs; +} uint64_t_t; + class RCSwitch { public: @@ -93,6 +104,10 @@ class RCSwitch { unsigned int getReceivedDelay(); unsigned int getReceivedProtocol(); unsigned int* getReceivedRawdata(); + #ifdef BAZMODS + uint8_t getNumProtos(); + static uint64_t_t enabled_protocol_mask; //perhaps need function to change because used in interrupt + #endif #endif void enableTransmit(int nTransmitterPin); @@ -164,7 +179,9 @@ class RCSwitch { static void handleInterrupt(); static bool receiveProtocol(const int p, unsigned int changeCount); int nReceiverInterrupt; + #endif + int nTransmitterPin; int nRepeatTransmit; @@ -183,6 +200,8 @@ class RCSwitch { static unsigned int timings[RCSWITCH_MAX_CHANGES]; // буфер длительностей последних четырех пакетов, [0] - последний static unsigned int buftimings[4]; + + #endif diff --git a/tasmota/i18n.h b/tasmota/i18n.h index b84ce4265..4d2f0f2d6 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -221,7 +221,8 @@ #define D_LOG_SOME_SETTINGS_RESET "Some settings have been reset" -// Commands tasmota.ino +// Commands tasmota.ino + #define D_CMND_BACKLOG "Backlog" #define D_CMND_DELAY "Delay" #define D_CMND_NODELAY "NoDelay" @@ -496,6 +497,9 @@ #define D_JSON_RFRECEIVED "RfReceived" #define D_CMND_RFRAW "RfRaw" +#define D_CMND_RFRXPROTOCOL "RfRxProtocol" +#define D_JSON_ENABLED_MASK "Enabled-Mask" + // Commands xdrv_08_serial_bridge.ino #define D_CMND_SSERIALSEND "SSerialSend" #define D_CMND_SBAUDRATE "SBaudrate" diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 4b9e21839..c3ac4d2ba 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -18,6 +18,11 @@ */ const char kTasmotaCommands[] PROGMEM = "|" // No prefix +#ifdef BAZMODS +#ifdef USE_RC_SWITCH + D_CMND_RFRXPROTOCOL "|" +#endif +#endif D_CMND_BACKLOG "|" D_CMND_DELAY "|" D_CMND_POWER "|" D_CMND_STATUS "|" D_CMND_STATE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_RESTART "|" D_CMND_POWERONSTATE "|" D_CMND_PULSETIME "|" D_CMND_BLINKTIME "|" D_CMND_BLINKCOUNT "|" D_CMND_SAVEDATA "|" D_CMND_SO "|" D_CMND_SETOPTION "|" D_CMND_TEMPERATURE_RESOLUTION "|" D_CMND_HUMIDITY_RESOLUTION "|" D_CMND_PRESSURE_RESOLUTION "|" D_CMND_POWER_RESOLUTION "|" @@ -43,8 +48,12 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix "|Info|" D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|" D_CMND_TOUCH_NUM "|" D_CMND_CPU_FREQUENCY "|" D_CMND_WIFI #endif // ESP32 ; - void (* const TasmotaCommand[])(void) PROGMEM = { + #ifdef BAZMODS +#ifdef USE_RC_SWITCH + &CmndRfRxProtocol, +#endif +#endif &CmndBacklog, &CmndDelay, &CmndPower, &CmndStatus, &CmndState, &CmndSleep, &CmndUpgrade, &CmndUpgrade, &CmndOtaUrl, &CmndSeriallog, &CmndRestart, &CmndPowerOnState, &CmndPulsetime, &CmndBlinktime, &CmndBlinkcount, &CmndSavedata, &CmndSetoption, &CmndSetoption, &CmndTemperatureResolution, &CmndHumidityResolution, &CmndPressureResolution, &CmndPowerResolution, diff --git a/tasmota/xdrv_17_rcswitch.ino b/tasmota/xdrv_17_rcswitch.ino index 067e3f457..abbafa353 100644 --- a/tasmota/xdrv_17_rcswitch.ino +++ b/tasmota/xdrv_17_rcswitch.ino @@ -16,7 +16,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include +#include "my_user_config.h" +// doesn't pickup defines while editing without this +// dunno if this is unique to my enviroment or everyone experiences it .. #ifdef USE_RC_SWITCH /*********************************************************************************************\ * RF send and receive using RCSwitch library https://github.com/sui77/rc-switch/ @@ -32,8 +36,8 @@ #define D_JSON_RF_PULSE "Pulse" #define D_JSON_RF_REPEAT "Repeat" -const char kRfSendCommands[] PROGMEM = "|" // No prefix - D_CMND_RFSEND; +const char kRfSendCommands[] PROGMEM = "|" D_CMND_RFSEND; // No prefix + void (* const RfSendCommand[])(void) PROGMEM = { &CmndRfSend }; @@ -86,6 +90,10 @@ void RfInit(void) if (PinUsed(GPIO_RFRECV)) { pinMode( Pin(GPIO_RFRECV), INPUT); mySwitch.enableReceive(Pin(GPIO_RFRECV)); +#ifdef BAZMODS + mySwitch.enabled_protocol_mask.longs.high32 = Settings.ex_adc_param1; + mySwitch.enabled_protocol_mask.longs.low32 = Settings.ex_adc_param2; +#endif } } @@ -93,6 +101,55 @@ void RfInit(void) * Commands \*********************************************************************************************/ +#ifdef BAZMODS +void CmndRfRxProtocol(void){ + uint64_t thisbit; + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: index:%d usridx:%d data_len:%d data:%s"),XdrvMailbox.index, XdrvMailbox.usridx, XdrvMailbox.data_len,XdrvMailbox.data); + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test data_len >0")); + //if (XdrvMailbox.data_len > 0) { + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test usridx ==1")); + if (XdrvMailbox.usridx==1) { + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test payload >=0")); + if(XdrvMailbox.payload >=0){ + thisbit = (1ULL << (XdrvMailbox.index-1) ); + if(XdrvMailbox.payload &1){ + mySwitch.enabled_protocol_mask.value |= thisbit; + }else{ + mySwitch.enabled_protocol_mask.value &= ~thisbit; + } + } + }else{ + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test for a")); + if(XdrvMailbox.data[0]=='a'){ + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: set mask all")); + mySwitch.enabled_protocol_mask.value= (1ULL << mySwitch.getNumProtos())-1 ; + }else{ + // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: set mask with value")); + mySwitch.enabled_protocol_mask.value = strtoull(XdrvMailbox.data,nullptr, 0); + } + } + Settings.ex_adc_param1 = mySwitch.enabled_protocol_mask.longs.high32; + Settings.ex_adc_param2 = mySwitch.enabled_protocol_mask.longs.low32; + //} + ResponseClear(); + ResponseAppend_P(PSTR("{\"" D_CMND_RFRXPROTOCOL "\":")); + ResponseAppend_P(PSTR("\"")); + bool gotone = false; + thisbit=1; + for (int i=0;i Date: Sun, 6 Dec 2020 00:13:24 +1300 Subject: [PATCH 2/3] Remove BAZMOD tags --- lib/lib_rf/rc-switch/src/RCSwitch.cpp | 13 ------------- lib/lib_rf/rc-switch/src/RCSwitch.h | 4 +--- tasmota/support_command.ino | 4 ---- tasmota/xdrv_17_rcswitch.ino | 5 +---- 4 files changed, 2 insertions(+), 24 deletions(-) diff --git a/lib/lib_rf/rc-switch/src/RCSwitch.cpp b/lib/lib_rf/rc-switch/src/RCSwitch.cpp index f5b628c53..9fddf23df 100644 --- a/lib/lib_rf/rc-switch/src/RCSwitch.cpp +++ b/lib/lib_rf/rc-switch/src/RCSwitch.cpp @@ -146,10 +146,7 @@ const unsigned int RCSwitch::nSeparationLimit = 2600; // 4300 default // should be set to the minimum value of pulselength * the sync signal unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES]; unsigned int RCSwitch::buftimings[4]; -#ifdef BAZMODS uint64_t_t RCSwitch::enabled_protocol_mask; - -#endif #endif RCSwitch::RCSwitch() { @@ -160,16 +157,12 @@ RCSwitch::RCSwitch() { this->nReceiverInterrupt = -1; this->setReceiveTolerance(60); RCSwitch::nReceivedValue = 0; -#ifdef BAZMODS RCSwitch::enabled_protocol_mask.value = (1ULL << numProto)-1 ;//pow(2,numProto)-1; -#endif #endif } -#ifdef BAZMODS uint8_t RCSwitch::getNumProtos(){ return numProto; } -#endif /** * Sets the protocol to send. */ @@ -845,21 +838,15 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() { repeatCount++; // при приеме второго повторного начинаем анализ принятого первым if (repeatCount == 1) { - #ifdef BAZMODS unsigned long long thismask = 1; - #endif for(unsigned int i = 1; i <= numProto; i++) { - #ifdef BAZMODS if(enabled_protocol_mask.value & thismask){ -#endif if (receiveProtocol(i, changeCount)) { // receive succeeded for protocol i break; } - #ifdef BAZMODS } thismask <<= 1; -#endif } // очищаем количество повторных пакетов repeatCount = 0; diff --git a/lib/lib_rf/rc-switch/src/RCSwitch.h b/lib/lib_rf/rc-switch/src/RCSwitch.h index 5af50be16..92ef61f46 100644 --- a/lib/lib_rf/rc-switch/src/RCSwitch.h +++ b/lib/lib_rf/rc-switch/src/RCSwitch.h @@ -104,10 +104,8 @@ class RCSwitch { unsigned int getReceivedDelay(); unsigned int getReceivedProtocol(); unsigned int* getReceivedRawdata(); - #ifdef BAZMODS uint8_t getNumProtos(); - static uint64_t_t enabled_protocol_mask; //perhaps need function to change because used in interrupt - #endif + static uint64_t_t enabled_protocol_mask; //perhaps need function to change because used in interrupt #endif void enableTransmit(int nTransmitterPin); diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index c3ac4d2ba..e29d8433d 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -18,10 +18,8 @@ */ const char kTasmotaCommands[] PROGMEM = "|" // No prefix -#ifdef BAZMODS #ifdef USE_RC_SWITCH D_CMND_RFRXPROTOCOL "|" -#endif #endif D_CMND_BACKLOG "|" D_CMND_DELAY "|" D_CMND_POWER "|" D_CMND_STATUS "|" D_CMND_STATE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_RESTART "|" D_CMND_POWERONSTATE "|" D_CMND_PULSETIME "|" D_CMND_BLINKTIME "|" D_CMND_BLINKCOUNT "|" D_CMND_SAVEDATA "|" @@ -49,10 +47,8 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // ESP32 ; void (* const TasmotaCommand[])(void) PROGMEM = { - #ifdef BAZMODS #ifdef USE_RC_SWITCH &CmndRfRxProtocol, -#endif #endif &CmndBacklog, &CmndDelay, &CmndPower, &CmndStatus, &CmndState, &CmndSleep, &CmndUpgrade, &CmndUpgrade, &CmndOtaUrl, &CmndSeriallog, &CmndRestart, &CmndPowerOnState, &CmndPulsetime, &CmndBlinktime, &CmndBlinkcount, &CmndSavedata, diff --git a/tasmota/xdrv_17_rcswitch.ino b/tasmota/xdrv_17_rcswitch.ino index abbafa353..779d4def9 100644 --- a/tasmota/xdrv_17_rcswitch.ino +++ b/tasmota/xdrv_17_rcswitch.ino @@ -90,10 +90,8 @@ void RfInit(void) if (PinUsed(GPIO_RFRECV)) { pinMode( Pin(GPIO_RFRECV), INPUT); mySwitch.enableReceive(Pin(GPIO_RFRECV)); -#ifdef BAZMODS mySwitch.enabled_protocol_mask.longs.high32 = Settings.ex_adc_param1; mySwitch.enabled_protocol_mask.longs.low32 = Settings.ex_adc_param2; -#endif } } @@ -101,7 +99,6 @@ void RfInit(void) * Commands \*********************************************************************************************/ -#ifdef BAZMODS void CmndRfRxProtocol(void){ uint64_t thisbit; // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: index:%d usridx:%d data_len:%d data:%s"),XdrvMailbox.index, XdrvMailbox.usridx, XdrvMailbox.data_len,XdrvMailbox.data); @@ -149,7 +146,7 @@ void CmndRfRxProtocol(void){ ResponseJsonEnd(); } -#endif + void CmndRfSend(void) { bool error = false; From c5c28dec253d486a434720bf41a83ab88b5c12c4 Mon Sep 17 00:00:00 2001 From: BBBits Date: Sun, 6 Dec 2020 10:45:01 +1300 Subject: [PATCH 3/3] Address Theo's requests & some cleanups + errors Removed all code changes out i18n.h & support_command.ino --- tasmota/i18n.h | 3 -- tasmota/support_command.ino | 6 --- tasmota/xdrv_17_rcswitch.ino | 97 +++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 4d2f0f2d6..807f1d5c6 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -497,9 +497,6 @@ #define D_JSON_RFRECEIVED "RfReceived" #define D_CMND_RFRAW "RfRaw" -#define D_CMND_RFRXPROTOCOL "RfRxProtocol" -#define D_JSON_ENABLED_MASK "Enabled-Mask" - // Commands xdrv_08_serial_bridge.ino #define D_CMND_SSERIALSEND "SSerialSend" #define D_CMND_SBAUDRATE "SBaudrate" diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index e29d8433d..da7ff3a1c 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -18,9 +18,6 @@ */ const char kTasmotaCommands[] PROGMEM = "|" // No prefix -#ifdef USE_RC_SWITCH - D_CMND_RFRXPROTOCOL "|" -#endif D_CMND_BACKLOG "|" D_CMND_DELAY "|" D_CMND_POWER "|" D_CMND_STATUS "|" D_CMND_STATE "|" D_CMND_SLEEP "|" D_CMND_UPGRADE "|" D_CMND_UPLOAD "|" D_CMND_OTAURL "|" D_CMND_SERIALLOG "|" D_CMND_RESTART "|" D_CMND_POWERONSTATE "|" D_CMND_PULSETIME "|" D_CMND_BLINKTIME "|" D_CMND_BLINKCOUNT "|" D_CMND_SAVEDATA "|" D_CMND_SO "|" D_CMND_SETOPTION "|" D_CMND_TEMPERATURE_RESOLUTION "|" D_CMND_HUMIDITY_RESOLUTION "|" D_CMND_PRESSURE_RESOLUTION "|" D_CMND_POWER_RESOLUTION "|" @@ -47,9 +44,6 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix #endif // ESP32 ; void (* const TasmotaCommand[])(void) PROGMEM = { -#ifdef USE_RC_SWITCH - &CmndRfRxProtocol, -#endif &CmndBacklog, &CmndDelay, &CmndPower, &CmndStatus, &CmndState, &CmndSleep, &CmndUpgrade, &CmndUpgrade, &CmndOtaUrl, &CmndSeriallog, &CmndRestart, &CmndPowerOnState, &CmndPulsetime, &CmndBlinktime, &CmndBlinkcount, &CmndSavedata, &CmndSetoption, &CmndSetoption, &CmndTemperatureResolution, &CmndHumidityResolution, &CmndPressureResolution, &CmndPowerResolution, diff --git a/tasmota/xdrv_17_rcswitch.ino b/tasmota/xdrv_17_rcswitch.ino index 779d4def9..fad417d8f 100644 --- a/tasmota/xdrv_17_rcswitch.ino +++ b/tasmota/xdrv_17_rcswitch.ino @@ -16,11 +16,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include -#include "my_user_config.h" - -// doesn't pickup defines while editing without this -// dunno if this is unique to my enviroment or everyone experiences it .. #ifdef USE_RC_SWITCH /*********************************************************************************************\ * RF send and receive using RCSwitch library https://github.com/sui77/rc-switch/ @@ -35,12 +30,15 @@ #define D_CMND_RFSEND "RFSend" #define D_JSON_RF_PULSE "Pulse" #define D_JSON_RF_REPEAT "Repeat" +#define D_CMND_RFRXPROTOCOL "RfRxProtocol" +#define D_JSON_NONE_ENABLED "None Enabled" -const char kRfSendCommands[] PROGMEM = "|" D_CMND_RFSEND; // No prefix - -void (* const RfSendCommand[])(void) PROGMEM = { - &CmndRfSend }; +const char kRfCommands[] PROGMEM = "|" D_CMND_RFSEND "|" D_CMND_RFRXPROTOCOL; // No prefix + + +void (* const RfCommands[])(void) PROGMEM = { + &CmndRfSend,&CmndRfRxProtocol }; #include @@ -90,58 +88,66 @@ void RfInit(void) if (PinUsed(GPIO_RFRECV)) { pinMode( Pin(GPIO_RFRECV), INPUT); mySwitch.enableReceive(Pin(GPIO_RFRECV)); - mySwitch.enabled_protocol_mask.longs.high32 = Settings.ex_adc_param1; - mySwitch.enabled_protocol_mask.longs.low32 = Settings.ex_adc_param2; + GetMaskFromSettings(); } } - +void GetMaskFromSettings(){ + mySwitch.enabled_protocol_mask.longs.high32 = Settings.ex_adc_param1 ; + mySwitch.enabled_protocol_mask.longs.low32 = Settings.ex_adc_param2 ; +} +void SaveMaskToSettings(){ + Settings.ex_adc_param1 = mySwitch.enabled_protocol_mask.longs.high32; + Settings.ex_adc_param2 = mySwitch.enabled_protocol_mask.longs.low32; + SettingsSave(1); +} /*********************************************************************************************\ * Commands \*********************************************************************************************/ void CmndRfRxProtocol(void){ - uint64_t thisbit; - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: index:%d usridx:%d data_len:%d data:%s"),XdrvMailbox.index, XdrvMailbox.usridx, XdrvMailbox.data_len,XdrvMailbox.data); - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test data_len >0")); - //if (XdrvMailbox.data_len > 0) { - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test usridx ==1")); - if (XdrvMailbox.usridx==1) { - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test payload >=0")); - if(XdrvMailbox.payload >=0){ - thisbit = (1ULL << (XdrvMailbox.index-1) ); - if(XdrvMailbox.payload &1){ - mySwitch.enabled_protocol_mask.value |= thisbit; - }else{ - mySwitch.enabled_protocol_mask.value &= ~thisbit; - } - } - }else{ - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: test for a")); - if(XdrvMailbox.data[0]=='a'){ - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: set mask all")); - mySwitch.enabled_protocol_mask.value= (1ULL << mySwitch.getNumProtos())-1 ; + if(!PinUsed(GPIO_RFRECV))return; +// AddLog_P(LOG_LEVEL_INFO, PSTR("RFR:CmndRfRxProtocol:: index:%d usridx:%d data_len:%d data:\"%s\""),XdrvMailbox.index, XdrvMailbox.usridx, XdrvMailbox.data_len,XdrvMailbox.data); + + uint64_t thisdat; + if (XdrvMailbox.usridx==1) { + if(XdrvMailbox.payload >=0){ + thisdat = (1ULL << (XdrvMailbox.index-1) ); + if(XdrvMailbox.payload &1){ + mySwitch.enabled_protocol_mask.value |= thisdat; }else{ - // AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: set mask with value")); - mySwitch.enabled_protocol_mask.value = strtoull(XdrvMailbox.data,nullptr, 0); + mySwitch.enabled_protocol_mask.value &= ~thisdat; + } + SaveMaskToSettings(); + }else if(XdrvMailbox.data_len > 0) return; // not a number + }else{ + if(XdrvMailbox.data_len >0){ + if(XdrvMailbox.data[0]=='a'){ + mySwitch.enabled_protocol_mask.value= (1ULL << mySwitch.getNumProtos())-1 ; + SaveMaskToSettings(); + }else{ + thisdat = strtoull(XdrvMailbox.data,nullptr, 0); + if(thisdat>0 || XdrvMailbox.data[0]=='0' ){ + mySwitch.enabled_protocol_mask.value = thisdat; + SaveMaskToSettings(); + }else return; // not a number } + } - Settings.ex_adc_param1 = mySwitch.enabled_protocol_mask.longs.high32; - Settings.ex_adc_param2 = mySwitch.enabled_protocol_mask.longs.low32; - //} + } +// AddLog_P(LOG_LEVEL_INFO, PSTR("RFR:CmndRfRxProtocol:: Start responce")); ResponseClear(); ResponseAppend_P(PSTR("{\"" D_CMND_RFRXPROTOCOL "\":")); ResponseAppend_P(PSTR("\"")); bool gotone = false; - thisbit=1; + thisdat=1; for (int i=0;i