diff --git a/src/brewHandler.h b/src/brewHandler.h index ea6717b4..c880320f 100644 --- a/src/brewHandler.h +++ b/src/brewHandler.h @@ -46,7 +46,7 @@ uint8_t currBrewSwitchStateMomentary = LOW; int brewSwitchState = kBrewSwitchIdle; boolean brewSwitchWasOff = false; -int isBrewDetected = 0; // flag is set if brew was detected +int brewOn = 0; // flag is set if brew was detected double totalBrewTime = 0; // total brewtime set in software double timeBrewed = 0; // total brewed time double lastBrewTimeMillis = 0; // for shottimer delay after disarmed button @@ -102,7 +102,7 @@ void checkbrewswitch() { if (currBrewSwitchStateMomentary == LOW) { // Brew trigger currStateBrewSwitch = HIGH; - isBrewDetected = 1; + brewOn = 1; brewSwitchState = kBrewSwitchBrewAbort; LOG(DEBUG, "brewSwitchState = kBrewSwitchBrew; brew switch short pressed - start Brew"); } @@ -122,7 +122,7 @@ void checkbrewswitch() { if ((currBrewSwitchStateMomentary == HIGH && currStateBrewSwitch == HIGH) || (machineState == kShotTimerAfterBrew) || (backflushState == kBackflushWaitBrewswitchOff)) { currStateBrewSwitch = LOW; brewSwitchState = kBrewSwitchReset; - isBrewDetected = 0; + brewOn = 0; LOG(DEBUG, "brewSwitchState = kBrewSwitchBrewAbort: brew switch short pressed - stop brew"); } break; @@ -131,7 +131,7 @@ void checkbrewswitch() { // Brew switch got released - stop flushing if (currBrewSwitchStateMomentary == LOW && currStateBrewSwitch == LOW) { brewSwitchState = kBrewSwitchReset; - isBrewDetected = 0; + brewOn = 0; LOG(DEBUG, "brewswitchTriggerCase = kBrewSwitchFlushOff: brew switch long press released - stop flushing"); valveRelay.off(); pumpRelay.off(); @@ -233,6 +233,37 @@ void backflush() { } } +#if (FEATURE_BREWCONTROL == 0) +/** + * @brief Brew timer + */ +void brewTimer() { + unsigned long currentMillisTemp = millis(); + checkbrewswitch(); + + // Start the timer when the brew switch is turned on + if (currStateBrewSwitch == HIGH && currBrewState == kBrewIdle) { + startingTime = currentMillisTemp; + currBrewState = kBrewRunning; + LOG(INFO, "Brew timer started"); + } + + // Update the brewed time if the brew switch is still on + if (currStateBrewSwitch == HIGH && currBrewState == kBrewRunning) { + timeBrewed = currentMillisTemp - startingTime; + } + + // Stop the timer when the brew switch is turned off + if (currStateBrewSwitch == LOW && currBrewState == kBrewRunning) { + LOG(INFO, "Brew timer stopped"); + currBrewState = kBrewIdle; + lastBrewTime = timeBrewed; // store brewtime to show in Shottimer after brew is finished + timeBrewed = 0; + } +} +#endif + + #if (FEATURE_BREWCONTROL == 1) /** * @brief Time base brew mode diff --git a/src/main.cpp b/src/main.cpp index 348dbbb3..a1f34a5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1588,8 +1588,12 @@ void looppid() { shottimerscale(); // Calculation of weight of shot while brew is running #endif -#if (FEATURE_BREWCONTROL == 1) +#if (FEATURE_BREWSWITCH == 1) + #if (FEATURE_BREWCONTROLL == 0) + brewTimer(); + #elif brew(); + #endif #endif #if (FEATURE_PRESSURESENSOR == 1)