Skip to content

Commit

Permalink
bring brewcontrol setting onto website
Browse files Browse the repository at this point in the history
  • Loading branch information
LoQue90 committed Oct 13, 2024
1 parent 454d93b commit 0b0cf7e
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 228 deletions.
205 changes: 102 additions & 103 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ uint8_t currReadingBrewSwitch = LOW;
bool brewSwitchWasOff = false;

// Brew values
uint8_t featureBrewControl = FEATURE_BREW_CONTROL; // enables control of pumpe and valve
double brewTime = BREW_TIME; // brewtime in s
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?
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?

// Backflush values
int backflushCycles = BACKFLUSH_CYCLES;
Expand Down Expand Up @@ -182,132 +183,131 @@ bool brew() {
timeBrewed = currentMillisTemp - startingTime;
}

#if (FEATURE_BREWCONTROL == 1) // brew-by-time and brew-by-weight
if (featureBrewControl) { // brew-by-time and brew-by-weight

// check if brewswitch was turned off after a brew; Brew only runs once even brewswitch is still pressed
if (currBrewSwitchState == kBrewSwitchIdle) {
brewSwitchWasOff = true;
}

// set brew time every cycle, in case changes are done during brew
if (brewTime > 0) {
totalBrewTime = (preinfusion * 1000) + (preinfusionPause * 1000) + (brewTime * 1000);
}
else {
// Stop by time deactivated --> brewTime = 0
totalBrewTime = 0;
}
// check if brewswitch was turned off after a brew; Brew only runs once even brewswitch is still pressed
if (currBrewSwitchState == kBrewSwitchIdle) {
brewSwitchWasOff = true;
}

// state machine for brew
switch (currBrewState) {
case kBrewIdle: // waiting step for brew switch turning on
if (currBrewSwitchState == kBrewSwitchShortPressed && brewSwitchWasOff && backflushOn == 0 && machineState != kWaterEmpty && machineState != kBackflush) {
startingTime = millis();
timeBrewed = 0; // reset timeBrewed, last brew is still stored
LOG(INFO, "Brew started");
// set brew time every cycle, in case changes are done during brew
if (brewTime > 0) {
totalBrewTime = (preinfusion * 1000) + (preinfusionPause * 1000) + (brewTime * 1000);
}
else {
// Stop by time deactivated --> brewTime = 0
totalBrewTime = 0;
}

if (preinfusionPause == 0 || preinfusion == 0) {
LOG(INFO, "Brew running");
currBrewState = kBrewRunning;
}
else {
LOG(INFO, "Preinfusion running");
currBrewState = kPreinfusion;
// state machine for brew
switch (currBrewState) {
case kBrewIdle: // waiting step for brew switch turning on
if (currBrewSwitchState == kBrewSwitchShortPressed && brewSwitchWasOff && backflushOn == 0 && machineState != kWaterEmpty && machineState != kBackflush) {
startingTime = millis();
timeBrewed = 0; // reset timeBrewed, last brew is still stored
LOG(INFO, "Brew started");

if (preinfusionPause == 0 || preinfusion == 0) {
LOG(INFO, "Brew running");
currBrewState = kBrewRunning;
}
else {
LOG(INFO, "Preinfusion running");
currBrewState = kPreinfusion;
}
}
}

break;
break;

case kPreinfusion:
valveRelay.on();
pumpRelay.on();
case kPreinfusion:
valveRelay.on();
pumpRelay.on();

if (timeBrewed > (preinfusion * 1000)) {
LOG(INFO, "Preinfusion pause running");
currBrewState = kPreinfusionPause;
}
if (timeBrewed > (preinfusion * 1000)) {
LOG(INFO, "Preinfusion pause running");
currBrewState = kPreinfusionPause;
}

break;
break;

case kPreinfusionPause:
valveRelay.on();
pumpRelay.off();
case kPreinfusionPause:
valveRelay.on();
pumpRelay.off();

if (timeBrewed > ((preinfusion + preinfusionPause) * 1000)) {
LOG(INFO, "Brew running");
currBrewState = kBrewRunning;
}
if (timeBrewed > ((preinfusion + preinfusionPause) * 1000)) {
LOG(INFO, "Brew running");
currBrewState = kBrewRunning;
}

break;
break;

case kBrewRunning:
valveRelay.on();
pumpRelay.on();
case kBrewRunning:
valveRelay.on();
pumpRelay.on();

// stop brew if target-time is reached --> No stop if stop by time is deactivated via Parameter (0)
if ((timeBrewed > totalBrewTime) && ((brewTime > 0))) {
LOG(INFO, "Brew reached time target");
currBrewState = kBrewFinished;
}
// stop brew if target-time is reached --> No stop if stop by time is deactivated via Parameter (0)
if ((timeBrewed > totalBrewTime) && ((brewTime > 0))) {
LOG(INFO, "Brew reached time target");
currBrewState = kBrewFinished;
}
#if (FEATURE_SCALE == 1)
// stop brew if target-weight is reached --> No stop if stop by weight is deactivated via Parameter (0)
else if (((FEATURE_SCALE == 1) && (weightBrew > weightSetpoint)) && (weightSetpoint > 0)) {
LOG(INFO, "Brew reached weight target");
currBrewState = kBrewFinished;
}
// stop brew if target-weight is reached --> No stop if stop by weight is deactivated via Parameter (0)
else if (((FEATURE_SCALE == 1) && (weightBrew > weightSetpoint)) && (weightSetpoint > 0)) {
LOG(INFO, "Brew reached weight target");
currBrewState = kBrewFinished;
}
#endif

break;
break;

case kBrewFinished:
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);
LOG(INFO, "Brew idle");
currBrewState = kBrewIdle;
case kBrewFinished:
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);
LOG(INFO, "Brew idle");
currBrewState = kBrewIdle;

break;
break;
}
}
#else // FEATURE_BREWCONTROL == 0, only brew time
else { // brewControlOn == 0, only brew time

switch (currBrewState) {
case kBrewIdle: // waiting step for brew switch turning on
if (currBrewSwitchState == kBrewSwitchShortPressed && machineState != kWaterEmpty) {
startingTime = millis();
timeBrewed = 0; // reset timeBrewed, last brew is still stored
LOG(INFO, "Brew timer started");
currBrewState = kBrewRunning;
}
switch (currBrewState) {
case kBrewIdle: // waiting step for brew switch turning on
if (currBrewSwitchState == kBrewSwitchShortPressed && machineState != kWaterEmpty) {
startingTime = millis();
timeBrewed = 0; // reset timeBrewed, last brew is still stored
LOG(INFO, "Brew timer started");
currBrewState = kBrewRunning;
}

break;
break;

case kBrewRunning:
if (currBrewSwitchState == kBrewSwitchIdle && currBrewState == kBrewRunning) {
currBrewState = kBrewFinished;
}
case kBrewRunning:
if (currBrewSwitchState == kBrewSwitchIdle && currBrewState == kBrewRunning) {
currBrewState = kBrewFinished;
}

break;
break;

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");
currBrewState = kBrewIdle;
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");
currBrewState = kBrewIdle;

break;
break;
}
}
#endif

return (currBrewState != kBrewIdle && currBrewState != kBrewFinished);
}

