Add command ``RfProtocol`` to control RcSwitch

Add command ``RfProtocol`` to control RcSwitch receive protocols by BBBits (#10063)
This commit is contained in:
Theo Arends 2020-12-06 14:58:00 +01:00
parent 6a3ef272a8
commit 80ab642076
8 changed files with 91 additions and 101 deletions

View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- Fallback NTP server from x.pool.ntp.org if no ntpservers are configured
- TyuaMcu update 2/3 by Federico Leoni (#10004)
- Optional CCloader support for CC25xx Zigbee or CC26xx BLE by Christian Baars (#9970)
- Command ``RfProtocol`` to control RcSwitch receive protocols by BBBits (#10063)
### Breaking Changed
- KNX DPT9 (16-bit float) to DPT14 (32-bit float) by Adrian Scillato (#9811, #9888)

View File

@ -60,6 +60,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
### Added
- Command ``SetOption115 1`` to enable ESP32 MiBle
- Command ``SetOption116 1`` to disable auto-query of zigbee light devices (avoids network storms with large groups)
- Command ``RfProtocol`` to control RcSwitch receive protocols by BBBits (#10063)
- Commands ``TuyaRGB``, ``TuyaEnum`` and ``TuyaEnumList`` (#9769)
- Zigbee command ``ZbInfo`` and prepare support for EEPROM
- Zigbee command ``ZbLeave`` to unpair a device

View File

@ -133,8 +133,8 @@ enum {
};
#if not defined( RCSwitchDisableReceiving )
volatile unsigned long long RCSwitch::nReceivedValue = 0;
volatile unsigned long long RCSwitch::nReceiveProtocolMask;
volatile unsigned int RCSwitch::nReceivedBitlength = 0;
volatile unsigned int RCSwitch::nReceivedDelay = 0;
volatile unsigned int RCSwitch::nReceivedProtocol = 0;
@ -146,7 +146,6 @@ 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() {
@ -157,10 +156,11 @@ RCSwitch::RCSwitch() {
this->nReceiverInterrupt = -1;
this->setReceiveTolerance(60);
RCSwitch::nReceivedValue = 0;
RCSwitch::enabled_protocol_mask.value = (1ULL << numProto)-1 ;//pow(2,numProto)-1;
RCSwitch::nReceiveProtocolMask = (1ULL << numProto)-1; //pow(2,numProto)-1;
#endif
}
uint8_t RCSwitch::getNumProtos(){
uint8_t RCSwitch::getNumProtos() {
return numProto;
}
/**
@ -214,6 +214,10 @@ void RCSwitch::setRepeatTransmit(int nRepeatTransmit) {
void RCSwitch::setReceiveTolerance(int nPercent) {
RCSwitch::nReceiveTolerance = nPercent;
}
void RCSwitch::setReceiveProtocolMask(unsigned long long mask) {
RCSwitch::nReceiveProtocolMask = mask;
}
#endif
@ -840,7 +844,7 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() {
if (repeatCount == 1) {
unsigned long long thismask = 1;
for(unsigned int i = 1; i <= numProto; i++) {
if(enabled_protocol_mask.value & thismask){
if (RCSwitch::nReceiveProtocolMask & thismask) {
if (receiveProtocol(i, changeCount)) {
// receive succeeded for protocol i
break;

View File

@ -61,17 +61,6 @@
// Для 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:
@ -105,7 +94,6 @@ class RCSwitch {
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);
@ -114,6 +102,7 @@ class RCSwitch {
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
void setReceiveProtocolMask(unsigned long long mask);
#endif
/**
@ -177,17 +166,15 @@ class RCSwitch {
static void handleInterrupt();
static bool receiveProtocol(const int p, unsigned int changeCount);
int nReceiverInterrupt;
#endif
int nTransmitterPin;
int nRepeatTransmit;
Protocol protocol;
#if not defined( RCSwitchDisableReceiving )
static int nReceiveTolerance;
volatile static unsigned long long nReceivedValue;
volatile static unsigned long long nReceiveProtocolMask;
volatile static unsigned int nReceivedBitlength;
volatile static unsigned int nReceivedDelay;
volatile static unsigned int nReceivedProtocol;
@ -198,8 +185,6 @@ class RCSwitch {
static unsigned int timings[RCSWITCH_MAX_CHANGES];
// буфер длительностей последних четырех пакетов, [0] - последний
static unsigned int buftimings[4];
#endif

View File

@ -222,7 +222,6 @@
#define D_LOG_SOME_SETTINGS_RESET "Some settings have been reset"
// Commands tasmota.ino
#define D_CMND_BACKLOG "Backlog"
#define D_CMND_DELAY "Delay"
#define D_CMND_NODELAY "NoDelay"

View File

@ -642,9 +642,14 @@ struct {
uint16_t shd_warmup_brightness; // F5C
uint8_t shd_warmup_time; // F5E
uint8_t free_f5e[84]; // F5E - Decrement if adding new Setting variables just above and below
uint8_t free_f5e[72]; // F5E - Decrement if adding new Setting variables just above and below
// Only 32 bit boundary variables below
uint64_t rf_protocol_mask; // FA8
uint32_t free_fb0[1]; // FB0
SysBitfield5 flag5; // FB4
uint16_t pulse_counter_debounce_low; // FB8
uint16_t pulse_counter_debounce_high; // FBA

View File

@ -43,6 +43,7 @@ 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,

View File

@ -28,17 +28,17 @@
#define D_JSON_RF_DATA "Data"
#define D_CMND_RFSEND "RFSend"
#define D_CMND_RFPROTOCOL "RfProtocol"
#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 kRfCommands[] PROGMEM = "|" D_CMND_RFSEND "|" D_CMND_RFRXPROTOCOL; // No prefix
const char kRfCommands[] PROGMEM = "|" // No prefix
D_CMND_RFSEND "|" D_CMND_RFPROTOCOL;
void (* const RfCommands[])(void) PROGMEM = {
&CmndRfSend,&CmndRfRxProtocol };
&CmndRfSend, &CmndRfProtocol };
#include <RCSwitch.h>
@ -48,8 +48,7 @@ RCSwitch mySwitch = RCSwitch();
uint32_t rf_lasttime = 0;
void RfReceiveCheck(void)
{
void RfReceiveCheck(void) {
if (mySwitch.available()) {
unsigned long data = mySwitch.getReceivedValue();
@ -80,82 +79,77 @@ void RfReceiveCheck(void)
}
}
void RfInit(void)
{
void RfInit(void) {
if (PinUsed(GPIO_RFSEND)) {
mySwitch.enableTransmit(Pin(GPIO_RFSEND));
}
if (PinUsed(GPIO_RFRECV)) {
pinMode( Pin(GPIO_RFRECV), INPUT);
mySwitch.enableReceive(Pin(GPIO_RFRECV));
GetMaskFromSettings();
if (!Settings.rf_protocol_mask) {
Settings.rf_protocol_mask = (1ULL << mySwitch.getNumProtos()) -1;
}
mySwitch.setReceiveProtocolMask(Settings.rf_protocol_mask);
}
}
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;
void CmndRfProtocol(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;
if (1 == XdrvMailbox.usridx) {
if (XdrvMailbox.payload >= 0) {
thisdat = (1ULL << (XdrvMailbox.index -1));
if (XdrvMailbox.payload &1) {
Settings.rf_protocol_mask |= thisdat;
} else {
Settings.rf_protocol_mask &= ~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
}
else if (XdrvMailbox.data_len > 0) {
return; // Not a number
}
} else {
if (XdrvMailbox.data_len > 0) {
if ('a' == XdrvMailbox.data[0]) {
Settings.rf_protocol_mask = (1ULL << mySwitch.getNumProtos()) -1;
} else {
thisdat = strtoull(XdrvMailbox.data, nullptr, 0);
if ((thisdat > 0) || ('0' == XdrvMailbox.data[0])) {
Settings.rf_protocol_mask = thisdat;
} 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("\""));
mySwitch.setReceiveProtocolMask(Settings.rf_protocol_mask);
// AddLog_P(LOG_LEVEL_INFO, PSTR("RFR: CmndRfProtocol:: Start responce"));
Response_P(PSTR("{\"" D_CMND_RFPROTOCOL "\":\""));
bool gotone = false;
thisdat=1;
for (int i=0;i<mySwitch.getNumProtos();i++){
if(mySwitch.enabled_protocol_mask.value & thisdat){
thisdat = 1;
for (uint32_t i = 0; i < mySwitch.getNumProtos(); i++) {
if (Settings.rf_protocol_mask & thisdat) {
ResponseAppend_P(PSTR("%s%d"), (gotone) ? "," : "", i+1);
gotone = true;
}
thisdat <<=1;
}
if(!gotone)ResponseAppend_P(PSTR( D_JSON_NONE_ENABLED ));
if (!gotone) { ResponseAppend_P(PSTR(D_JSON_NONE_ENABLED)); }
ResponseAppend_P(PSTR("\""));
ResponseJsonEnd();
}
void CmndRfSend(void)
{
if(!PinUsed(GPIO_RFSEND))return;
if (!PinUsed(GPIO_RFSEND)) { return; }
bool error = false;
if (XdrvMailbox.data_len) {