2022-05-15 22:34:36 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
#include "config_user.h"
|
2022-05-15 22:34:36 +02:00
|
|
|
#include "config.h"
|
2019-08-04 11:56:18 +02:00
|
|
|
|
2022-09-14 00:10:03 +02:00
|
|
|
unsigned int anemometerRotations = 0;
|
|
|
|
uint32_t start_meas_wind_time = 0;
|
2022-09-14 11:56:41 +02:00
|
|
|
int interruptNumber;
|
2019-08-04 11:56:18 +02:00
|
|
|
|
2022-05-15 22:34:36 +02:00
|
|
|
ICACHE_RAM_ATTR void _anemometerInterrupt()
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
anemometerRotations++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.print("*");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:45:08 +02:00
|
|
|
float wind_speed()
|
|
|
|
{
|
2022-09-14 11:56:41 +02:00
|
|
|
start_measure_wind();
|
|
|
|
do {
|
|
|
|
delay(1000); // minimum delay of measurement time is 1 second
|
|
|
|
} while (check_measure_wind_done() == false);
|
|
|
|
return measure_wind_result();
|
2019-08-04 11:56:18 +02:00
|
|
|
}
|
2022-09-14 00:10:03 +02:00
|
|
|
|
|
|
|
void start_measure_wind()
|
|
|
|
{
|
2022-09-15 13:04:42 +02:00
|
|
|
|
2022-09-14 00:10:03 +02:00
|
|
|
start_meas_wind_time = millis();
|
|
|
|
anemometerRotations = 0;
|
|
|
|
interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
2022-09-15 13:04:42 +02:00
|
|
|
|
2022-09-14 00:10:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean check_measure_wind_done()
|
|
|
|
{
|
2022-09-14 11:56:41 +02:00
|
|
|
if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis())
|
2022-09-14 00:10:03 +02:00
|
|
|
{
|
|
|
|
detachInterrupt(interruptNumber);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:56:41 +02:00
|
|
|
float measure_wind_result()
|
2022-09-14 00:10:03 +02:00
|
|
|
{
|
2022-09-15 13:04:42 +02:00
|
|
|
start_meas_wind_time = 0;
|
2022-09-14 00:10:03 +02:00
|
|
|
return (float)anemometerRotations * WINDSPEED_FACTOR;
|
|
|
|
}
|