56 lines
1018 B
C++
56 lines
1018 B
C++
#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
|
|
|
|
#include "DeviceLed.h"
|
|
#include "DeviceLdr.h"
|
|
#include "DeviceDht.h"
|
|
|
|
#define HAS_LDR
|
|
#define HAS_LED
|
|
#undef HAS_DHT
|
|
|
|
// 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 D4
|
|
#define TYPE_DHT DHT22
|
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
|
|
|
Device * devices[3];
|
|
|
|
void setupHandler() {
|
|
for (int i = 0; i < 2; i++) {
|
|
devices[i]->setup();
|
|
}
|
|
}
|
|
|
|
void loopHandler() {
|
|
for (int i = 0; i < 2; i++) {
|
|
devices[i]->loop();
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Homie.setFirmware("things", "1.0.0");
|
|
devices[0] = &deviceLed;
|
|
devices[1] = &deviceLdr;
|
|
//devices[2] = &deviceDht;
|
|
for (int i = 0; i < 2; i++) {
|
|
devices[i]->homieRegister();
|
|
}
|
|
Homie.setSetupFunction(setupHandler);
|
|
Homie.setLoopFunction(loopHandler);
|
|
Homie.setup();
|
|
}
|
|
|
|
void loop() {
|
|
Homie.loop();
|
|
}
|