array of devices

This commit is contained in:
Ronald Schaten 2016-04-10 23:54:05 +02:00
parent 4f0db94c70
commit c2aaf2b980

View File

@ -4,9 +4,9 @@
#include "DeviceLdr.h"
#include "DeviceDht.h"
#undef HAS_LDR
#undef HAS_LED
#define HAS_DHT
#define HAS_LDR
#define HAS_LED
#undef HAS_DHT
// HAS_LED
#define PIN_LED_RED D8
@ -23,41 +23,28 @@ DeviceLdr deviceLdr(PIN_LDR);
#define TYPE_DHT DHT22
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
Device * devices[3];
void setupHandler() {
#ifdef HAS_LDR
deviceLdr.setup();
#endif
#ifdef HAS_LED
deviceLed.setup();
#endif
#ifdef HAS_DHT
deviceDht.setup();
#endif
for (int i = 0; i < 2; i++) {
devices[i]->setup();
}
}
void loopHandler() {
#ifdef HAS_LDR
deviceLdr.loop();
#endif
#ifdef HAS_LED
deviceLed.loop();
#endif
#ifdef HAS_DHT
deviceDht.loop();
#endif
for (int i = 0; i < 2; i++) {
devices[i]->loop();
}
}
void setup() {
Homie.setFirmware("things", "1.0.0");
#ifdef HAS_LDR
deviceLdr.homieRegister();
#endif
#ifdef HAS_LED
deviceLed.homieRegister();
#endif
#ifdef HAS_DHT
deviceDht.homieRegister();
#endif
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();