2016-03-30 19:08:18 +00:00
|
|
|
#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
|
|
|
|
|
2016-04-08 22:21:18 +00:00
|
|
|
#include "DeviceLed.h"
|
2016-04-08 08:18:59 +00:00
|
|
|
#include "DeviceLdr.h"
|
2016-04-08 23:12:59 +00:00
|
|
|
#include "DeviceDht.h"
|
2016-04-18 09:34:44 +00:00
|
|
|
#include "DeviceIrRx.h"
|
2016-04-08 08:18:59 +00:00
|
|
|
|
2016-03-30 19:08:18 +00:00
|
|
|
// HAS_LED
|
|
|
|
#define PIN_LED_RED D8
|
|
|
|
#define PIN_LED_GREEN D6
|
|
|
|
#define PIN_LED_BLUE D7
|
2016-04-08 22:21:18 +00:00
|
|
|
DeviceLed deviceLed(PIN_LED_RED, PIN_LED_GREEN, PIN_LED_BLUE);
|
2016-03-30 19:08:18 +00:00
|
|
|
|
|
|
|
// HAS_LDR
|
|
|
|
#define PIN_LDR A0
|
2016-04-08 08:18:59 +00:00
|
|
|
DeviceLdr deviceLdr(PIN_LDR);
|
2016-03-30 19:08:18 +00:00
|
|
|
|
|
|
|
// HAS_DHT
|
|
|
|
#define PIN_DHT D4
|
|
|
|
#define TYPE_DHT DHT22
|
2016-04-08 23:12:59 +00:00
|
|
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
2016-03-30 19:08:18 +00:00
|
|
|
|
2016-04-18 09:34:44 +00:00
|
|
|
// HAS_IRRX
|
|
|
|
#define PIN_IRRX D1
|
|
|
|
#define PIN_POWER D2
|
|
|
|
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
|
|
|
|
|
|
|
|
Device* devices[] = { &deviceLed, &deviceLdr, &deviceIrRx };
|
2016-04-10 21:54:05 +00:00
|
|
|
|
2016-03-30 19:08:18 +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
|
|
|
}
|
|
|
|
|
2016-03-30 19:08:18 +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() {
|
2016-03-30 19:08:18 +00:00
|
|
|
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
|
|
|
}
|
2016-03-30 19:08:18 +00:00
|
|
|
Homie.setSetupFunction(setupHandler);
|
|
|
|
Homie.setLoopFunction(loopHandler);
|
|
|
|
Homie.setup();
|
2016-02-23 10:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-03-30 19:08:18 +00:00
|
|
|
Homie.loop();
|
2016-02-23 10:12:04 +00:00
|
|
|
}
|