Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC-Switch Protocol Disable via Console #10063

Merged
merged 3 commits into from
Dec 6, 2020
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: 13 additions & 4 deletions lib/lib_rf/rc-switch/src/RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -145,6 +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];
uint64_t_t RCSwitch::enabled_protocol_mask;
#endif

RCSwitch::RCSwitch() {
Expand All @@ -155,9 +157,12 @@ RCSwitch::RCSwitch() {
this->nReceiverInterrupt = -1;
this->setReceiveTolerance(60);
RCSwitch::nReceivedValue = 0;
RCSwitch::enabled_protocol_mask.value = (1ULL << numProto)-1 ;//pow(2,numProto)-1;
#endif
}

uint8_t RCSwitch::getNumProtos(){
return numProto;
}
/**
* Sets the protocol to send.
*/
Expand Down Expand Up @@ -833,11 +838,15 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() {
repeatCount++;
// при приеме второго повторного начинаем анализ принятого первым
if (repeatCount == 1) {
unsigned long long thismask = 1;
for(unsigned int i = 1; i <= numProto; i++) {
if (receiveProtocol(i, changeCount)) {
// receive succeeded for protocol i
break;
if(enabled_protocol_mask.value & thismask){
if (receiveProtocol(i, changeCount)) {
// receive succeeded for protocol i
break;
}
}
thismask <<= 1;
}
// очищаем количество повторных пакетов
repeatCount = 0;
Expand Down
17 changes: 17 additions & 0 deletions lib/lib_rf/rc-switch/src/RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -93,6 +104,8 @@ class RCSwitch {
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
uint8_t getNumProtos();
static uint64_t_t enabled_protocol_mask; //perhaps need function to change because used in interrupt
#endif

void enableTransmit(int nTransmitterPin);
Expand Down Expand Up @@ -164,7 +177,9 @@ class RCSwitch {
static void handleInterrupt();
static bool receiveProtocol(const int p, unsigned int changeCount);
int nReceiverInterrupt;

#endif

int nTransmitterPin;
int nRepeatTransmit;

Expand All @@ -183,6 +198,8 @@ class RCSwitch {
static unsigned int timings[RCSWITCH_MAX_CHANGES];
// буфер длительностей последних четырех пакетов, [0] - последний
static unsigned int buftimings[4];


#endif


Expand Down
3 changes: 2 additions & 1 deletion tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion tasmota/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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 = {
&CmndBacklog, &CmndDelay, &CmndPower, &CmndStatus, &CmndState, &CmndSleep, &CmndUpgrade, &CmndUpgrade, &CmndOtaUrl,
&CmndSeriallog, &CmndRestart, &CmndPowerOnState, &CmndPulsetime, &CmndBlinktime, &CmndBlinkcount, &CmndSavedata,
Expand Down
79 changes: 69 additions & 10 deletions tasmota/xdrv_17_rcswitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef USE_RC_SWITCH
/*********************************************************************************************\
* RF send and receive using RCSwitch library https://github.com/sui77/rc-switch/
Expand All @@ -31,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 = "|" // No prefix
D_CMND_RFSEND;
const char kRfCommands[] PROGMEM = "|" D_CMND_RFSEND "|" D_CMND_RFRXPROTOCOL; // No prefix

void (* const RfSendCommand[])(void) PROGMEM = {
&CmndRfSend };

void (* const RfCommands[])(void) PROGMEM = {
&CmndRfSend,&CmndRfRxProtocol };

#include <RCSwitch.h>

Expand Down Expand Up @@ -86,15 +88,74 @@ void RfInit(void)
if (PinUsed(GPIO_RFRECV)) {
pinMode( Pin(GPIO_RFRECV), INPUT);
mySwitch.enableReceive(Pin(GPIO_RFRECV));
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){
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{
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
}

}
}
// AddLog_P(LOG_LEVEL_INFO, PSTR("RFR:CmndRfRxProtocol:: Start responce"));
ResponseClear();
ResponseAppend_P(PSTR("{\"" D_CMND_RFRXPROTOCOL "\":"));
ResponseAppend_P(PSTR("\""));
bool gotone = false;
thisdat=1;
for (int i=0;i<mySwitch.getNumProtos();i++){
if(mySwitch.enabled_protocol_mask.value & thisdat){
ResponseAppend_P(PSTR("%s%d"), (gotone) ? "," : "", i+1);
gotone = true;
}
thisdat <<=1;
}
if(!gotone)ResponseAppend_P(PSTR( D_JSON_NONE_ENABLED ));
ResponseAppend_P(PSTR("\""));
ResponseJsonEnd();

}

void CmndRfSend(void)
{
if(!PinUsed(GPIO_RFSEND))return;
bool error = false;

if (XdrvMailbox.data_len) {
Expand Down Expand Up @@ -175,10 +236,8 @@ bool Xdrv17(uint8_t function)
}
break;
case FUNC_COMMAND:
if (PinUsed(GPIO_RFSEND)) {
result = DecodeCommand(kRfSendCommands, RfSendCommand);
}
break;
result = DecodeCommand(kRfCommands, RfCommands);
break;
case FUNC_INIT:
RfInit();
break;
Expand Down