Files
MyNotificationClock/MyNotificationLight.ino
2018-03-16 22:25:13 +01:00

105 lines
2.5 KiB
Arduino

#include <nodemanager_config.h>
#include <MySensors.h>
#include <NodeManager.h>
#include "NotificationLEDs.h"
#define SENSOR_CHECK_INTERVAL 2000
#define MSG_SEND_CYCLES 15
#define MSG_SEND_INTERVAL 30000
#define PIN_BUZZER 3
#define PIN_RGBW 5
#define PIN_MOTION 6
#define PIN_DOOR0 A0
#define PIN_DOOR1 A1
#define PIN_DOOR2 A2
#define PIN_DOOR3 A3
#define PIN_MOTION2 A5
#define SENSOR_ID_RGBW 0
#define SENSOR_ID_DIMMER 1
#define SENSOR_ID_POWERSWITCH 2
#define SENSOR_ID_COMMAND 3
#define SENSOR_ID_MOTION 10
#define SENSOR_ID_DOOR0 11
#define SENSOR_ID_DOOR1 12
#define SENSOR_ID_DOOR2 13
#define SENSOR_ID_DOOR3 14
#define SENSOR_ID_MOTION2 15
#define SENSOR_ID_VCC 210
#define DIN_DEBOUNCE 6
#define UNIXTIME_FETCH_INTERVAL_SEC 300
#define NEOPIXEL_LEDCOUNT 16
// create a NodeManager instance
typedef NodeManager<
Tuple<
NotificationLEDs<PIN_RGBW, SENSOR_ID_RGBW, SENSOR_ID_DIMMER, SENSOR_ID_POWERSWITCH, SENSOR_ID_COMMAND, NEOPIXEL_LEDCOUNT>,
SensorMotion<PIN_MOTION, SENSOR_ID_MOTION, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorMotion<PIN_MOTION2, SENSOR_ID_MOTION2, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorDoor<PIN_DOOR0, SENSOR_ID_DOOR0, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorDoor<PIN_DOOR1, SENSOR_ID_DOOR1, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorDoor<PIN_DOOR2, SENSOR_ID_DOOR2, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorDoor<PIN_DOOR3, SENSOR_ID_DOOR3, INPUT_PULLUP, DIN_DEBOUNCE, MSG_SEND_INTERVAL>,
SensorVcc<SENSOR_ID_VCC, SENSOR_CHECK_INTERVAL, MSG_SEND_CYCLES>
>
> MyNodeManagerBase;
class MyNodeManager : public MyNodeManagerBase {
protected:
} nodeManager;
void before() {
//nodeManager.setSleep(ALWAYS_ON, 1, SECONDS);
nodeManager.before();
}
void presentation() {
nodeManager.presentation();
}
void receive(const MyMessage &message) {
if (!message.isAck()) {
nodeManager.receive(message);
}
}
unsigned long unixTime = 0;
unsigned long unixTimeMillis = 0;
void receiveTime(unsigned long ts) {
unixTime = ts;
unixTimeMillis = millis();
nodeManager.receiveTime(ts);
}
void setup() {
nodeManager.setup();
}
void loop() {
auto currentMillis = millis();
auto diffMillis = currentMillis - unixTimeMillis;
auto diffSeconds = diffMillis/1000;
long currentUnixTime = unixTime + diffSeconds;
if (unixTime == 0 || diffSeconds >= UNIXTIME_FETCH_INTERVAL_SEC) {
requestTime();
}
nodeManager.loop(currentUnixTime, currentMillis);
}