fix raingauge first flip amount

This commit is contained in:
interfisch 2020-11-13 16:12:19 +01:00
parent a53fd957af
commit 5cea05e0be
1 changed files with 7 additions and 2 deletions

View File

@ -210,7 +210,7 @@ struct sensordata
sensordata dataRaingauge;
unsigned long raingauge_lasttimereset=0;
uint16_t raingauge_pulsecounter=0; //counted pulses since last reset
bool raingauge_idleflag=true;
#define RAINGAUGE_DEBOUNCETIME 1000
unsigned long raingauge_lastpulse_fordebounce=0;
@ -1011,11 +1011,16 @@ void loop_raingauge()
bool _changed=false;
if (millis() >= (d.lastreadtime+d.readdelay)) {
if (millis()-raingauge_lasttimereset > d.senddelaymax) {
raingauge_idleflag=true; //raingauge didn't flip for a long time
}
if (raingauge_pulsecounter>0){ //if rg flipped
if (millis()-raingauge_lasttimereset > d.senddelaymax) { //last flip is before reset time
if (raingauge_idleflag) { //last flip is before reset time
value_raingauge=raingauge_pulsecounter*RAINGAUGE_FLIPAMOUNT; //set to fixed amount if flip was exactly at that time
raingauge_idleflag=false;
}else{
value_raingauge=3600000/(millis()-raingauge_lasttimereset)/raingauge_pulsecounter*RAINGAUGE_FLIPAMOUNT;
raingauge_idleflag=false;
}
_changed=true;
}