Template
timing tweak
This commit is contained in:
+38
-39
@@ -96,43 +96,6 @@ void hotwater_setup() {
|
||||
|
||||
// loop() is called repeatedly
|
||||
void hotwater_loop () {
|
||||
|
||||
switch (state){
|
||||
case S0: //wait for flow threshold before turning pump on
|
||||
if (flowChanged && pumpEnabled) {
|
||||
state = S1;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
DPRINT("pump start @ ");
|
||||
DPRINTLN(ticktime);
|
||||
pumpOn = true;
|
||||
pumpEnabled = false;
|
||||
pumpstart_tc = ticktime;
|
||||
}
|
||||
break;
|
||||
case S1: //wait for pump off
|
||||
if (!pumpOn) {
|
||||
state = S2;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
}
|
||||
break;
|
||||
case S2: //wait for flow to stop
|
||||
if (!flowChanged) { // wait for flow to stop; don't need to keep pumping!
|
||||
state = S3;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
//totalflow = Tflow;
|
||||
}
|
||||
break;
|
||||
case S3: //wait for hysteresis time before cycling again
|
||||
if (pumpEnabled) { // limit duty cycle
|
||||
state = S0;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
}
|
||||
break;
|
||||
} // FSM
|
||||
|
||||
|
||||
|
||||
|
||||
// process interrupt
|
||||
if (intflag_FLOW) {
|
||||
if (FLOWING){
|
||||
@@ -144,19 +107,20 @@ void hotwater_loop () {
|
||||
DPRINTLN("flow interrupt");
|
||||
}
|
||||
|
||||
|
||||
if (millis()+DEBOUNCE > FLOW_eventtime){ // this is a debounce
|
||||
flowChanged = true;
|
||||
FLOW_eventtime = ULONG_MAX;
|
||||
}
|
||||
// record flowstart time
|
||||
if ((flowChanged == true) && (FLOWING) && (flowstart_tc == 0)) {
|
||||
flowstart_tc = ticktime; // only set flowstarted time once!
|
||||
flowstart_tc = ticktime;
|
||||
DPRINTLN("flow start");
|
||||
}
|
||||
|
||||
// flow start
|
||||
if ((flowChanged == true) && (flowstart_tc > 0)){
|
||||
if(ticktime > flowstart_tc){
|
||||
if(ticktime > flowstart_tc + TWOSECONDS){ // flow state changes 2 sec after flowstopped
|
||||
flowChanged = false;
|
||||
reportFlowChange = true;
|
||||
flowOn = true;
|
||||
@@ -192,6 +156,7 @@ void hotwater_loop () {
|
||||
flowstart_tc = 0;
|
||||
pumpstart_tc = 0;
|
||||
pumpstop_tc = ticktime;
|
||||
reportPumpChange = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,4 +196,38 @@ void hotwater_loop () {
|
||||
}
|
||||
}
|
||||
|
||||
switch (state){
|
||||
case S0: //wait for flow threshold before turning pump on
|
||||
if (flowOn && pumpEnabled) {
|
||||
state = S1;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
DPRINT("pump start @ ");
|
||||
DPRINTLN(ticktime);
|
||||
pumpOn = true;
|
||||
pumpEnabled = false;
|
||||
pumpstart_tc = ticktime;
|
||||
reportPumpChange = true;
|
||||
}
|
||||
break;
|
||||
case S1: //wait for pump off
|
||||
if (!pumpOn) {
|
||||
state = S2;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
}
|
||||
break;
|
||||
case S2: //wait for flow to stop
|
||||
if (!flowOn) { // wait for flow to stop; don't need to keep pumping!
|
||||
state = S3;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
//totalflow = Tflow;
|
||||
}
|
||||
break;
|
||||
case S3: //wait for hysteresis time before cycling again
|
||||
if (pumpEnabled) { // limit duty cycle
|
||||
state = S0;
|
||||
if (FSM_DEBUG) DEBUGSTATE(state)
|
||||
}
|
||||
break;
|
||||
} // FSM
|
||||
|
||||
} // end loop()
|
||||
|
||||
+13
-22
@@ -134,52 +134,43 @@ void mqtt_loop() {
|
||||
// record flow
|
||||
if (reportFlowChange) {
|
||||
mqtt_connect();
|
||||
mqttClient.beginMessage(topic);
|
||||
if (flowOn) {
|
||||
flowstarted = WiFi.getTime();
|
||||
mqttClient.beginMessage(topic);
|
||||
mqttClient.print("start flow event@: ");
|
||||
DPRINT(flowstarted);
|
||||
DPRINTLN();
|
||||
mqttClient.print(flowstarted);
|
||||
mqttClient.endMessage();
|
||||
reportFlowChange = false; // do once
|
||||
DPRINTLN(flowstarted);
|
||||
mqttClient.print(flowstarted);
|
||||
} else {
|
||||
flowstopped = WiFi.getTime();
|
||||
mqttClient.beginMessage(topic);
|
||||
mqttClient.print("stop flow event@: ");
|
||||
DPRINT(flowstopped);
|
||||
DPRINTLN();
|
||||
DPRINTLN(flowstopped);
|
||||
mqttClient.print(flowstopped);
|
||||
mqttClient.endMessage();
|
||||
reportFlowChange = false; // do once
|
||||
}
|
||||
mqttClient.endMessage();
|
||||
mqttClient.stop();
|
||||
reportFlowChange = false; // do once
|
||||
}
|
||||
|
||||
|
||||
// record pump activity
|
||||
if (pumpChanged) {
|
||||
if (reportPumpChange) {
|
||||
mqtt_connect();
|
||||
mqttClient.beginMessage(topic);
|
||||
if (pumpOn) {
|
||||
pumpstarted = WiFi.getTime();
|
||||
mqttClient.beginMessage(topic);
|
||||
mqttClient.print("start pump event@: ");
|
||||
DPRINT(pumpstarted);
|
||||
DPRINTLN();
|
||||
DPRINTLN(pumpstarted);
|
||||
mqttClient.print(pumpstarted);
|
||||
mqttClient.endMessage();
|
||||
pumpChanged = false; // once is enough
|
||||
} else {
|
||||
pumpstopped = WiFi.getTime();
|
||||
mqttClient.beginMessage(topic);
|
||||
mqttClient.print("stop pump event@: ");
|
||||
DPRINT(pumpstopped);
|
||||
DPRINTLN();
|
||||
DPRINTLN(pumpstopped);
|
||||
mqttClient.print(pumpstopped);
|
||||
mqttClient.endMessage();
|
||||
pumpChanged = false; // once is enough
|
||||
}
|
||||
}
|
||||
mqttClient.endMessage();
|
||||
mqttClient.stop();
|
||||
reportPumpChange = false; // do once
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ void hotwater_loop();
|
||||
volatile boolean intflag_FLOW = false; // external GPIO interrupt (event)
|
||||
volatile unsigned long ticktime = 0;
|
||||
volatile unsigned int ticknum = 0;
|
||||
volatile unsigned long FLOW_eventtime = 0;
|
||||
volatile unsigned long FLOW_eventtime = ULONG_MAX;
|
||||
|
||||
unsigned long FLOW_starttime;
|
||||
unsigned long FLOW_stoptime;
|
||||
|
||||
Reference in New Issue
Block a user