Things/things/DeviceIrRx.h

48 lines
1.1 KiB
C
Raw Normal View History

#ifndef DEVICEIRRX_H
#define DEVICEIRRX_H
#include "Device.h"
#include <Homie.h>
2016-04-18 11:58:37 +02:00
#include <IRremoteESP8266.h>
class DeviceIrRx : public Device {
public:
2016-04-18 11:58:37 +02:00
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;
2016-04-18 11:58:37 +02:00
IRrecv irrecv;
decode_results results;
HomieNode irRxNode = HomieNode("irrx", "irrx");
};
void DeviceIrRx::deviceSetup() {
2016-04-18 11:58:37 +02:00
//pinMode(pin_irrx, INPUT);
irrecv.enableIRIn();
pinMode(pin_power, OUTPUT);
digitalWrite(pin_power, HIGH);
}
void DeviceIrRx::deviceRegister() {
Homie.registerNode(irRxNode);
}
void DeviceIrRx::deviceLoop() {
2016-04-18 11:58:37 +02:00
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