Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/brewvoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,23 @@ boolean brewPIDDisabled = false; // is PID disabled for delay
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 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
const unsigned long intervalWeight = 50; // weight scale
unsigned long previousMillisScale; // initialisation at the end of init()
HX711_ADC LoadCell(PIN_HXDAT, PIN_HXCLK);
#if SCALE_TYPE == 0
HX711_ADC LoadCell2(PIN_HXDAT2, PIN_HXCLK);
#endif

// flow rate calculation
unsigned long prevFlowRateTime = 0;
float prevFlowRateWeight = 0.0;
float flowRate = 0.0;
float flowRateEmaAlpha = 0.05;
#endif

/**
Expand Down Expand Up @@ -376,6 +381,11 @@ void brew() {
if (brewCounter > kBrewIdle && brewCounter < kWaitBrewOff) {
timeBrewed = currentMillisTemp - startingTime;
weightBrew = weight - weightPreBrew;

// Avoid ugly scale glitches below 0g at the beginning of the shot
if (weightBrew < 0) {
weightBrew = 0;
}
}

if (brewSwitch == LOW && movingAverageInitialized) {
Expand All @@ -399,6 +409,8 @@ void brew() {

coldstart = false; // force reset coldstart if shot is pulled
weightPreBrew = weight;
prevFlowRateWeight = weight;
prevFlowRateTime = currentMillisTemp;
} else {
backflush();
}
Expand Down Expand Up @@ -465,6 +477,7 @@ void brew() {

// disarmed button
currentMillisTemp = 0;
lastBrewTime = timeBrewed;
timeBrewed = 0;
brewDetected = 0; // rearm brewDetection
brewCounter = kBrewIdle;
Expand All @@ -474,6 +487,31 @@ void brew() {

break;
}

if (brewCounter > kBrewIdle && brewCounter < kWaitBrewOff) {
// Calculate time and weight difference
unsigned long timeDelta = currentMillisTemp - prevFlowRateTime;
float weightDelta = weightBrew - prevFlowRateWeight;
// avoid flowrate flicker when scale flickers negatively
if (weightDelta < 0) {
weightDelta = 0;
}

// Calculate flow rate
// we only get a new weight measurement every intervalWeight ms, so we do not need to compute this more often!
if (timeDelta > intervalWeight) {
float currentFlowRate = weightDelta / (timeDelta / 1000.0); // Flow rate in g/s
flowRate = flowRateEmaAlpha * currentFlowRate + (1 - flowRateEmaAlpha) * flowRate;

// debugPrintf("Delta %i, weightDelta %.2f. Curr: %.2f, flowrate %.2f //// time: %i, weight %.2f\n", timeDelta, weightDelta, currentFlowRate, flowRate, timeBrewed, weightBrew);

prevFlowRateTime = currentMillisTemp;
prevFlowRateWeight = weightBrew;
}
}
else {
flowRate = 0;
}
}
}
#endif
18 changes: 12 additions & 6 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ void displayShottimer(void) {

// temp icon
u8g2.drawXBMP(-1, 11, Brew_Cup_Logo_width, Brew_Cup_Logo_height, Brew_Cup_Logo);
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(64, 15);
u8g2.setFont(u8g2_font_profont17_tf);
u8g2.setCursor(64, 5);
u8g2.print(timeBrewed / 1000, 1);
u8g2.print("s");
u8g2.setCursor(64, 38);
u8g2.setCursor(64, 25);
u8g2.print(weightBrew, 1);
u8g2.print("g");
u8g2.setCursor(64, 45);
u8g2.print(flowRate, 1);
u8g2.print("g/s");
u8g2.setFont(u8g2_font_profont11_tf);
displayWaterIcon(119, 1);
u8g2.sendBuffer();
Expand All @@ -256,13 +259,16 @@ void displayShottimer(void) {
if (((machineState == kShotTimerAfterBrew) && FEATURE_SHOTTIMER == 1 && SHOTTIMER_TYPE == 2)) {
u8g2.clearBuffer();
u8g2.drawXBMP(-1, 11, Brew_Cup_Logo_width, Brew_Cup_Logo_height, Brew_Cup_Logo);
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(64, 15);
u8g2.setFont(u8g2_font_profont17_tf);
u8g2.setCursor(64, 5);
u8g2.print(lastBrewTime / 1000, 1);
u8g2.print("s");
u8g2.setCursor(64, 38);
u8g2.setCursor(64, 25);
u8g2.print(weightBrew, 1);
u8g2.print("g");
u8g2.setCursor(64, 45);
u8g2.print(flowRate, 1);
u8g2.print("g/s");
u8g2.setFont(u8g2_font_profont11_tf);
displayWaterIcon(119, 1);
u8g2.sendBuffer();
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,11 +2098,11 @@ void setup() {
mqttSensors["pressure"] = []{ return inputPressureFilter; };
#endif

#if (BREWMODE == 2 || ONLYPIDSCALE == 1)
#if (ONLYPIDSCALE == 1 || BREWMODE == 2)
mqttSensors["currentWeight"] = []{ return weight; };
mqttSensors["flowRate"] = []{ return flowRate; };
#endif


Serial.begin(115200);

initTimer1();
Expand Down
2 changes: 0 additions & 2 deletions src/scalevoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ void shottimerscale() {
break;

case 20:
weightBrew = weight - weightPreBrew;

Comment on lines -194 to -195
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this was here before -- the weight is already calculated in brewvoid.h, why do it again here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half done refactoring and moving stuff out of main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless somebody remebers/knows why it should be here I think removing it here is good. Now that I looked at it again I would guess that the entire shottimerscale() could be removed.

if (timeBrewed == 0) {
shottimerCounter = 10;
}
Expand Down