rc-gateway/devices/presence_ticker/src/presence_ticker.cpp

37 lines
704 B
C++

#include <Arduino.h>
#include <TinyPower.h>
#include "ContactSensor.h"
#define MINUTES(value) (uint16_t)(value*60/8) // minutes*60(seconds)/8s(WDT)
#define HOURS(value) MINUTES(value)*60
#define SEND_INTERVAL MINUTES(2)
#define SEND_VCC_INTERVAL HOURS(6)
// Pins
#define SENDER_PIN PIN_B2
volatile uint16_t counter = 0;
ContactSensor sensor(PRESENCE_SENSOR);
void setup() {
TinySwitch::setup(SENDER_PIN);
TinyPower::setup();
TinyPower::enableWdt(WDTO_8S);
}
void loop() {
if (counter % SEND_VCC_INTERVAL == 0) {
sensor.sendStateAndVoltage(true);
counter = 0;
} else if (counter % SEND_INTERVAL == 0) {
sensor.sendState(true);
}
TinyPower::sleep();
}
ISR(WDT_vect) {
counter++;
}