Browse Source

sns/event: change counter variable only in the isr

ensure the only operation from main loop() is load
since isr handles incrementing the counter, resulting value is calculated as
offset between the current and the previous reading (always positive)
mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
735e5c0ec2
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      code/espurna/sensors/EventSensor.h

+ 5
- 5
code/espurna/sensors/EventSensor.h View File

@ -105,18 +105,16 @@ class EventSensor : public BaseSensor {
} }
void pre() override { void pre() override {
ETS_GPIO_INTR_DISABLE();
_last = _current;
_current = _counter; _current = _counter;
_counter = 0ul;
ETS_GPIO_INTR_ENABLE();
} }
double value(unsigned char index) override { double value(unsigned char index) override {
switch (index) { switch (index) {
case 0: case 0:
return _current;
return _current - _last;
case 1: case 1:
return (_current > 0) ? 1.0 : 0.0;
return (_current - _last > 0) ? 1.0 : 0.0;
default: default:
return 0.0; return 0.0;
} }
@ -170,7 +168,9 @@ class EventSensor : public BaseSensor {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
unsigned long _counter { 0ul }; unsigned long _counter { 0ul };
unsigned long _current { 0ul }; unsigned long _current { 0ul };
unsigned long _last { 0ul };
unsigned long _isr_last { 0ul }; unsigned long _isr_last { 0ul };
unsigned long _isr_debounce { microsecondsToClockCycles(EVENTS1_DEBOUNCE * 1000) }; unsigned long _isr_debounce { microsecondsToClockCycles(EVENTS1_DEBOUNCE * 1000) };


Loading…
Cancel
Save