From ebd964e923c5caf0012cbe94c5691743cf55a41f Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Tue, 4 Apr 2023 10:00:11 +0200 Subject: [PATCH] Indention fixed and comment added. --- firmware/sensor_wind.ino | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/firmware/sensor_wind.ino b/firmware/sensor_wind.ino index b354b99..080329d 100644 --- a/firmware/sensor_wind.ino +++ b/firmware/sensor_wind.ino @@ -5,19 +5,25 @@ #define WIND_DEFAULT_MEAS_INIT 255 volatile unsigned int anemometerRotations = 0; -uint32_t start_meas_wind_time = 0; -int interruptNumber; +volatile uint32_t start_meas_wind_time = 0; +int interruptNumber; #ifndef SENSOR_WIND_NO_ISR void ICACHE_RAM_ATTR _anemometerInterrupt() { + if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis()) + { + // measurement already done, prevent read of further rotations + return; + } + anemometerRotations++; #ifdef DEBUG Serial.print("*"); debug("*"); #endif } -#endif +#endif // end of if not defined SENSOR_WIND_NO_ISR float wind_speed() { @@ -30,9 +36,9 @@ float wind_speed() void start_measure_wind() { - start_meas_wind_time = millis(); anemometerRotations = 0; #ifndef SENSOR_WIND_NO_ISR + start_meas_wind_time = millis(); interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN); attachInterrupt(interruptNumber, _anemometerInterrupt, FALLING); #endif