Skip to content

Commit

Permalink
include backflush if BREWCONTROL == 1
Browse files Browse the repository at this point in the history
  • Loading branch information
LoQue90 committed Sep 28, 2024
1 parent 91d1f46 commit 9bb37f3
Showing 1 changed file with 84 additions and 84 deletions.
168 changes: 84 additions & 84 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,90 +153,6 @@ void checkbrewswitch() {
}
}

/**
* @brief Backflush
*/
void backflush() {
if (backflushState != kBackflushWaitBrewswitchOn && backflushOn == 0) {
backflushState = kBackflushWaitBrewswitchOff; // Force reset in case backflushOn is reset during backflush!
LOG(INFO, "Backflush: Disabled via Webinterface");
}
else if (offlineMode == 1 || currBrewState > kBrewIdle || maxflushCycles <= 0 || backflushOn == 0) {
return;
}

if (bPID.GetMode() == 1) { // Deactivate PID
bPID.SetMode(0);
pidOutput = 0;
}

heaterRelay.off(); // Stop heating

checkbrewswitch();

if (currStateBrewSwitch == LOW && backflushState != kBackflushWaitBrewswitchOn) { // Abort function for state machine from every state
backflushState = kBackflushWaitBrewswitchOff;
}

// State machine for backflush
switch (backflushState) {
case kBackflushWaitBrewswitchOn:
if (currStateBrewSwitch == HIGH && backflushOn) {
startingTime = millis();
backflushState = kBackflushFillingStart;
}

break;

case kBackflushFillingStart:
LOG(INFO, "Backflush: Portafilter filling...");
valveRelay.on();
pumpRelay.on();
backflushState = kBackflushFilling;

break;

case kBackflushFilling:
if (millis() - startingTime > FILLTIME) {
startingTime = millis();
backflushState = kBackflushFlushingStart;
}

break;

case kBackflushFlushingStart:
LOG(INFO, "Backflush: Flushing to drip tray...");
valveRelay.off();
pumpRelay.off();
flushCycles++;
backflushState = kBackflushFlushing;

break;

case kBackflushFlushing:
if (millis() - startingTime > flushTime && flushCycles < maxflushCycles) {
startingTime = millis();
backflushState = kBackflushFillingStart;
}
else if (flushCycles >= maxflushCycles) {
backflushState = kBackflushWaitBrewswitchOff;
}

break;

case kBackflushWaitBrewswitchOff:
if (currStateBrewSwitch == LOW) {
LOG(INFO, "Backflush: Finished!");
valveRelay.off();
pumpRelay.off();
flushCycles = 0;
backflushState = kBackflushWaitBrewswitchOn;
}

break;
}
}

#if (FEATURE_BREWCONTROL == 0)
/**
* @brief Brew timer
Expand Down Expand Up @@ -401,4 +317,88 @@ void brew() {
break;
}
}
/**
* @brief Backflush
*/
void backflush() {
if (backflushState != kBackflushWaitBrewswitchOn && backflushOn == 0) {
backflushState = kBackflushWaitBrewswitchOff; // Force reset in case backflushOn is reset during backflush!
LOG(INFO, "Backflush: Disabled via Webinterface");
}
else if (offlineMode == 1 || currBrewState > kBrewIdle || maxflushCycles <= 0 || backflushOn == 0) {
return;
}

if (bPID.GetMode() == 1) { // Deactivate PID
bPID.SetMode(0);
pidOutput = 0;
}

heaterRelay.off(); // Stop heating

checkbrewswitch();

if (currStateBrewSwitch == LOW && backflushState != kBackflushWaitBrewswitchOn) { // Abort function for state machine from every state
backflushState = kBackflushWaitBrewswitchOff;
}

// State machine for backflush
switch (backflushState) {
case kBackflushWaitBrewswitchOn:
if (currStateBrewSwitch == HIGH && backflushOn) {
startingTime = millis();
backflushState = kBackflushFillingStart;
}

break;

case kBackflushFillingStart:
LOG(INFO, "Backflush: Portafilter filling...");
valveRelay.on();
pumpRelay.on();
backflushState = kBackflushFilling;

break;

case kBackflushFilling:
if (millis() - startingTime > FILLTIME) {
startingTime = millis();
backflushState = kBackflushFlushingStart;
}

break;

case kBackflushFlushingStart:
LOG(INFO, "Backflush: Flushing to drip tray...");
valveRelay.off();
pumpRelay.off();
flushCycles++;
backflushState = kBackflushFlushing;

break;

case kBackflushFlushing:
if (millis() - startingTime > flushTime && flushCycles < maxflushCycles) {
startingTime = millis();
backflushState = kBackflushFillingStart;
}
else if (flushCycles >= maxflushCycles) {
backflushState = kBackflushWaitBrewswitchOff;
}

break;

case kBackflushWaitBrewswitchOff:
if (currStateBrewSwitch == LOW) {
LOG(INFO, "Backflush: Finished!");
valveRelay.off();
pumpRelay.off();
flushCycles = 0;
backflushState = kBackflushWaitBrewswitchOn;
}

break;
}
}

#endif

0 comments on commit 9bb37f3

Please sign in to comment.