Added clang-format (#623)
* added .clang-format * added names to travis jobs removed deprecated travis option * check github action * added .gitignore
This commit is contained in:
1 parent
661ef9c55e
commit
10a9d00aaf
59 files changed
+2892
-3640
No files matched your search
+61
-82
@@ -29,61 +29,55 @@
|
||||
|
||||
#ifdef ZgatewayRF
|
||||
|
||||
#ifdef ZradioCC1101
|
||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
#endif
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
# endif
|
||||
|
||||
#include <RCSwitch.h> // library for controling Radio frequency switch
|
||||
# include <RCSwitch.h> // library for controling Radio frequency switch
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
#ifdef ZmqttDiscovery
|
||||
void RFtoMQTTdiscovery(unsigned long MQTTvalue)
|
||||
{ //on the fly switch creation from received RF values
|
||||
# ifdef ZmqttDiscovery
|
||||
void RFtoMQTTdiscovery(unsigned long MQTTvalue) { //on the fly switch creation from received RF values
|
||||
char val[11];
|
||||
sprintf(val, "%lu", MQTTvalue);
|
||||
Log.trace(F("switchRFDiscovery" CR));
|
||||
char *switchRF[8] = {"switch", val, "", "", "", val, "", ""};
|
||||
char* switchRF[8] = {"switch", val, "", "", "", val, "", ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
|
||||
Log.trace(F("CreateDiscoverySwitch: %s" CR),switchRF[1]);
|
||||
Log.trace(F("CreateDiscoverySwitch: %s" CR), switchRF[1]);
|
||||
createDiscovery(switchRF[0],
|
||||
subjectRFtoMQTT, switchRF[1], (char *)getUniqueId(switchRF[1], switchRF[2]).c_str(),
|
||||
subjectRFtoMQTT, switchRF[1], (char*)getUniqueId(switchRF[1], switchRF[2]).c_str(),
|
||||
will_Topic, switchRF[3], switchRF[4],
|
||||
switchRF[5], switchRF[6], switchRF[7],
|
||||
0, "", "", true, subjectMQTTtoRF);
|
||||
}
|
||||
#endif
|
||||
|
||||
void setupRF()
|
||||
{
|
||||
# endif
|
||||
|
||||
void setupRF() {
|
||||
//RF init parameters
|
||||
Log.notice(F("RF_EMITTER_PIN: %d " CR), RF_EMITTER_PIN);
|
||||
Log.notice(F("RF_RECEIVER_PIN: %d " CR), RF_RECEIVER_PIN);
|
||||
#ifdef ZradioCC1101 //receiving with CC1101
|
||||
ELECHOUSE_cc1101.Init();
|
||||
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
#endif
|
||||
# ifdef ZradioCC1101 //receiving with CC1101
|
||||
ELECHOUSE_cc1101.Init();
|
||||
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
# endif
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT);
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
Log.trace(F("ZgatewayRF setup done" CR));
|
||||
}
|
||||
|
||||
void RFtoMQTT()
|
||||
{
|
||||
|
||||
if (mySwitch.available())
|
||||
{
|
||||
void RFtoMQTT() {
|
||||
if (mySwitch.available()) {
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
StaticJsonBuffer<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
||||
JsonObject &RFdata = jsonBuffer.createObject();
|
||||
JsonObject& RFdata = jsonBuffer.createObject();
|
||||
Log.trace(F("Rcv. RF" CR));
|
||||
#ifdef ESP32
|
||||
Log.trace(F("RF Task running on core :%d" CR),xPortGetCoreID());
|
||||
#endif
|
||||
# ifdef ESP32
|
||||
Log.trace(F("RF Task running on core :%d" CR), xPortGetCoreID());
|
||||
# endif
|
||||
RFdata.set("value", (unsigned long)mySwitch.getReceivedValue());
|
||||
RFdata.set("protocol", (int)mySwitch.getReceivedProtocol());
|
||||
RFdata.set("length", (int)mySwitch.getReceivedBitlength());
|
||||
@@ -91,16 +85,14 @@ void RFtoMQTT()
|
||||
mySwitch.resetAvailable();
|
||||
|
||||
unsigned long MQTTvalue = RFdata.get<unsigned long>("value");
|
||||
if (!isAduplicate(MQTTvalue) && MQTTvalue != 0)
|
||||
{ // conditions to avoid duplications of RF -->MQTT
|
||||
#ifdef ZmqttDiscovery //component creation for HA
|
||||
if (!isAduplicate(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
|
||||
# ifdef ZmqttDiscovery //component creation for HA
|
||||
RFtoMQTTdiscovery(MQTTvalue);
|
||||
#endif
|
||||
# endif
|
||||
pub(subjectRFtoMQTT, RFdata);
|
||||
Log.trace(F("Store val: %lu" CR), MQTTvalue);
|
||||
storeValue(MQTTvalue);
|
||||
if (repeatRFwMQTT)
|
||||
{
|
||||
if (repeatRFwMQTT) {
|
||||
Log.trace(F("Pub RF for rpt" CR));
|
||||
pub(subjectMQTTtoRF, RFdata);
|
||||
}
|
||||
@@ -108,15 +100,13 @@ void RFtoMQTT()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef simpleReceiving
|
||||
void MQTTtoRF(char *topicOri, char *datacallback)
|
||||
{
|
||||
|
||||
#ifdef ZradioCC1101 // set Receive off and Transmitt on
|
||||
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
|
||||
mySwitch.disableReceive();
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
#endif
|
||||
# ifdef simpleReceiving
|
||||
void MQTTtoRF(char* topicOri, char* datacallback) {
|
||||
# ifdef ZradioCC1101 // set Receive off and Transmitt on
|
||||
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
|
||||
mySwitch.disableReceive();
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
# endif
|
||||
unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295
|
||||
|
||||
// RF DATA ANALYSIS
|
||||
@@ -126,35 +116,29 @@ void MQTTtoRF(char *topicOri, char *datacallback)
|
||||
int valuePLSL = 0;
|
||||
int valueBITS = 0;
|
||||
int pos = topic.lastIndexOf(RFprotocolKey);
|
||||
if (pos != -1)
|
||||
{
|
||||
if (pos != -1) {
|
||||
pos = pos + +strlen(RFprotocolKey);
|
||||
valuePRT = (topic.substring(pos, pos + 1)).toInt();
|
||||
}
|
||||
//We look into the subject to see if a special RF pulselength is defined
|
||||
int pos2 = topic.lastIndexOf(RFpulselengthKey);
|
||||
if (pos2 != -1)
|
||||
{
|
||||
if (pos2 != -1) {
|
||||
pos2 = pos2 + strlen(RFpulselengthKey);
|
||||
valuePLSL = (topic.substring(pos2, pos2 + 3)).toInt();
|
||||
}
|
||||
int pos3 = topic.lastIndexOf(RFbitsKey);
|
||||
if (pos3 != -1)
|
||||
{
|
||||
if (pos3 != -1) {
|
||||
pos3 = pos3 + strlen(RFbitsKey);
|
||||
valueBITS = (topic.substring(pos3, pos3 + 2)).toInt();
|
||||
}
|
||||
|
||||
if ((cmpToMainTopic(topicOri, subjectMQTTtoRF)) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0))
|
||||
{
|
||||
if ((cmpToMainTopic(topicOri, subjectMQTTtoRF)) && (valuePRT == 0) && (valuePLSL == 0) && (valueBITS == 0)) {
|
||||
Log.trace(F("MQTTtoRF dflt" CR));
|
||||
mySwitch.setProtocol(1, 350);
|
||||
mySwitch.send(data, 24);
|
||||
// Acknowledgement to the GTWRF topic
|
||||
pub(subjectGTWRFtoMQTT, datacallback);
|
||||
}
|
||||
else if ((valuePRT != 0) || (valuePLSL != 0) || (valueBITS != 0))
|
||||
{
|
||||
} else if ((valuePRT != 0) || (valuePLSL != 0) || (valueBITS != 0)) {
|
||||
Log.trace(F("MQTTtoRF usr par." CR));
|
||||
if (valuePRT == 0)
|
||||
valuePRT = 1;
|
||||
@@ -170,28 +154,25 @@ void MQTTtoRF(char *topicOri, char *datacallback)
|
||||
// Acknowledgement to the GTWRF topic
|
||||
pub(subjectGTWRFtoMQTT, datacallback); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
|
||||
}
|
||||
#ifdef ZradioCC1101 // set Receive on and Transmitt off
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
mySwitch.disableTransmit();
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
#endif
|
||||
# ifdef ZradioCC1101 // set Receive on and Transmitt off
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
mySwitch.disableTransmit();
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#ifdef jsonReceiving
|
||||
void MQTTtoRF(char *topicOri, JsonObject &RFdata)
|
||||
{ // json object decoding
|
||||
#ifdef ZradioCC1101 // set Receive off and Transmitt on
|
||||
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
|
||||
mySwitch.disableReceive();
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
#endif
|
||||
if (cmpToMainTopic(topicOri, subjectMQTTtoRF))
|
||||
{
|
||||
# ifdef jsonReceiving
|
||||
void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
|
||||
# ifdef ZradioCC1101 // set Receive off and Transmitt on
|
||||
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY);
|
||||
mySwitch.disableReceive();
|
||||
mySwitch.enableTransmit(RF_EMITTER_PIN);
|
||||
# endif
|
||||
if (cmpToMainTopic(topicOri, subjectMQTTtoRF)) {
|
||||
Log.trace(F("MQTTtoRF json" CR));
|
||||
unsigned long data = RFdata["value"];
|
||||
if (data != 0)
|
||||
{
|
||||
if (data != 0) {
|
||||
int valuePRT = RFdata["protocol"] | 1;
|
||||
int valuePLSL = RFdata["delay"] | 350;
|
||||
int valueBITS = RFdata["length"] | 24;
|
||||
@@ -203,19 +184,17 @@ void MQTTtoRF(char *topicOri, JsonObject &RFdata)
|
||||
mySwitch.setProtocol(valuePRT, valuePLSL);
|
||||
mySwitch.send(data, valueBITS);
|
||||
Log.notice(F("MQTTtoRF OK" CR));
|
||||
pub(subjectGTWRFtoMQTT, RFdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
|
||||
pub(subjectGTWRFtoMQTT, RFdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
|
||||
mySwitch.setRepeatTransmit(RF_EMITTER_REPEAT); // Restore the default value
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Log.error(F("MQTTtoRF Fail json" CR));
|
||||
}
|
||||
}
|
||||
#ifdef ZradioCC1101 // set Receive on and Transmitt off
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
mySwitch.disableTransmit();
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
#endif
|
||||
# ifdef ZradioCC1101 // set Receive on and Transmitt off
|
||||
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY);
|
||||
mySwitch.disableTransmit();
|
||||
mySwitch.enableReceive(RF_RECEIVER_PIN);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
Reference in new issue
Block a user