optimize state reading in wdt, reset wdt counter when interrupting
This commit is contained in:
parent
534039dc08
commit
2508d2cf5e
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
|
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
volatile int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -40,14 +40,16 @@ byte readState() {
|
|||||||
|
|
||||||
ISR(PCINT0_vect) {
|
ISR(PCINT0_vect) {
|
||||||
sensor.sendStateAndVoltage(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
wdt_reset();
|
||||||
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
bool state = readState();
|
bool state = readState();
|
||||||
if (state != currentState) {
|
if (state != currentState) {
|
||||||
sensor.sendStateAndVoltage(readState());
|
sensor.sendStateAndVoltage(state);
|
||||||
updateState();
|
currentState = state;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
if (counter % 225 == 0) {
|
if (counter % 225 == 0) {
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
|
ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
|
||||||
|
|
||||||
int counter = 0;
|
volatile int counter = 0;
|
||||||
bool currentState;
|
bool currentState;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -37,13 +37,15 @@ byte readState() {
|
|||||||
|
|
||||||
ISR(PCINT0_vect) {
|
ISR(PCINT0_vect) {
|
||||||
sensor.sendStateAndVoltage(readState());
|
sensor.sendStateAndVoltage(readState());
|
||||||
|
wdt_reset();
|
||||||
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
bool state = readState();
|
bool state = readState();
|
||||||
if (state != currentState) {
|
if (state != currentState) {
|
||||||
sensor.sendStateAndVoltage(readState());
|
sensor.sendStateAndVoltage(state);
|
||||||
updateState();
|
currentState = state;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user