Things/things/things.ino

66 lines
1.3 KiB
C++

#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
#include "DeviceLed.h"
#include "DeviceLdr.h"
#include "DeviceDht.h"
#include "DeviceIrRx.h"
#include "DeviceIrTx.h"
// HAS_LED
#define PIN_LED_RED D8
#define PIN_LED_GREEN D6
#define PIN_LED_BLUE D7
DeviceLed deviceLed(PIN_LED_RED, PIN_LED_GREEN, PIN_LED_BLUE);
// HAS_LDR
#define PIN_LDR A0
DeviceLdr deviceLdr(PIN_LDR);
// HAS_DHT
#define PIN_DHT D5
#define TYPE_DHT DHT22
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
// HAS_IRRX
#define PIN_IRRX D1
#define PIN_POWER D0
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
// HAS_IRTX
#define PIN_IRTX D2
DeviceIrTx deviceIrTx(PIN_IRTX);
Device* devices[] = {
&deviceLed,
&deviceLdr,
&deviceDht,
&deviceIrRx,
&deviceIrTx,
};
void setupHandler() {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceSetup();
}
}
void loopHandler() {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceLoop();
}
}
void setup() {
Homie.setFirmware("things", "1.0.0");
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceRegister();
}
Homie.setSetupFunction(setupHandler);
Homie.setLoopFunction(loopHandler);
Homie.setup();
}
void loop() {
Homie.loop();
}