Things/things/DeviceIrRx.h

48 lines
1.1 KiB
C++

#ifndef DEVICEIRRX_H
#define DEVICEIRRX_H
#include "Device.h"
#include <Homie.h>
#include <IRremoteESP8266.h>
class DeviceIrRx : public Device {
public:
inline DeviceIrRx(byte irrxPin, byte powerPin):irrecv(irrxPin) {
pin_irrx = irrxPin;
pin_power = powerPin;
}
virtual void deviceSetup();
virtual void deviceRegister();
virtual void deviceLoop();
private:
byte pin_irrx;
byte pin_power;
IRrecv irrecv;
decode_results results;
HomieNode irRxNode = HomieNode("irrx", "irrx");
};
void DeviceIrRx::deviceSetup() {
//pinMode(pin_irrx, INPUT);
irrecv.enableIRIn();
pinMode(pin_power, OUTPUT);
digitalWrite(pin_power, HIGH);
}
void DeviceIrRx::deviceRegister() {
Homie.registerNode(irRxNode);
}
void DeviceIrRx::deviceLoop() {
if (irrecv.decode(&results)) {
Serial.print("IR-Rx: ");
Serial.println(results.value, HEX);
if (!Homie.setNodeProperty(irRxNode, "value", String(results.value), false)) {
Serial.println("Sending failed");
}
irrecv.resume(); // Receive the next value
}
}
#endif