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-05-15 22:34:36 +02:00
|
|
|
unsigned int anemometerRotations = 0;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
float wind_speed() {
|
|
|
|
anemometerRotations = 0;
|
2022-05-15 22:34:36 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
|
|
|
|
|
|
|
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
|
2022-05-15 22:34:36 +02:00
|
|
|
delay(1000 * WIND_SENSOR_MEAS_TIME_S); // time to measure
|
2019-08-04 11:56:18 +02:00
|
|
|
detachInterrupt(interruptNumber);
|
|
|
|
|
2022-05-15 22:34:36 +02:00
|
|
|
return (float)anemometerRotations * COUNT_TO_KMH;
|
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
}
|