elegant array handling

This commit is contained in:
Ronald Schaten 2016-04-11 21:09:31 +02:00
parent c145154f3b
commit 7cafe6cccb

View File

@ -19,26 +19,23 @@ DeviceLdr deviceLdr(PIN_LDR);
#define TYPE_DHT DHT22
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
Device * devices[3];
Device* devices[] = { &deviceLed, &deviceLdr };
void setupHandler() {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceSetup();
}
}
void loopHandler() {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceLoop();
}
}
void setup() {
Homie.setFirmware("things", "1.0.0");
devices[0] = &deviceLed;
devices[1] = &deviceLdr;
//devices[2] = &deviceDht;
for (int i = 0; i < 2; i++) {
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
devices[i]->deviceRegister();
}
Homie.setSetupFunction(setupHandler);