added new device type IrRx (infrared receiver)

This commit is contained in:
Ronald Schaten 2016-04-18 11:34:44 +02:00
parent 7cafe6cccb
commit 5691267905
2 changed files with 43 additions and 1 deletions

36
things/DeviceIrRx.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef DEVICEIRRX_H
#define DEVICEIRRX_H
#include "Device.h"
#include <Homie.h>
class DeviceIrRx : public Device {
public:
inline DeviceIrRx(byte irrxPin, byte powerPin) {
pin_irrx = irrxPin;
pin_power = powerPin;
}
virtual void deviceSetup();
virtual void deviceRegister();
virtual void deviceLoop();
private:
byte pin_irrx;
byte pin_power;
HomieNode irRxNode = HomieNode("irrx", "irrx");
};
void DeviceIrRx::deviceSetup() {
pinMode(pin_irrx, INPUT);
pinMode(pin_power, OUTPUT);
digitalWrite(pin_power, HIGH);
}
void DeviceIrRx::deviceRegister() {
Homie.registerNode(irRxNode);
}
void DeviceIrRx::deviceLoop() {
// TODO receive IR
}
#endif

View File

@ -3,6 +3,7 @@
#include "DeviceLed.h"
#include "DeviceLdr.h"
#include "DeviceDht.h"
#include "DeviceIrRx.h"
// HAS_LED
#define PIN_LED_RED D8
@ -19,7 +20,12 @@ DeviceLdr deviceLdr(PIN_LDR);
#define TYPE_DHT DHT22
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
Device* devices[] = { &deviceLed, &deviceLdr };
// HAS_IRRX
#define PIN_IRRX D1
#define PIN_POWER D2
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
Device* devices[] = { &deviceLed, &deviceLdr, &deviceIrRx };
void setupHandler() {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {