Skip to content

Commit

Permalink
adding brewtimer
Browse files Browse the repository at this point in the history
adds brewtimer without controlling pump/valve
  • Loading branch information
LoQue90 committed Sep 7, 2024
1 parent d83f511 commit 8649bcd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
39 changes: 35 additions & 4 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8649bcd

Please sign in to comment.