Skip to content

Commit

Permalink
rework scale shottimer
Browse files Browse the repository at this point in the history
cleanup in main.cpp
adding translations
rename some scale vars to be more precice
  • Loading branch information
LoQue90 committed Oct 18, 2024
1 parent 79b984f commit 4475993
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 59 deletions.
10 changes: 6 additions & 4 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// 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?
// check if u8g2.setFontMode(1); still needed in display templates

#pragma once

Expand Down Expand Up @@ -76,9 +78,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
Expand Down Expand Up @@ -248,7 +250,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/display/displayCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ bool displayShottimer() {
u8g2.print(timeBrewed / 1000, 1);
u8g2.print("s");
u8g2.setCursor(64, 38);
u8g2.print(weightBrew, 1);
u8g2.print(weightBrewed, 1);
u8g2.print("g");
u8g2.setFont(u8g2_font_profont11_tf);
#else
Expand Down
104 changes: 71 additions & 33 deletions src/display/displayTemplateScale.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/display/displayTemplateStandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void printScreen() {
drawTemperaturebar(8, 50, 30);
}

// Brew time
// Brew and flush time
#if (FEATURE_BREWSWITCH == 1)

if (featureBrewControl) {
Expand All @@ -75,8 +75,6 @@ void printScreen() {
u8g2.print(" s");
}

// Flush time

// Shown flush time while machine is flushing
if (machineState == kManualFlush) {
u8g2.setDrawColor(0);
Expand Down
6 changes: 6 additions & 0 deletions src/languages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
25 changes: 13 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -68,11 +73,6 @@ hw_timer_t* timer = NULL;
#include <HX711_ADC.h>
#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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/scaleHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void checkWeight() {
}

#if SCALE_TYPE == 0
weight = w1 + w2;
currWeight = w1 + w2;
#else
weight = w1;
currWeight = w1;
#endif

if (scaleCalibrationOn) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4475993

Please sign in to comment.