Things/things/DeviceIrTx.cpp

82 lines
2.4 KiB
C++

#include "DeviceIrTx.h"
void DeviceIrTx::deviceSetup() {
// pinMode(pin_irtx, OUTPUT); // this is done by begin()
irsend.begin();
}
bool DeviceIrTx::irTxHandler(String message) {
DynamicJsonBuffer json_inBuffer;
JsonObject& json_in = json_inBuffer.parseObject(message);
if (json_in.success()) {
unsigned long data = 0;
int nbits = 0;
if (json_in.containsKey("data")) {
data = json_in["data"];
}
if (json_in.containsKey("nbits")) {
nbits = json_in["nbits"];
}
if (json_in.containsKey("protocol")) {
String protocol = json_in["protocol"];
protocol.toUpperCase();
Serial.print("IR-Tx: sending ");
Serial.print(data);
Serial.print(" (");
Serial.print(nbits);
Serial.print(") via ");
Serial.print(protocol);
Serial.println(" Protocol");
for (int i = 0; i < 5; i++) {
if (protocol == "NEC") {
irsend.sendNEC(data, nbits);
} else if (protocol == "SONY") {
irsend.sendSony(data, nbits);
} else if (protocol == "RC5") {
irsend.sendRC5(data, nbits);
} else if (protocol == "RC6") {
irsend.sendRC6(data, nbits);
} else if (protocol == "DISH") {
irsend.sendDISH(data, nbits);
} else if (protocol == "SHARP") {
irsend.sendSharp(data, nbits);
} else if (protocol == "PANASONIC") {
irsend.sendPanasonic(data, nbits);
/* JVC needs a repeat parameter, will be implemented if necessary
} else if (protocol == "JVC") {
int repeat = 0;
irsend.sendJVC(data, nbits, repeat);
*/
/* Sanyo and Mitsubishi aren't implemented in the library
} else if (protocol == "SANYO") {
irsend.sendSanyo(data, nbits);
} else if (protocol == "MITSUBISHI") {
irsend.sendMitsubishi(data, nbits);
*/
} else if (protocol == "SAMSUNG") {
irsend.sendSAMSUNG(data, nbits);
} else if (protocol == "LG") {
irsend.sendLG(data, nbits);
} else if (protocol == "WHYNTER") {
irsend.sendLG(data, nbits);
} else {
Serial.println("IR protocol not implemented");
}
delay(40);
}
}
} else {
Serial.println("parsing of JSON failed");
}
return true;
}
void DeviceIrTx::deviceRegister() {
irTxNode.subscribe("irtx", [this](String value) { return irTxHandler(value); });
Homie.registerNode(irTxNode);
}
void DeviceIrTx::deviceLoop() {
return;
}