array of devices
This commit is contained in:
parent
4f0db94c70
commit
c2aaf2b980
@ -4,9 +4,9 @@
|
|||||||
#include "DeviceLdr.h"
|
#include "DeviceLdr.h"
|
||||||
#include "DeviceDht.h"
|
#include "DeviceDht.h"
|
||||||
|
|
||||||
#undef HAS_LDR
|
#define HAS_LDR
|
||||||
#undef HAS_LED
|
#define HAS_LED
|
||||||
#define HAS_DHT
|
#undef HAS_DHT
|
||||||
|
|
||||||
// HAS_LED
|
// HAS_LED
|
||||||
#define PIN_LED_RED D8
|
#define PIN_LED_RED D8
|
||||||
@ -23,41 +23,28 @@ DeviceLdr deviceLdr(PIN_LDR);
|
|||||||
#define TYPE_DHT DHT22
|
#define TYPE_DHT DHT22
|
||||||
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
||||||
|
|
||||||
|
Device * devices[3];
|
||||||
|
|
||||||
void setupHandler() {
|
void setupHandler() {
|
||||||
#ifdef HAS_LDR
|
for (int i = 0; i < 2; i++) {
|
||||||
deviceLdr.setup();
|
devices[i]->setup();
|
||||||
#endif
|
}
|
||||||
#ifdef HAS_LED
|
|
||||||
deviceLed.setup();
|
|
||||||
#endif
|
|
||||||
#ifdef HAS_DHT
|
|
||||||
deviceDht.setup();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopHandler() {
|
void loopHandler() {
|
||||||
#ifdef HAS_LDR
|
for (int i = 0; i < 2; i++) {
|
||||||
deviceLdr.loop();
|
devices[i]->loop();
|
||||||
#endif
|
}
|
||||||
#ifdef HAS_LED
|
|
||||||
deviceLed.loop();
|
|
||||||
#endif
|
|
||||||
#ifdef HAS_DHT
|
|
||||||
deviceDht.loop();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Homie.setFirmware("things", "1.0.0");
|
Homie.setFirmware("things", "1.0.0");
|
||||||
#ifdef HAS_LDR
|
devices[0] = &deviceLed;
|
||||||
deviceLdr.homieRegister();
|
devices[1] = &deviceLdr;
|
||||||
#endif
|
//devices[2] = &deviceDht;
|
||||||
#ifdef HAS_LED
|
for (int i = 0; i < 2; i++) {
|
||||||
deviceLed.homieRegister();
|
devices[i]->homieRegister();
|
||||||
#endif
|
}
|
||||||
#ifdef HAS_DHT
|
|
||||||
deviceDht.homieRegister();
|
|
||||||
#endif
|
|
||||||
Homie.setSetupFunction(setupHandler);
|
Homie.setSetupFunction(setupHandler);
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
Homie.setup();
|
Homie.setup();
|
||||||
|
Loading…
Reference in New Issue
Block a user