Big wheaterstation update #2

Closed
klaute wants to merge 19 commits from master into feature/http_call_send_json
Showing only changes of commit 1e4075a0f5 - Show all commits

View file

@ -2,6 +2,8 @@
#include "config_user.h" #include "config_user.h"
#include "config.h" #include "config.h"
#define WIND_DEFAULT_MEAS_INIT 255
volatile unsigned int anemometerRotations = 0; volatile unsigned int anemometerRotations = 0;
uint32_t start_meas_wind_time = 0; uint32_t start_meas_wind_time = 0;
int interruptNumber; int interruptNumber;
@ -38,35 +40,37 @@ void start_measure_wind()
boolean check_measure_wind_done() boolean check_measure_wind_done()
{ {
static uint8_t previous_pin_state = 255; static uint8_t previous_pin_state = WIND_DEFAULT_MEAS_INIT;
static uint8_t tmp_pin_state = 255; static uint8_t tmp_pin_state = WIND_DEFAULT_MEAS_INIT;
static uint32_t meas_time_done = 0;
#ifndef SENSOR_WIND_NO_ISR
// interrupt routine based measurement
if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis()) if ((start_meas_wind_time + (WIND_SENSOR_MEAS_TIME_S * 1000)) <= millis())
{ {
#ifndef SENSOR_WIND_NO_ISR
detachInterrupt(interruptNumber); detachInterrupt(interruptNumber);
#endif
return true; return true;
}
#endif
#ifdef SENSOR_WIND_NO_ISR #ifdef SENSOR_WIND_NO_ISR
if (meas_time_done >= (WIND_SENSOR_MEAS_TIME_S * 1000))
{
meas_time_done = 0;
previous_pin_state = WIND_DEFAULT_MEAS_INIT;
return true;
} else { } else {
// measure wind without ISR // measure wind without ISR
uint32_t start = millis(); uint32_t start = millis();
/*#ifdef DEBUG
Serial.print(".");
debug(".");
#endif*/
do { do {
// read pin state // read pin state
previous_pin_state = tmp_pin_state; previous_pin_state = tmp_pin_state;
tmp_pin_state = digitalRead(ANEMOMETER_PIN); tmp_pin_state = digitalRead(ANEMOMETER_PIN);
/*#ifdef DEBUG if (previous_pin_state != tmp_pin_state && previous_pin_state != WIND_DEFAULT_MEAS_INIT)
Serial.print("+");
debug("+");
#endif*/
if (previous_pin_state != tmp_pin_state && previous_pin_state != 255)
{ {
anemometerRotations++; anemometerRotations++;
#ifdef DEBUG #ifdef DEBUG
@ -83,8 +87,12 @@ boolean check_measure_wind_done()
WDT_FEED(); WDT_FEED();
#endif #endif
} while ((start + WIND_SPEED_MEAS_NO_ISR_TIME_MS) >= millis()); } while ((start + WIND_SPEED_MEAS_NO_ISR_TIME_MS) >= millis());
#endif // SENSOR_WIND_NO_ISR
meas_time_done += WIND_SPEED_MEAS_NO_ISR_TIME_MS;
} }
#endif // SENSOR_WIND_NO_ISR
return false; return false;
} }