Things/things/things.ino

60 lines
1.2 KiB
Arduino
Raw Normal View History

#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
#include "DeviceLed.h"
2016-04-08 08:18:59 +00:00
#include "DeviceLdr.h"
#include "DeviceDht.h"
#include "DeviceIrRx.h"
2016-04-08 08:18:59 +00:00
// 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
2016-04-08 08:18:59 +00:00
DeviceLdr deviceLdr(PIN_LDR);
// HAS_DHT
2016-04-19 22:29:07 +00:00
#define PIN_DHT D5
#define TYPE_DHT DHT22
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
// HAS_IRRX
#define PIN_IRRX D1
2016-04-19 22:29:07 +00:00
#define PIN_POWER D0
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
2016-04-20 08:34:46 +00:00
Device* devices[] = {
&deviceLed,
&deviceLdr,
&deviceDht,
&deviceIrRx,
};
2016-04-10 21:54:05 +00:00
void setupHandler() {
2016-04-11 19:09:31 +00:00
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
2016-04-10 22:29:05 +00:00
devices[i]->deviceSetup();
2016-04-10 21:54:05 +00:00
}
2016-02-23 10:12:04 +00:00
}
void loopHandler() {
2016-04-11 19:09:31 +00:00
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
2016-04-10 22:29:05 +00:00
devices[i]->deviceLoop();
2016-04-10 21:54:05 +00:00
}
2016-02-24 06:43:01 +00:00
}
2016-02-23 10:12:04 +00:00
void setup() {
Homie.setFirmware("things", "1.0.0");
2016-04-11 19:09:31 +00:00
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
2016-04-10 22:29:05 +00:00
devices[i]->deviceRegister();
2016-04-10 21:54:05 +00:00
}
Homie.setSetupFunction(setupHandler);
Homie.setLoopFunction(loopHandler);
Homie.setup();
2016-02-23 10:12:04 +00:00
}
void loop() {
Homie.loop();
2016-02-23 10:12:04 +00:00
}