2016-04-18 11:34:44 +02:00
|
|
|
#ifndef DEVICEIRRX_H
|
|
|
|
#define DEVICEIRRX_H
|
|
|
|
|
|
|
|
#include "Device.h"
|
|
|
|
#include <Homie.h>
|
2016-04-18 11:58:37 +02:00
|
|
|
#include <IRremoteESP8266.h>
|
2016-04-18 11:34:44 +02:00
|
|
|
|
|
|
|
class DeviceIrRx : public Device {
|
|
|
|
public:
|
2016-04-18 11:58:37 +02:00
|
|
|
inline DeviceIrRx(byte irrxPin, byte powerPin):irrecv(irrxPin) {
|
2016-04-18 11:34:44 +02:00
|
|
|
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;
|
2016-04-18 11:34:44 +02:00
|
|
|
HomieNode irRxNode = HomieNode("irrx", "irrx");
|
|
|
|
};
|
|
|
|
|
|
|
|
void DeviceIrRx::deviceSetup() {
|
2016-04-18 11:58:37 +02:00
|
|
|
//pinMode(pin_irrx, INPUT);
|
|
|
|
irrecv.enableIRIn();
|
2016-04-18 11:34:44 +02:00
|
|
|
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
|
|
|
|
}
|
2016-04-18 11:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|