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