61 lines
1.3 KiB
C++
61 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"
|
|
|
|
const byte PIN_LED_RED = D8;
|
|
const byte PIN_LED_GREEN = D6;
|
|
const byte PIN_LED_BLUE = D7;
|
|
DeviceLed deviceLed(PIN_LED_RED, PIN_LED_GREEN, PIN_LED_BLUE);
|
|
|
|
const byte PIN_LDR = A0;
|
|
DeviceLdr deviceLdr(PIN_LDR);
|
|
|
|
const byte PIN_DHT = D5;
|
|
const byte TYPE_DHT = DHT22;
|
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
|
|
|
const byte PIN_IRRX = D1;
|
|
const byte PIN_POWER = D0;
|
|
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
|
|
|
|
const byte 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();
|
|
}
|