46 lines
907 B
C++
46 lines
907 B
C++
|
|
#include "config_user.h"
|
|
#include "config.h"
|
|
|
|
unsigned int anemometerRotations = 0;
|
|
uint32_t start_meas_wind_time = 0;
|
|
int interruptNumber;
|
|
|
|
ICACHE_RAM_ATTR void _anemometerInterrupt()
|
|
{
|
|
anemometerRotations++;
|
|
#ifdef DEBUG
|
|
Serial.print("*");
|
|
#endif
|
|
}
|
|
|
|
float wind_speed()
|
|
{
|
|
start_measure_wind();
|
|
do {
|
|
delay(1000); // minimum delay of measurement time is 1 second
|
|
} while (check_measure_wind_done() == false);
|
|
return measure_wind_result();
|
|
}
|
|
|
|
void start_measure_wind()
|
|
{
|
|
start_meas_wind_time = millis();
|
|
anemometerRotations = 0;
|
|
interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
|
}
|
|
|
|
boolean check_measure_wind_done()
|
|
{
|
|
if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis())
|
|
{
|
|
detachInterrupt(interruptNumber);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
float measure_wind_result()
|
|
{
|
|
return (float)anemometerRotations * WINDSPEED_FACTOR;
|
|
}
|