elegant array handling
This commit is contained in:
parent
c145154f3b
commit
7cafe6cccb
@ -19,26 +19,23 @@ 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];
|
Device* devices[] = { &deviceLed, &deviceLdr };
|
||||||
|
|
||||||
void setupHandler() {
|
void setupHandler() {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
||||||
devices[i]->deviceSetup();
|
devices[i]->deviceSetup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopHandler() {
|
void loopHandler() {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
||||||
devices[i]->deviceLoop();
|
devices[i]->deviceLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Homie.setFirmware("things", "1.0.0");
|
Homie.setFirmware("things", "1.0.0");
|
||||||
devices[0] = &deviceLed;
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
||||||
devices[1] = &deviceLdr;
|
|
||||||
//devices[2] = &deviceDht;
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
devices[i]->deviceRegister();
|
devices[i]->deviceRegister();
|
||||||
}
|
}
|
||||||
Homie.setSetupFunction(setupHandler);
|
Homie.setSetupFunction(setupHandler);
|
||||||
|
Loading…
Reference in New Issue
Block a user