#if (FEATURE_BREWCONTROL == 1)
/**
* @brief manual grouphead flush
* @return true if manual flush is running, false otherwise
Expand Down Expand Up @@ -421,4 +421,3 @@ void backflush() {
break;
}
}
#endif
1 change: 1 addition & 0 deletions src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int writeSysParamsToStorage(void);
#define BACKFLUSH_CYCLES 5 // number of cycles the backflush should run
#define BACKFLUSH_FILL_TIME 5 // time in seconds the pump is running during backflush
#define BACKFLUSH_FLUSH_TIME 10 // time in seconds the 3-way valve is open during backflush
#define FEATURE_BREW_CONTROL 0 // enables function to control pump and solenoid valve

#define PID_KP_START_MIN 0
#define PID_KP_START_MAX 999
Expand Down
2 changes: 1 addition & 1 deletion src/display/displayRotateUpright.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void displayEmergencyStop(void) {
* @brief display shot timer
*/
bool displayShottimer() {
if (((timeBrewed > 0 && FEATURE_BREWCONTROL == 0) || (FEATURE_BREWCONTROL > 0 && currBrewState > kBrewIdle && currBrewState <= kBrewFinished)) && FEATURE_SHOTTIMER == 1) {
if (((timeBrewed > 0 && featureBrewControl == 0) || (featureBrewControl > 0 && currBrewState > kBrewIdle && currBrewState <= kBrewFinished)) && FEATURE_SHOTTIMER == 1) {
u8g2.clearBuffer();

// draw temp icon
Expand Down
58 changes: 28 additions & 30 deletions src/display/displayTemplateMinimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,39 @@ void printScreen() {
u8g2.setFont(u8g2_font_profont11_tf);

// Brew time
#if (FEATURE_BREWSWITCH == 1 && FEATURE_BREWCONTROL == 1)

// Shown brew time while machine is brewing and after the brewing during SHOTTIMERDISPLAYDELAY
if (machineState == kBrew || (millis() - lastBrewTimeMillis) < SHOTTIMERDISPLAYDELAY) {
u8g2.setCursor(34, 44);
u8g2.print(langstring_brew);
u8g2.print(timeBrewed / 1000, 0);
u8g2.print("/");
u8g2.print(totalBrewTime / 1000, 0);
}
#if (FEATURE_BREWSWITCH == 1)
if (featureBrewControl) {
// Shown brew time while machine is brewing and after the brewing during SHOTTIMERDISPLAYDELAY
if (machineState == kBrew || (millis() - lastBrewTimeMillis) < SHOTTIMERDISPLAYDELAY) {
u8g2.setCursor(34, 44);
u8g2.print(langstring_brew);
u8g2.print(timeBrewed / 1000, 0);
u8g2.print("/");
u8g2.print(totalBrewTime / 1000, 0);
}

// Flush time
// Flush time

// Shown flush time while machine is flushing
if (machineState == kManualFlush) {
u8g2.setDrawColor(0);
u8g2.drawBox(34, 44, 100, 15);
u8g2.setDrawColor(1);
u8g2.setCursor(34, 44);
u8g2.print(langstring_manual_flush);
u8g2.print(timeBrewed / 1000, 0);
// Shown flush time while machine is flushing
if (machineState == kManualFlush) {
u8g2.setDrawColor(0);
u8g2.drawBox(34, 44, 100, 15);
u8g2.setDrawColor(1);
u8g2.setCursor(34, 44);
u8g2.print(langstring_manual_flush);
u8g2.print(timeBrewed / 1000, 0);
}
}

#endif

// Brew Timer with optocoupler
#if (FEATURE_BREWSWITCH == 1 && FEATURE_BREWCONTROL == 0)

// Shown brew time while machine is brewing and after the brewing during SHOTTIMERDISPLAYDELAY
if (machineState == kBrew || (millis() - lastBrewTimeMillis) < SHOTTIMERDISPLAYDELAY) {
u8g2.setCursor(34, 44);
u8g2.print(langstring_brew);
u8g2.print(timeBrewed / 1000, 0);
// Brew Timer with optocoupler
else {
// Shown brew time while machine is brewing and after the brewing during SHOTTIMERDISPLAYDELAY
if (machineState == kBrew || (millis() - lastBrewTimeMillis) < SHOTTIMERDISPLAYDELAY) {
u8g2.setCursor(34, 44);
u8g2.print(langstring_brew);
u8g2.print(timeBrewed / 1000, 0);
}
}

#endif

// Show heater output in %
Expand Down
Loading

0 comments on commit 0b0cf7e

Please sign in to comment.