#include "config_user.h" #include "config.h" unsigned int anemometerRotations = 0; uint32_t start_meas_wind_time = 0; ICACHE_RAM_ATTR void _anemometerInterrupt() { anemometerRotations++; #ifdef DEBUG Serial.print("*"); #endif } /* float wind_speed() { anemometerRotations = 0; int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN); attachInterrupt(interruptNumber, _anemometerInterrupt, RISING); delay(1000 * WIND_SENSOR_MEAS_TIME_S); // time to measure detachInterrupt(interruptNumber); // calculate the speed as km/h float tmp_speed = (float)anemometerRotations * WINDSPEED_FACTOR; #ifdef DEBUG Serial.print("Windspeed: " + String(tmp_speed)); #endif return tmp_speed; } */ void start_measure_wind() { start_meas_wind_time = millis(); anemometerRotations = 0; interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN); } boolean check_measure_wind_done() { if (start_meas_wind + WIND_SENSOR_MEAS_TIME_S <= millis()) { detachInterrupt(interruptNumber); return true; } return false; } float stop_measure_wind() { return (float)anemometerRotations * WINDSPEED_FACTOR; }