Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Inonsistent Brew & Steam switch behaviours #413 #414 #414

Closed
wants to merge 9 commits into from
88 changes: 88 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Contributing to CleverCoffee

Thank you for considering contributing to the project. To ensure consistency and maintainability, please follow these style guidelines when submitting code changes.

## Code Style Guidelines

### Coding Standards

- **Indentation**: Use 4 spaces for indentation.
- **Curly Braces**: Place opening curly braces on the same line as the statement.
```cpp
// Example
if (condition) {
// code
}
else {
// code
}
```
- **Capitalization**: Follow C++ style capitalization.
```cpp
// Example
int myVariable;

void myFunction() {
// code
}
```
- **Operators**: Use spaces around operators.
```cpp
// Example
int sum = a + b;

if (x == y) {
// code
}
```

### Code Organization

**Blank Lines**: Include a blank line before and after a code block.
```cpp
// Example
void functionA() {
// code
}

void functionB() {
// code
}
```

### Encapsulation

- **Separate Files or Classes**: Encapsulate significant code changes in separate header files or classes if applicable. This helps maintain a modular and organized codebase, improving readability and reusability.
- **Include guards**: Use the #pragma directive instead of include guards:
```cpp
#pragma once
// code

// instead of
#ifndef MENU_H
#define MENU_H
// code
#endif
```

### Comments

**Meaningful Comments**: Write clear and descriptive comments. Comments should explain the 'why' behind the code, not just reiterate the code itself. For instance, the following example doesn't provide any additional information:
```cpp
// increment some values
i++;
j++;
```

## Submitting Changes

1. Fork the repository and create a new branch for your changes.
2. Ensure your code follows the outlined style guidelines.
3. Make sure to include clear commit messages explaining the purpose of the changes.
4. Open a pull request with a descriptive title and detailed information about the changes made.

## Code Review Process

All contributions will be reviewed to ensure compliance with the project's guidelines. Be prepared to address any feedback or suggestions for improvement during the review process.

Thank you for your contributions to CleverCoffee!
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Further development, with new features, will only be done for ESP32.
* Separate PID for steam mode with own parameters and target temperature (can be enabled in the web interface/MQTT or using the steam switch)
* Automatically brew by set time (including pre-infusion with additional dimmer for the pump).
* Automatically brew by weight when scale components are built in.
* Possible to change brew and steam switches to push buttons. Brew push button then has two actions: short press for brew, long press to flush.
* Allows brew switch detection (e.g. for the shot timer) by using an optocoupler module when deciding not to control the pump from the ESP ([details](https://rancilio-pid.github.io/ranciliopid-handbook/de/customization/brueherkennung.html#konfiguration-der-erkennung)).
* MQTT (IoT) support to monitor and manipulate all important parameters.
* Extended data monitoring via Influxdb/Grafana.
Expand Down
31 changes: 19 additions & 12 deletions src/Displayrotateupright.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ void displayLogo(String displaymessagetext, String displaymessagetext2) {
u8g2.drawStr(0, 55, displaymessagetext2.c_str());

// Rancilio startup logo
switch (machineLogo) {
case 1:
u8g2.drawXBMP(9, 2, startLogoRancilio_width, startLogoRancilio_height, startLogoRancilio_bits);
switch (machine) {
case RancilioSilvia: // Rancilio
u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height,
startLogoRancilio_bits);
break;

case 2:
u8g2.drawXBMP(0, 2, startLogoGaggia_width, startLogoGaggia_height, startLogoGaggia_bits);
case RancilioSilviaE: // Rancilio
u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height,
startLogoRancilio_bits);
break;

case 3:
u8g2.drawXBMP(22, 0, startLogoQuickMill_width, startLogoQuickMill_height, startLogoQuickMill_bits);
case Gaggia: // Gaggia
u8g2.drawXBMP(0, 2, startLogoGaggia_width, startLogoGaggia_height,
startLogoGaggia_bits);
break;
}

case QuickMill: // Quickmill
u8g2.drawXBMP(22, 0, startLogoQuickMill_width, startLogoQuickMill_height,
startLogoQuickMill_bits);
break;
}
u8g2.sendBuffer();
}

