From db7e1d87eb3d7a7324e4bedd255081f891e3b3b7 Mon Sep 17 00:00:00 2001 From: Lorenz Uhlig <98092139+LoQue90@users.noreply.github.com> Date: Fri, 18 Oct 2024 01:17:23 +0200 Subject: [PATCH] rework scale shottimer cleanup in main.cpp adding translations rename some scale vars to be more precice rename Display settings on website do not show weight in full screen shot timer during manual flush --- src/brewHandler.h | 10 +-- src/display/displayCommon.h | 26 +++--- src/display/displayTemplateScale.h | 104 ++++++++++++++++-------- src/display/displayTemplateStandard.h | 112 +++++++++++++------------- src/languages.h | 6 ++ src/main.cpp | 31 +++---- src/scaleHandler.h | 12 +-- 7 files changed, 171 insertions(+), 130 deletions(-) diff --git a/src/brewHandler.h b/src/brewHandler.h index f32edf7c..40355037 100644 --- a/src/brewHandler.h +++ b/src/brewHandler.h @@ -6,9 +6,9 @@ */ // TODO: // Flush Timer configurable and seperated from shottimer? -// check all Scale stuff // show heating logo if steam temp isn´t reached? // show sections on website only if needed +// add pressure to shot timer? #pragma once @@ -76,9 +76,9 @@ boolean scaleCalibrationOn = 0; boolean scaleTareOn = 0; int shottimerCounter = 10; float calibrationValue = SCALE_CALIBRATION_FACTOR; // use calibration example to get value -float weight = 0; // value from HX711 -float weightPreBrew = 0; // value of scale before wrew started -float weightBrew = 0; // weight value of brew +float currWeight = 0; // value from HX711 +float weightPreBrew = 0; // value of scale before brew started +float weightBrewed = 0; // weight value of brew float scaleDelayValue = 2.5; // value in gramm that takes still flows onto the scale after brew is stopped bool scaleFailure = false; const unsigned long intervalWeight = 200; // weight scale @@ -248,7 +248,7 @@ bool brew() { } #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)) { + else if (((FEATURE_SCALE == 1) && (weightBrewed > weightSetpoint)) && (weightSetpoint > 0)) { LOG(INFO, "Brew reached weight target"); currBrewState = kBrewFinished; } diff --git a/src/display/displayCommon.h b/src/display/displayCommon.h index 464111c7..af1f3644 100644 --- a/src/display/displayCommon.h +++ b/src/display/displayCommon.h @@ -246,24 +246,24 @@ bool displayShottimer() { if (machineState != kManualFlush) { u8g2.drawXBMP(-1, 11, Brew_Cup_Logo_width, Brew_Cup_Logo_height, Brew_Cup_Logo); +#if (FEATURE_SCALE == 1) + u8g2.setFont(u8g2_font_profont22_tf); + u8g2.setCursor(64, 15); + u8g2.print(timeBrewed / 1000, 1); + u8g2.print("s"); + u8g2.setCursor(64, 38); + u8g2.print(weightBrewed, 1); + u8g2.print("g"); + u8g2.setFont(u8g2_font_profont11_tf); +#else + displayBrewtime(48, 25, timeBrewed); +#endif } else { u8g2.drawXBMP(0, 12, Manual_Flush_Logo_width, Manual_Flush_Logo_height, Manual_Flush_Logo); + displayBrewtime(48, 25, timeBrewed); } -#if (FEATURE_SCALE == 1) - u8g2.setFont(u8g2_font_profont22_tf); - u8g2.setCursor(64, 15); - u8g2.print(timeBrewed / 1000, 1); - u8g2.print("s"); - u8g2.setCursor(64, 38); - u8g2.print(weightBrew, 1); - u8g2.print("g"); - u8g2.setFont(u8g2_font_profont11_tf); -#else - displayBrewtime(48, 25, timeBrewed); -#endif - displayWaterIcon(119, 1); u8g2.sendBuffer(); return true; diff --git a/src/display/displayTemplateScale.h b/src/display/displayTemplateScale.h index 5120dd2b..e27646eb 100644 --- a/src/display/displayTemplateScale.h +++ b/src/display/displayTemplateScale.h @@ -51,53 +51,91 @@ void printScreen() { u8g2.print("/"); u8g2.print(setpoint, 1); + /** + * @brief Shot timer for scale + * + * If scale has an error show fault on the display otherwise show current reading of the scale + * if brew is running show current brew time and current brew weight + * if brewControl is enabled and time or weight target is set show targets + * if brewControl is enabled show flush time during manualFlush + * if FEATURE_PRESSURESENSOR is enabled show current pressure during brew + * if brew is finished show brew values for shotTimerDisplayDelay + */ + + // Show current weight if scale has no error u8g2.setCursor(32, 26); - u8g2.print("W: "); - + u8g2.print(langstring_weight); + u8g2.setCursor(82, 26); if (scaleFailure) { u8g2.print("fault"); } else { - if (machineState == kBrew) { - u8g2.print(weightBrew, 0); - } - else { - u8g2.print(weight, 0); - } - - if (weightSetpoint > 0) { - u8g2.print("/"); - u8g2.print(weightSetpoint, 0); - } - - u8g2.print(" ("); - u8g2.print(weightBrew, 1); - u8g2.print(")"); + u8g2.print(currWeight, 0); + u8g2.print(" g"); } - // Brew - u8g2.setCursor(32, 36); - u8g2.print("t: "); - u8g2.print(timeBrewed / 1000, 0); - - if (FEATURE_BREWCONTROL == 0) { - u8g2.print("/"); - u8g2.print(brewtimesoftware, 0); + if (featureBrewControl) { + // Shown brew time and weight while machine is brewing and after the brewing during shotTimerDisplayDelay + if (machineState == kBrew || (millis() - lastBrewTimeMillis) < (shotTimerDisplayDelay * 1000)) { + + // weight + u8g2.setCursor(32, 26); + u8g2.print(langstring_weight); + u8g2.setCursor(82, 26); + u8g2.print(weightBrewed, 0); + + if (weightSetpoint > 0) { + u8g2.print("/"); + u8g2.print(weightSetpoint, 0); + u8g2.print(" g"); + } + // time + u8g2.setCursor(32, 36); + u8g2.print(langstring_brew); + u8g2.setCursor(82, 36); + u8g2.print(timeBrewed / 1000, 0); + + if (brewTime > 0) { + u8g2.print("/"); + u8g2.print(totalBrewTime / 1000, 0); + u8g2.print(" s"); + } + } + // Shown flush time while machine is flushing + if (machineState == kManualFlush) { + u8g2.setDrawColor(0); + u8g2.drawBox(32, 26, 100, 40); + u8g2.setDrawColor(1); + u8g2.setCursor(32, 26); + u8g2.print(langstring_manual_flush); + u8g2.setCursor(82, 26); + u8g2.print(timeBrewed / 1000, 0); + u8g2.print(" s"); + } } else { - if (brewTime > 0) { - u8g2.print("/"); - u8g2.print(totalBrewTime / 1000, 0); + // Brew Timer with optocoupler + + // Shown brew time and weight while machine is brewing and after the brewing during shotTimerDisplayDelay + if (machineState == kBrew || (millis() - lastBrewTimeMillis) < (shotTimerDisplayDelay * 1000)) { + // weight + u8g2.setCursor(32, 26); + u8g2.print(langstring_weight); + u8g2.setCursor(82, 26); + u8g2.print(weightBrewed, 0); + u8g2.print(" g"); + // time + u8g2.setCursor(32, 36); + u8g2.print(langstring_brew); + u8g2.setCursor(82, 36); + u8g2.print(timeBrewed / 1000, 0); + u8g2.print(" s"); } - - u8g2.print(" ("); - u8g2.print(lastBrewTime / 1000, 1); - u8g2.print(")"); } #if (FEATURE_PRESSURESENSOR == 1) u8g2.setCursor(32, 46); - u8g2.print("P: "); + u8g2.print(langstring_pressure); u8g2.print(inputPressure, 1); #endif diff --git a/src/display/displayTemplateStandard.h b/src/display/displayTemplateStandard.h index 1de76622..c26b4ded 100644 --- a/src/display/displayTemplateStandard.h +++ b/src/display/displayTemplateStandard.h @@ -59,78 +59,74 @@ void printScreen() { drawTemperaturebar(8, 50, 30); } -// Brew time +// Brew and flush time #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 * 1000)) { - u8g2.setFontMode(1); - u8g2.setCursor(34, 36); - u8g2.print(langstring_brew); - u8g2.setCursor(84, 36); - u8g2.print(timeBrewed / 1000, 0); - u8g2.print("/"); - u8g2.print(totalBrewTime / 1000, 0); - u8g2.print(" s"); - } - - // Flush time - - // Shown flush time while machine is flushing - if (machineState == kManualFlush) { - u8g2.setDrawColor(0); - u8g2.drawBox(34, 36, 100, 10); - u8g2.setDrawColor(1); - u8g2.setCursor(34, 36); - u8g2.print(langstring_manual_flush); - u8g2.setCursor(84, 36); - u8g2.print(timeBrewed / 1000, 0); - u8g2.print(" s"); - } + u8g2.setCursor(34, 36); + u8g2.print(langstring_brew); + u8g2.setCursor(84, 36); + u8g2.print(timeBrewed / 1000, 0); + u8g2.print("/"); + u8g2.print(totalBrewTime / 1000, 0); + u8g2.print(" s"); } - else { - // Brew Timer with optocoupler - // Shown brew time while machine is brewing and after the brewing during shotTimerDisplayDelay - if (machineState == kBrew || (millis() - lastBrewTimeMillis) < (shotTimerDisplayDelay * 1000)) { - u8g2.setCursor(34, 36); - u8g2.print(langstring_brew); - u8g2.setCursor(84, 36); - u8g2.print(timeBrewed / 1000, 0); - u8g2.print(" s"); - } + // Shown flush time while machine is flushing + if (machineState == kManualFlush) { + u8g2.setDrawColor(0); + u8g2.drawBox(34, 36, 100, 10); + u8g2.setDrawColor(1); + u8g2.setCursor(34, 36); + u8g2.print(langstring_manual_flush); + u8g2.setCursor(84, 36); + u8g2.print(timeBrewed / 1000, 0); + u8g2.print(" s"); + } +} +else { + // Brew Timer with optocoupler + + // Shown brew time while machine is brewing and after the brewing during shotTimerDisplayDelay + if (machineState == kBrew || (millis() - lastBrewTimeMillis) < (shotTimerDisplayDelay * 1000)) { + u8g2.setCursor(34, 36); + u8g2.print(langstring_brew); + u8g2.setCursor(84, 36); + u8g2.print(timeBrewed / 1000, 0); + u8g2.print(" s"); } +} #endif - // PID values over heat bar - u8g2.setCursor(38, 47); +// PID values over heat bar +u8g2.setCursor(38, 47); - u8g2.print(bPID.GetKp(), 0); - u8g2.print("|"); +u8g2.print(bPID.GetKp(), 0); +u8g2.print("|"); - if (bPID.GetKi() != 0) { - u8g2.print(bPID.GetKp() / bPID.GetKi(), 0); - } - else { - u8g2.print("0"); - } +if (bPID.GetKi() != 0) { + u8g2.print(bPID.GetKp() / bPID.GetKi(), 0); +} +else { + u8g2.print("0"); +} - u8g2.print("|"); - u8g2.print(bPID.GetKd() / bPID.GetKp(), 0); - u8g2.setCursor(96, 47); +u8g2.print("|"); +u8g2.print(bPID.GetKd() / bPID.GetKp(), 0); +u8g2.setCursor(96, 47); - if (pidOutput < 99) { - u8g2.print(pidOutput / 10, 1); - } - else { - u8g2.print(pidOutput / 10, 0); - } +if (pidOutput < 99) { + u8g2.print(pidOutput / 10, 1); +} +else { + u8g2.print(pidOutput / 10, 0); +} - u8g2.print("%"); +u8g2.print("%"); - // Show heater output in % - displayProgressbar(pidOutput / 10, 30, 60, 98); +// Show heater output in % +displayProgressbar(pidOutput / 10, 30, 60, 98); - u8g2.sendBuffer(); +u8g2.sendBuffer(); } diff --git a/src/languages.h b/src/languages.h index 9bde884b..6a5327c2 100644 --- a/src/languages.h +++ b/src/languages.h @@ -13,7 +13,9 @@ static const char* langstring_set_temp = "Soll: "; static const char* langstring_current_temp = "Ist: "; static const char* langstring_brew = "Bezug: "; +static const char* langstring_weight = "Gewicht: "; static const char* langstring_manual_flush = "Spuelen: "; +static const char* langstring_pressure = "Druck: "; static const char* langstring_uptime = "Uptime: "; #endif #if (DISPLAYTEMPLATE >= 20) // vertical templates @@ -39,7 +41,9 @@ static const char* langstring_backflush_finish = "um zu beenden..."; static const char* langstring_set_temp = "Set: "; static const char* langstring_current_temp = "Temp: "; static const char* langstring_brew = "Brew: "; +static const char* langstring_weight = "Weight: "; static const char* langstring_manual_flush = "Flush: "; +static const char* langstring_pressure = "Pressure: "; static const char* langstring_uptime = "Uptime: "; #endif #if (DISPLAYTEMPLATE >= 20) // vertical templates @@ -66,7 +70,9 @@ static const char* langstring_backflush_finish = "to finish..."; static const char* langstring_set_temp = "Obj: "; static const char* langstring_current_temp = "T: "; static const char* langstring_brew = "Brew: "; +static const char* langstring_weight = "Peso: "; static const char* langstring_manual_flush = "Fregar: "; +static const char* langstring_pressure = "Presión: "; static const char* langstring_uptime = "Uptime: "; #endif #if (DISPLAYTEMPLATE >= 20) // vertical templates diff --git a/src/main.cpp b/src/main.cpp index d06d0d68..37cc5caa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,11 @@ #include "defaults.h" #include "userConfig.h" // needs to be configured by the user +// Version of userConfig need to match, checked by preprocessor +#if (FW_VERSION != USR_FW_VERSION) || (FW_SUBVERSION != USR_FW_SUBVERSION) || (FW_HOTFIX != USR_FW_HOTFIX) +#error Version of userConfig file and main.cpp need to match! +#endif + hw_timer_t* timer = NULL; #if (FEATURE_PRESSURESENSOR == 1) @@ -68,11 +73,6 @@ hw_timer_t* timer = NULL; #include #endif -// Version of userConfig need to match, checked by preprocessor -#if (FW_VERSION != USR_FW_VERSION) || (FW_SUBVERSION != USR_FW_SUBVERSION) || (FW_HOTFIX != USR_FW_HOTFIX) -#error Version of userConfig file and main.cpp need to match! -#endif - MACHINE machine = (enum MACHINE)MACHINEID; #define HIGH_ACCURACY @@ -179,15 +179,12 @@ void updateStandbyTimer(void); void resetStandbyTimer(void); // system parameters -uint8_t pidON = 0; // 1 = control loop in closed loop +uint8_t pidON = 0; // 1 = control loop in closed loop +uint8_t usePonM = 0; // 1 = use PonM for cold start PID, 0 = use normal PID for cold start double brewSetpoint = SETPOINT; double brewTempOffset = TEMPOFFSET; double setpoint = brewSetpoint; double steamSetpoint = STEAMSETPOINT; -float scaleCalibration = SCALE_CALIBRATION_FACTOR; -float scale2Calibration = SCALE_CALIBRATION_FACTOR; -float scaleKnownWeight = SCALE_KNOWN_WEIGHT; -uint8_t usePonM = 0; // 1 = use PonM for cold start PID, 0 = use normal PID for cold start double steamKp = STEAMKP; double startKp = STARTKP; double startTn = STARTTN; @@ -196,6 +193,10 @@ double aggTn = AGGTN; double aggTv = AGGTV; double aggIMax = AGGIMAX; +// Scale +float scaleCalibration = SCALE_CALIBRATION_FACTOR; +float scale2Calibration = SCALE_CALIBRATION_FACTOR; +float scaleKnownWeight = SCALE_KNOWN_WEIGHT; double weightSetpoint = SCALE_WEIGHTSETPOINT; // PID - values for offline brew detection @@ -1163,7 +1164,7 @@ void setup() { .type = kDouble, .section = sBrewSection, .position = 21, - .show = [] { return true && FEATURE_SCALE == 1; }, + .show = [] { return true && FEATURE_SCALE == 1 && featureBrewControl == 1; }, .minValue = WEIGHTSETPOINT_MIN, .maxValue = WEIGHTSETPOINT_MAX, .ptr = (void*)&weightSetpoint}; @@ -1323,7 +1324,7 @@ void setup() { .ptr = (void*)&scale2Calibration}; #endif - editableVars["SHOT_TIMER"] = {.displayName = F("Enable Shot Timer"), + editableVars["SHOT_TIMER"] = {.displayName = F("Enable Full Screen Shot Timer"), .hasHelpText = true, .helpText = "Enables a full screen shot and flush timer", .type = kUInt8, @@ -1345,7 +1346,7 @@ void setup() { .maxValue = SHOT_TIMER_DISPLAY_DELAY_MAX, .ptr = (void*)&shotTimerDisplayDelay}; - editableVars["HEATING_LOGO"] = {.displayName = F("Enable Heating Logo"), + editableVars["HEATING_LOGO"] = {.displayName = F("Enable Full Screen Heating Logo"), .hasHelpText = true, .helpText = "full screen logo will be shown if temperature is 5°C below setpoint", .type = kUInt8, @@ -1356,7 +1357,7 @@ void setup() { .maxValue = 1, .ptr = (void*)&featureHeatingLogo}; - editableVars["PID_OFF_LOGO"] = {.displayName = F("Enable ´PID Disabled´ Logo"), + editableVars["PID_OFF_LOGO"] = {.displayName = F("Enable Full Screen ´PID Disabled´ Logo"), .hasHelpText = true, .helpText = "full screen logo will be shown if pid is disabled", .type = kUInt8, @@ -1425,7 +1426,7 @@ void setup() { mqttVars["scaleTareOn"] = [] { return &editableVars.at("TARE_ON"); }; mqttVars["scaleCalibrationOn"] = [] { return &editableVars.at("CALIBRATION_ON"); }; - mqttSensors["currentWeight"] = [] { return weight; }; + mqttSensors["currentWeight"] = [] { return currWeight; }; #endif #if FEATURE_PRESSURESENSOR == 1 diff --git a/src/scaleHandler.h b/src/scaleHandler.h index 906f2ba7..41ce32c3 100644 --- a/src/scaleHandler.h +++ b/src/scaleHandler.h @@ -78,9 +78,9 @@ void checkWeight() { } #if SCALE_TYPE == 0 - weight = w1 + w2; + currWeight = w1 + w2; #else - weight = w1; + currWeight = w1; #endif if (scaleCalibrationOn) { @@ -177,24 +177,24 @@ void shottimerscale() { case 10: // waiting step for brew switch turning on if (preinfusionPause == 0 || preinfusion == 0) { if (timeBrewed > 0) { - weightPreBrew = weight; + weightPreBrew = currWeight; shottimerCounter = 20; } } else { if (timeBrewed > preinfusion * 1000) { - weightPreBrew = weight; + weightPreBrew = currWeight; shottimerCounter = 20; } else if (timeBrewed > 0) { - weightBrew = 0; + weightBrewed = 0; } } break; case 20: - weightBrew = weight - weightPreBrew; + weightBrewed = currWeight - weightPreBrew; if (timeBrewed == 0) { shottimerCounter = 10;