Added start, wait, read functions and changed main sensor read function.

This commit is contained in:
Kai Lauterbach 2022-09-14 11:56:41 +02:00
parent 4bd4944d6b
commit 8c907ce1e1

View file

@ -4,6 +4,7 @@
unsigned int anemometerRotations = 0; unsigned int anemometerRotations = 0;
uint32_t start_meas_wind_time = 0; uint32_t start_meas_wind_time = 0;
int interruptNumber;
ICACHE_RAM_ATTR void _anemometerInterrupt() ICACHE_RAM_ATTR void _anemometerInterrupt()
{ {
@ -13,28 +14,14 @@ ICACHE_RAM_ATTR void _anemometerInterrupt()
#endif #endif
} }
/*
float wind_speed() float wind_speed()
{ {
anemometerRotations = 0; start_measure_wind();
do {
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN); delay(1000); // minimum delay of measurement time is 1 second
} while (check_measure_wind_done() == false);
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING); return measure_wind_result();
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() void start_measure_wind()
{ {
@ -45,7 +32,7 @@ void start_measure_wind()
boolean check_measure_wind_done() boolean check_measure_wind_done()
{ {
if (start_meas_wind + WIND_SENSOR_MEAS_TIME_S <= millis()) if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis())
{ {
detachInterrupt(interruptNumber); detachInterrupt(interruptNumber);
return true; return true;
@ -53,7 +40,7 @@ boolean check_measure_wind_done()
return false; return false;
} }
float stop_measure_wind() float measure_wind_result()
{ {
return (float)anemometerRotations * WINDSPEED_FACTOR; return (float)anemometerRotations * WINDSPEED_FACTOR;
} }