Apply VSC auto format to the code and indent macros for readability

This commit is contained in:
1technophile committed 2019-12-14 17:14:36 +01:00
1 parent f7ec81ffaa
commit 7f9d8d18da
26 files changed
+4512 -3692

No files matched your search

+90 -70
View File
@@ -27,114 +27,134 @@
*/
#include "User_config.h"
#ifdef ZgatewayPilight
#include <ESPiLight.h>
ESPiLight rf(RF_EMITTER_PIN); // use -1 to disable transmitter
#ifdef ZgatewayPilight
#include <ESPiLight.h>
ESPiLight rf(RF_EMITTER_PIN); // use -1 to disable transmitter
void pilightCallback(const String &protocol,const String &message, int status,
size_t repeats, const String &deviceID) {
if (status == VALID) {
void pilightCallback(const String &protocol, const String &message, int status,
size_t repeats, const String &deviceID)
{
if (status == VALID)
{
trc(F("Creating RF PiLight buffer"));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject& RFPiLightdata = jsonBuffer.createObject();
JsonObject &RFPiLightdata = jsonBuffer.createObject();
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer2;
JsonObject& msg = jsonBuffer2.parseObject(message);
JsonObject &msg = jsonBuffer2.parseObject(message);
RFPiLightdata.set("message", msg);
RFPiLightdata.set("protocol",(char *)protocol.c_str());
RFPiLightdata.set("protocol", (char *)protocol.c_str());
RFPiLightdata.set("length", (char *)deviceID.c_str());
RFPiLightdata.set("repeats", (int)repeats);
RFPiLightdata.set("status", (int)status);
pub(subjectPilighttoMQTT,RFPiLightdata);
if (repeatPilightwMQTT){
trc(F("Pub Pilight for rpt"));
pub(subjectMQTTtoPilight,RFPiLightdata);
pub(subjectPilighttoMQTT, RFPiLightdata);
if (repeatPilightwMQTT)
{
trc(F("Pub Pilight for rpt"));
pub(subjectMQTTtoPilight, RFPiLightdata);
}
}
}
}
void setupPilight(){
#ifndef ZgatewayRF && ZgatewayRF2 && ZgatewayRF315 //receiving with Pilight is not compatible with ZgatewayRF or RF2 or RF315 as far as I can tell
rf.setCallback(pilightCallback);
rf.initReceiver(RF_RECEIVER_PIN);
trc(F("RF_EMITTER_PIN "));
trc(String(RF_EMITTER_PIN));
trc(F("RF_RECEIVER_PIN "));
trc(String(RF_RECEIVER_PIN));
trc(F("ZgatewayPilight setup done "));
#else
trc(F("ZgatewayPilight setup cannot be done, comment first ZgatewayRF && ZgatewayRF2 && ZgatewayRF315"));
#endif
void setupPilight()
{
#ifndef ZgatewayRF &&ZgatewayRF2 &&ZgatewayRF315 //receiving with Pilight is not compatible with ZgatewayRF or RF2 or RF315 as far as I can tell
rf.setCallback(pilightCallback);
rf.initReceiver(RF_RECEIVER_PIN);
trc(F("RF_EMITTER_PIN "));
trc(String(RF_EMITTER_PIN));
trc(F("RF_RECEIVER_PIN "));
trc(String(RF_RECEIVER_PIN));
trc(F("ZgatewayPilight setup done "));
#else
trc(F("ZgatewayPilight setup cannot be done, comment first ZgatewayRF && ZgatewayRF2 && ZgatewayRF315"));
#endif
}
void PilighttoMQTT(){
void PilighttoMQTT()
{
rf.loop();
}
void MQTTtoPilight(char * topicOri, JsonObject& Pilightdata) {
void MQTTtoPilight(char *topicOri, JsonObject &Pilightdata)
{
int result = 0;
if (cmpToMainTopic(topicOri,subjectMQTTtoPilight)){
if (cmpToMainTopic(topicOri, subjectMQTTtoPilight))
{
trc(F("MQTTtoPilight json data analysis"));
const char * message = Pilightdata["message"];
const char * protocol = Pilightdata["protocol"];
const char * raw = Pilightdata["raw"];
if(raw){
const char *message = Pilightdata["message"];
const char *protocol = Pilightdata["protocol"];
const char *raw = Pilightdata["raw"];
if (raw)
{
int msgLength = 0;
uint16_t codes[MAXPULSESTREAMLENGTH];
msgLength = rf.stringToPulseTrain(
raw,
codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) {
if (msgLength > 0)
{
trc(F("MQTTtoPilight raw ok"));
rf.sendPulseTrain(codes, msgLength);
result = msgLength;
}else{
}
else
{
trc(F("MQTTtoPilight raw KO"));
switch (result) {
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_C:
trc(F("'c' not found in string, or has no data"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_P:
trc(F("'p' not found in string, or has no data"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_END:
trc(F("';' or '@' not found in data string"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_TYPE:
trc(F("pulse type not defined"));
break;
switch (result)
{
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_C:
trc(F("'c' not found in string, or has no data"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_P:
trc(F("'p' not found in string, or has no data"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_END:
trc(F("';' or '@' not found in data string"));
break;
case ESPiLight::ERROR_INVALID_PULSETRAIN_MSG_TYPE:
trc(F("pulse type not defined"));
break;
}
}
}else if (message && protocol) {
}
else if (message && protocol)
{
trc(F("MQTTtoPilight msg & protocol ok"));
result = rf.send(protocol, message);
}else{
}
else
{
trc(F("MQTTtoPilight failed json read"));
}
if (result > 0) {
if (result > 0)
{
trc(F("Adv data MQTTtoPilight push state via PilighttoMQTT"));
pub(subjectGTWPilighttoMQTT, Pilightdata);
} else {
switch (result) {
case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL:
trc(F("protocol is not available"));
break;
case ESPiLight::ERROR_INVALID_PILIGHT_MSG:
trc(F("message is invalid"));
break;
case ESPiLight::ERROR_INVALID_JSON:
trc(F("message is not a proper json object"));
break;
case ESPiLight::ERROR_NO_OUTPUT_PIN:
trc(F("no transmitter pin"));
break;
default:
trc(F("invalid json data, can't read raw or message/protocol"));
break;
}
else
{
switch (result)
{
case ESPiLight::ERROR_UNAVAILABLE_PROTOCOL:
trc(F("protocol is not available"));
break;
case ESPiLight::ERROR_INVALID_PILIGHT_MSG:
trc(F("message is invalid"));
break;
case ESPiLight::ERROR_INVALID_JSON:
trc(F("message is not a proper json object"));
break;
case ESPiLight::ERROR_NO_OUTPUT_PIN:
trc(F("no transmitter pin"));
break;
default:
trc(F("invalid json data, can't read raw or message/protocol"));
break;
}
}
}
}
#endif
#endif