when window is opened, continue to send state every 10 mins until it is

closed
This commit is contained in:
Nicu Hodos 2019-02-21 23:15:49 +01:00
parent 1b26db7e91
commit 34a6dbef65
2 changed files with 10 additions and 8 deletions

View File

@ -10,6 +10,7 @@ ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
volatile int counter = 0; volatile int counter = 0;
volatile bool shouldSend = true; volatile bool shouldSend = true;
bool currentState = false;
void setup() { void setup() {
@ -26,7 +27,8 @@ void setup() {
void loop() { void loop() {
if (shouldSend) { if (shouldSend) {
shouldSend = false; shouldSend = false;
sensor.sendStateAndVoltage(digitalRead(SWITCH)); currentState = digitalRead(SWITCH);
sensor.sendStateAndVoltage(currentState);
} }
TinyPower::sleep(); TinyPower::sleep();
} }
@ -34,8 +36,8 @@ void loop() {
ISR(PCINT0_vect) { ISR(PCINT0_vect) {
shouldSend = true; shouldSend = true;
wdt_reset(); wdt_reset();
TinyPower::enableWdt(WDTO_8S);
counter = 0; counter = 0;
TinyPower::enableWdt(WDTO_8S);
} }
ISR(WDT_vect) { ISR(WDT_vect) {
@ -47,8 +49,7 @@ ISR(WDT_vect) {
if (counter % 75 == 0) { if (counter % 75 == 0) {
shouldSend = true; shouldSend = true;
} }
if (counter >= 225) { if (!currentState && counter >= 225) {
TinyPower::disableWdt(); TinyPower::disableWdt();
counter = 0;
} }
} }

View File

@ -9,6 +9,7 @@ ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
volatile int counter = 0; volatile int counter = 0;
volatile bool shouldSend = true; volatile bool shouldSend = true;
bool currentState = false;
void setup() { void setup() {
@ -23,7 +24,8 @@ void setup() {
void loop() { void loop() {
if (shouldSend) { if (shouldSend) {
shouldSend = false; shouldSend = false;
sensor.sendStateAndVoltage(digitalRead(SWITCH)); currentState = digitalRead(SWITCH);
sensor.sendStateAndVoltage(currentState);
} }
TinyPower::sleep(); TinyPower::sleep();
} }
@ -31,8 +33,8 @@ void loop() {
ISR(PCINT0_vect) { ISR(PCINT0_vect) {
shouldSend = true; shouldSend = true;
wdt_reset(); wdt_reset();
TinyPower::enableWdt(WDTO_8S);
counter = 0; counter = 0;
TinyPower::enableWdt(WDTO_8S);
} }
ISR(WDT_vect) { ISR(WDT_vect) {
@ -44,8 +46,7 @@ ISR(WDT_vect) {
if (counter % 75 == 0) { if (counter % 75 == 0) {
shouldSend = true; shouldSend = true;
} }
if (counter >= 225) { if (!currentState && counter >= 225) {
TinyPower::disableWdt(); TinyPower::disableWdt();
counter = 0;
} }
} }