2016-04-22 22:45:45 +02:00
|
|
|
#include <Homie.h> // https://github.com/marvinroger/homie-esp8266
|
2016-03-30 21:08:18 +02:00
|
|
|
|
2016-04-09 00:21:18 +02:00
|
|
|
#include "DeviceLed.h"
|
2016-04-08 10:18:59 +02:00
|
|
|
#include "DeviceLdr.h"
|
2016-04-09 01:12:59 +02:00
|
|
|
#include "DeviceDht.h"
|
2016-04-18 11:34:44 +02:00
|
|
|
#include "DeviceIrRx.h"
|
2016-04-20 22:34:15 +02:00
|
|
|
#include "DeviceIrTx.h"
|
2016-04-24 12:17:15 +02:00
|
|
|
#include "DeviceButton.h"
|
2016-04-08 10:18:59 +02:00
|
|
|
|
2016-04-22 22:42:18 +02:00
|
|
|
const byte PIN_LED_RED = D8;
|
|
|
|
const byte PIN_LED_GREEN = D6;
|
|
|
|
const byte PIN_LED_BLUE = D7;
|
2016-04-09 00:21:18 +02:00
|
|
|
DeviceLed deviceLed(PIN_LED_RED, PIN_LED_GREEN, PIN_LED_BLUE);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
2016-04-22 22:42:18 +02:00
|
|
|
const byte PIN_LDR = A0;
|
2016-04-08 10:18:59 +02:00
|
|
|
DeviceLdr deviceLdr(PIN_LDR);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
2016-04-22 22:42:18 +02:00
|
|
|
const byte PIN_DHT = D5;
|
|
|
|
const byte TYPE_DHT = DHT22;
|
2016-04-09 01:12:59 +02:00
|
|
|
DeviceDht deviceDht(PIN_DHT, TYPE_DHT);
|
2016-03-30 21:08:18 +02:00
|
|
|
|
2016-04-22 22:42:18 +02:00
|
|
|
const byte PIN_IRRX = D1;
|
|
|
|
const byte PIN_POWER = D0;
|
2016-04-18 11:34:44 +02:00
|
|
|
DeviceIrRx deviceIrRx(PIN_IRRX, PIN_POWER);
|
|
|
|
|
2016-04-22 22:42:18 +02:00
|
|
|
const byte PIN_IRTX = D2;
|
2016-04-20 22:34:15 +02:00
|
|
|
DeviceIrTx deviceIrTx(PIN_IRTX);
|
|
|
|
|
2016-04-24 12:17:15 +02:00
|
|
|
const byte PIN_BUTTON = D2;
|
|
|
|
DeviceButton deviceButton(PIN_BUTTON);
|
|
|
|
|
2016-04-20 10:34:46 +02:00
|
|
|
Device* devices[] = {
|
|
|
|
&deviceLed,
|
|
|
|
&deviceLdr,
|
|
|
|
&deviceDht,
|
|
|
|
&deviceIrRx,
|
2016-04-20 22:34:15 +02:00
|
|
|
&deviceIrTx,
|
2016-04-24 12:17:15 +02:00
|
|
|
&deviceButton,
|
2016-04-20 10:34:46 +02:00
|
|
|
};
|
2016-04-10 23:54:05 +02:00
|
|
|
|
2016-03-30 21:08:18 +02:00
|
|
|
void setupHandler() {
|
2016-04-11 21:09:31 +02:00
|
|
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
2016-04-11 00:29:05 +02:00
|
|
|
devices[i]->deviceSetup();
|
2016-04-10 23:54:05 +02:00
|
|
|
}
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|
|
|
|
|
2016-03-30 21:08:18 +02:00
|
|
|
void loopHandler() {
|
2016-04-11 21:09:31 +02:00
|
|
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
2016-04-11 00:29:05 +02:00
|
|
|
devices[i]->deviceLoop();
|
2016-04-10 23:54:05 +02:00
|
|
|
}
|
2016-02-24 07:43:01 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:12:04 +01:00
|
|
|
void setup() {
|
2016-03-30 21:08:18 +02:00
|
|
|
Homie.setFirmware("things", "1.0.0");
|
2016-04-11 21:09:31 +02:00
|
|
|
for (int i = 0; i < sizeof(devices) / sizeof(*devices); i++) {
|
2016-04-11 00:29:05 +02:00
|
|
|
devices[i]->deviceRegister();
|
2016-04-10 23:54:05 +02:00
|
|
|
}
|
2016-03-30 21:08:18 +02:00
|
|
|
Homie.setSetupFunction(setupHandler);
|
|
|
|
Homie.setLoopFunction(loopHandler);
|
|
|
|
Homie.setup();
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-03-30 21:08:18 +02:00
|
|
|
Homie.loop();
|
2016-02-23 11:12:04 +01:00
|
|
|
}
|