Expand Down Expand Up @@ -118,15 +125,15 @@ void displayShottimer(void) {
u8g2.sendBuffer();

}
if (SHOTTIMER == 1 && millis() >= brewTime_last_Millis && // directly after creating brewTime_last_mills (happens when turning off the brew switch, case 43 in the code) should be started
brewTime_last_Millis+brewswitchDelay >= millis() && // should run until millis() has caught up with brewswitchDelay, this can be used to control the display duration
brewTime_last_Millis < totalBrewTime) // if the totalBrewTime is reached automatically, nothing should be done, otherwise wrong time will be displayed because switch is pressed later than totalBrewTime
if (SHOTTIMER == 1 && millis() >= lastbrewTimeMillis && // directly after creating lastbrewTimeMillis (happens when turning off the brew switch, case 43 in the code) should be started
lastbrewTimeMillis + BREWSWITCHDELAY >= millis() && // should run until millis() has caught up with BREWSWITCHDELAY, this can be used to control the display duration
lastbrewTimeMillis < totalBrewTime) // if the totalBrewTime is reached automatically, nothing should be done, otherwise wrong time will be displayed because switch is pressed later than totalBrewTime
{
u8g2.clearBuffer();
u8g2.drawXBMP(0, 0, brewlogo_width, brewlogo_height, brewlogo_bits_u8g2);
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(5, 70);
u8g2.print((brewTime_last_Millis - startingTime) / 1000, 1);
u8g2.print((lastbrewTimeMillis - startingTime) / 1000, 1);
u8g2.setFont(u8g2_font_profont11_tf);
u8g2.sendBuffer();
}
Expand Down
2 changes: 1 addition & 1 deletion src/brewscaleini.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum BrewState {
BrewState brewcounter = kBrewIdle;
int brewswitch = 0;
int brewswitchTrigger = LOW;
int buttonStateBrewTrigger; // the current reading from the input pin
int lastButtonStateBrew; // the last valid reading from the input pin (debounced)
unsigned long lastDebounceTimeBrewTrigger = 0; // the last time the output pin was toggled
unsigned long debounceDelayBrewTrigger = 50;
unsigned long brewswitchTriggermillis = 0;
Expand Down
29 changes: 12 additions & 17 deletions src/brewvoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ void checkbrewswitch() {
#if (PIN_BREWSWITCH > 0)
int reading = digitalRead(PIN_BREWSWITCH);

if (reading != brewswitchTrigger) {
// reset the debouncing timer
if (reading != lastButtonStateBrew) {
// restart the debouncing timer
lastDebounceTimeBrewTrigger = millis();
// set new button state
lastButtonStateBrew = reading;
}

if ((millis() - lastDebounceTimeBrewTrigger) > debounceDelayBrewTrigger) {
else if ((millis() - lastDebounceTimeBrewTrigger) > debounceDelayBrewTrigger) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonStateBrewTrigger) {
buttonStateBrewTrigger = reading;
if (brewswitchTrigger != reading)
{
brewswitchTrigger = reading;
}
}

brewswitchTrigger = reading;
#endif

// Convert trigger signal to brew switch state
Expand Down Expand Up @@ -73,27 +72,23 @@ void checkbrewswitch() {
if ((brewswitchTrigger == HIGH && brewswitch == HIGH) || (machineState == kShotTimerAfterBrew) ) {
brewswitch = LOW;
brewswitchTriggerCase = 40;
brewswitchTriggermillis = millis();
debugPrintln("brewswitchTriggerCase 30: Brew Trigger LOW");
}
break;
case 31:
// Stop Manual brewing, button goes low:
if (brewswitchTrigger == LOW && brewswitch == LOW) {
brewswitchTriggerCase = 40;
brewswitchTriggermillis = millis();
debugPrintln("brewswitchTriggerCase 31: Manual Trigger - brewing stop");
digitalWrite(PIN_VALVE, relayOFF);
digitalWrite(PIN_PUMP, relayOFF);
}
break;

case 40:
// wait 5 Sec until next brew, detection
if (brewswitchTriggermillis + 5000 <= millis()) {
brewswitchTriggerCase = 10;
debugPrintln("brewswitchTriggerCase 40: Brew Trigger Next Loop");
}
// Go back to start and wait for brew button press
brewswitchTriggerCase = 10;
debugPrintln("brewswitchTriggerCase 40: Brew Trigger Next Loop");
break;

case 50:
Expand Down
38 changes: 2 additions & 36 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,39 +854,6 @@ float filterPressureValue(float input) {
return inSum;
}


/**
* @brief steamON & Quickmill
*/
void checkSteamON() {
if (STEAMSWITCHTYPE == 0) {
return;
}

// check digital GIPO
if (digitalRead(PIN_STEAMSWITCH) == HIGH) {
steamON = 1;
}

// if activated via web interface then steamFirstON == 1, prevent override
if (digitalRead(PIN_STEAMSWITCH) == LOW && steamFirstON == 0) {
steamON = 0;
}

// monitor QuickMill thermoblock steam-mode
if (machine == QuickMill) {
if (steamQM_active == true) {
if (checkSteamOffQM() == true) { // if true: steam-mode can be turned off
steamON = 0;
steamQM_active = false;
lastTimePVSwasON = 0;
} else {
steamON = 1;
}
}
}
}

void setEmergencyStopTemp() {
if (machineState == kSteam || machineState == kCoolDown) {
if (EmergencyStopTemp != 145) EmergencyStopTemp = 145;
Expand Down Expand Up @@ -2241,7 +2208,8 @@ void looppid() {
#endif

brew();
checkSteamON();
checkSteamSwitch();
checkPowerSwitch();

// set setpoint depending on steam or brew mode
if (steamON == 1) {
Expand All @@ -2251,8 +2219,6 @@ void looppid() {
}

setEmergencyStopTemp();
checkPowerSwitch();
checkSteamSwitch();

if (standbyModeOn && machineState != kStandby) {
updateStandbyTimer();
Expand Down
15 changes: 15 additions & 0 deletions src/steamswitchvoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ void checkSteamSwitch() {
if (digitalRead(PIN_STEAMSWITCH) == LOW && steamFirstON == 0) {
steamON = 0;
}

// monitor QuickMill thermoblock steam-mode
if (machine == QuickMill) {
if (steamQM_active == true) {
if (checkSteamOffQM() == true) { // if true: steam-mode can be turned off
steamON = 0;
steamQM_active = false;
lastTimePVSwasON = 0;
} else {
steamON = 1;
}
}
}

#elif STEAMSWITCHTYPE == 2 // TRIGGER
int reading = digitalRead(PIN_STEAMSWITCH);

Expand Down Expand Up @@ -57,4 +71,5 @@ void checkSteamSwitch() {

lastSteamSwitchTrigger = reading;
#endif

}
4 changes: 2 additions & 2 deletions src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ enum MACHINE {
#define WIFICONNECTIONDELAY 10000 // delay between reconnects in ms

// PID & Hardware
#define ONLYPID 1 // 1 = Only PID, 0 = PID and preinfusion
#define ONLYPID 1 // 0 = PID and preinfusion, 1 = Only PID
#define ONLYPIDSCALE 0 // 0 = off , 1 = OnlyPID with Scale
#define BREWMODE 1 // 1 = Brew by time (with preinfusion); 2 = Brew by weight (from scale)
#define BREWDETECTION 0 // 0 = off, 1 = Software (Onlypid 1), 2 = Hardware (Onlypid 0), 3 = Sensor/Hardware for Only PID
#define BREWSWITCHTYPE 0 // 0 = no switch connected, 1 = normal switch, 2 = trigger switch
#define POWERSWITCHTYPE 0 // 0 = no switch connected, 1 = normal switch, 2 = trigger switch
#define STEAMSWITCHTYPE 0 // 0 = no switch connected, 1 = normal switch, 2 = trigger switch
#define TRIGGERTYPE HIGH // LOW = low trigger, HIGH = high trigger relay for pump & valve
#define VOLTAGESENSORTYPE HIGH // BREWDETECTION 3 configuration
#define VOLTAGESENSORTYPE HIGH // BREWDETECTION 3 configuration (HIGH or LOW trigger optocoupler)
#define PINMODEVOLTAGESENSOR INPUT // Mode INPUT_PULLUP, INPUT or INPUT_PULLDOWN_16 (Only Pin 16)
#define PRESSURESENSOR 0 // 0 = no pressure sensor connected, 1 = pressure sensor connected
#define TEMP_LED 1 // Blink status LED when temp is in range
Expand Down