actually receive ir signals

This commit is contained in:
Ronald Schaten 2016-04-18 11:58:37 +02:00
parent 5691267905
commit f12580cd8e

View File

@ -3,10 +3,11 @@
#include "Device.h" #include "Device.h"
#include <Homie.h> #include <Homie.h>
#include <IRremoteESP8266.h>
class DeviceIrRx : public Device { class DeviceIrRx : public Device {
public: public:
inline DeviceIrRx(byte irrxPin, byte powerPin) { inline DeviceIrRx(byte irrxPin, byte powerPin):irrecv(irrxPin) {
pin_irrx = irrxPin; pin_irrx = irrxPin;
pin_power = powerPin; pin_power = powerPin;
} }
@ -16,11 +17,14 @@ class DeviceIrRx : public Device {
private: private:
byte pin_irrx; byte pin_irrx;
byte pin_power; byte pin_power;
IRrecv irrecv;
decode_results results;
HomieNode irRxNode = HomieNode("irrx", "irrx"); HomieNode irRxNode = HomieNode("irrx", "irrx");
}; };
void DeviceIrRx::deviceSetup() { void DeviceIrRx::deviceSetup() {
pinMode(pin_irrx, INPUT); //pinMode(pin_irrx, INPUT);
irrecv.enableIRIn();
pinMode(pin_power, OUTPUT); pinMode(pin_power, OUTPUT);
digitalWrite(pin_power, HIGH); digitalWrite(pin_power, HIGH);
} }
@ -30,7 +34,14 @@ void DeviceIrRx::deviceRegister() {
} }
void DeviceIrRx::deviceLoop() { void DeviceIrRx::deviceLoop() {
// TODO receive IR 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 #endif