Skip to content

Commit

Permalink
add function for showing brew Timer
Browse files Browse the repository at this point in the history
a own function to check if brew timer should be visible or not, based on brew is running
  • Loading branch information
LoQue90 committed Dec 17, 2024
1 parent ab65ec9 commit ea6feab
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ double preinfusion = PRE_INFUSION_TIME; // preinfusion time in s
double preinfusionPause = PRE_INFUSION_PAUSE_TIME; // preinfusion pause time in s
double totalBrewTime = 0; // total brewtime including preinfusion and preinfusion pause
double timeBrewed = 0; // total brewed time
double lastBrewTimeMillis = 0; // for shottimer delay after brew is finished
unsigned long startingTime = 0; // start time of brew
bool brewPIDDisabled = false; // is PID disabled for delay after brew has started?

Expand Down Expand Up @@ -259,7 +258,6 @@ bool brew() {
valveRelay.off();
pumpRelay.off();
currentMillisTemp = 0;
lastBrewTimeMillis = millis(); // time brew finished for shottimer delay
brewSwitchWasOff = false;
LOG(INFO, "Brew finished");
LOGF(INFO, "Shot time: %4.1f s", timeBrewed / 1000);
Expand Down Expand Up @@ -291,7 +289,6 @@ bool brew() {

case kBrewFinished:
currentMillisTemp = 0;
lastBrewTimeMillis = millis(); // time brew finished for shottimer delay
LOG(INFO, "Brew finished");
LOGF(INFO, "Shot time: %4.1f s", timeBrewed / 1000);
LOG(INFO, "Brew idle");
Expand Down
42 changes: 41 additions & 1 deletion src/display/displayCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,46 @@ void displayTemperature(int x, int y) {
u8g2.drawCircle(x + 72, y + 4, 3);
}

/**
* @brief determines if brew timer should be visible; postBrewTimerDuration defines how long the timer after the brew is shown
* @return true if timer should be visible, false otherwise
*/
bool shouldDisplayBrewTimer() {

enum BrewTimerState {
kBrewTimerIdle = 10,
kBrewTimerRunning = 20,
kBrewTimerPostBrew = 30
};

static BrewTimerState currBrewTimerState = kBrewTimerIdle;

static uint32_t brewEndTime = 0;

switch (currBrewTimerState) {
case kBrewTimerIdle:
if (brew()) {
currBrewTimerState = kBrewTimerRunning;
}
break;

case kBrewTimerRunning:
if (!brew()) {
currBrewTimerState = kBrewTimerPostBrew;
brewEndTime = millis();
}
break;

case kBrewTimerPostBrew:
if ((millis() - brewEndTime) > (uint32_t)(postBrewTimerDuration * 1000)) {
currBrewTimerState = kBrewTimerIdle;
}
break;
}

return (currBrewTimerState != kBrewTimerIdle);
}

/**
* @brief Draw the brew time at given position
*/
Expand Down Expand Up @@ -241,7 +281,7 @@ bool displayFullscreenBrewTimer() {
return false;
}

if (machineState == kBrew || ((millis() - lastBrewTimeMillis) < (postBrewTimerDuration * 1000) && lastBrewTimeMillis > 0)) {
if (shouldDisplayBrewTimer()) {
u8g2.clearBuffer();
u8g2.drawXBMP(-1, 11, Brew_Cup_Logo_width, Brew_Cup_Logo_height, Brew_Cup_Logo);
#if (FEATURE_SCALE == 1)
Expand Down
4 changes: 2 additions & 2 deletions src/display/displayTemplateStandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void printScreen() {

if (featureBrewControl) {
// Shown brew time while machine is brewing and after the brewing during postBrewTimerDuration
if (machineState == kBrew || ((millis() - lastBrewTimeMillis) < (postBrewTimerDuration * 1000) && lastBrewTimeMillis > 0)) {
if (shouldDisplayBrewTimer()) {
u8g2.setCursor(34, 36);
u8g2.print(langstring_brew);
u8g2.setCursor(84, 36);
Expand All @@ -95,7 +95,7 @@ void printScreen() {
// Brew Timer with optocoupler

// Shown brew time while machine is brewing and after the brewing during postBrewTimerDuration
if (machineState == kBrew || ((millis() - lastBrewTimeMillis) < (postBrewTimerDuration * 1000) && lastBrewTimeMillis > 0)) {
if (shouldDisplayBrewTimer()) {
u8g2.setCursor(34, 36);
u8g2.print(langstring_brew);
u8g2.setCursor(84, 36);
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,11 @@ void looppid() {
updateStandbyTimer();
handleMachineState();

// Check if brew timer should be shown
#if (FEATURE_BREWSWITCH == 1)
shouldDisplayBrewTimer();
#endif

// Check if PID should run or not. If not, set to manual and force output to zero
#if OLED_DISPLAY != 0
printDisplayTimer();
Expand Down

0 comments on commit ea6feab

Please sign in to comment.