diff --git a/src/Displaytemplateminimal.h b/src/Displaytemplateminimal.h index 77cb8bba..038b9280 100644 --- a/src/Displaytemplateminimal.h +++ b/src/Displaytemplateminimal.h @@ -53,7 +53,8 @@ void printScreen() { u8g2.setFont(u8g2_font_profont22_tf); u8g2.print(setpoint, numDecimalsSetpoint); } - } else { + } + else { u8g2.setCursor(2, 2); u8g2.setFont(u8g2_font_profont22_tf); u8g2.print(temperature, numDecimalsInput); @@ -62,7 +63,8 @@ void printScreen() { if (pidMode == 1) { u8g2.print(char(74)); - } else { + } + else { u8g2.print(char(70)); } @@ -73,13 +75,10 @@ void printScreen() { if (brewcounter > kBrewIdle) { u8g2.setFont(u8g2_font_profont17_tf); - - // Brew u8g2.setCursor(2, 30); - } else { + } + else { u8g2.setFont(u8g2_font_profont10_tf); - - // Brew u8g2.setCursor(36, 30); } @@ -89,7 +88,8 @@ void printScreen() { if (ONLYPID == 1) { u8g2.print(brewtimesoftware, 0); - } else { + } + else { u8g2.print(totalBrewTime / 1000, 0); } @@ -112,7 +112,8 @@ void printScreen() { u8g2.drawFrame(116, 28, 12, 12); u8g2.drawXBMP(118, 30, 8, 8, antenna_NOK_u8g2); } - } else { + } + else { u8g2.drawFrame(116, 28, 12, 12); u8g2.setCursor(120, 30); u8g2.print("O"); diff --git a/src/Displaytemplatescale.h b/src/Displaytemplatescale.h index 704ea74d..eee83d84 100644 --- a/src/Displaytemplatescale.h +++ b/src/Displaytemplatescale.h @@ -44,13 +44,15 @@ void printScreen() { u8g2.drawLine(12, 48, 12, 58 - (temperature / 2)); u8g2.drawLine(13, 48, 13, 58 - (temperature / 2)); } - } else if (temperature > 106) { + } + else if (temperature > 106) { u8g2.drawLine(9, 48, 9, 5); u8g2.drawLine(10, 48, 10, 4); u8g2.drawLine(11, 48, 11, 3); u8g2.drawLine(12, 48, 12, 4); u8g2.drawLine(13, 48, 13, 5); - } else { + } + else { u8g2.drawLine(9, 48, 9, 58 - (temperature / 2)); u8g2.drawLine(10, 48, 10, 58 - (temperature / 2)); u8g2.drawLine(11, 48, 11, 58 - (temperature / 2)); @@ -69,7 +71,8 @@ void printScreen() { if (ONLYPID == 1) { u8g2.print(brewtimesoftware, 0); // deaktivieren wenn Preinfusion ( // voransetzen ) - } else { + } + else { u8g2.print(totalBrewTime / 1000, 1); // aktivieren wenn Preinfusion und eine Nachkommastelle // oder alternativ keine } @@ -79,10 +82,12 @@ void printScreen() { if (scaleFailure) { u8g2.print("fault"); - } else { + } + else { if (brewswitch == LOW) { u8g2.print(weight, 0); - } else { + } + else { u8g2.print(weightBrew, 0); } @@ -114,7 +119,8 @@ void printScreen() { for (int b = 0; b <= signalBars; b++) { u8g2.drawVLine(45 + (b * 2), 10 - (b * 2), b * 2); } - } else { + } + else { u8g2.drawXBMP(40, 2, 8, 8, antenna_NOK_u8g2); u8g2.setCursor(88, 2); u8g2.print("RC: "); @@ -126,12 +132,14 @@ void printScreen() { u8g2.setCursor(60, 1); u8g2.setFont(u8g2_font_profont11_tf); u8g2.print("MQTT"); - } else { + } + else { u8g2.setCursor(60, 2); u8g2.print(""); } } - } else { + } + else { u8g2.setCursor(40, 2); u8g2.print("Offline Mode"); } diff --git a/src/Displaytemplatestandard.h b/src/Displaytemplatestandard.h index 0896ca33..96eec1e8 100644 --- a/src/Displaytemplatestandard.h +++ b/src/Displaytemplatestandard.h @@ -52,13 +52,15 @@ void printScreen() u8g2.drawLine(12, 48, 12, 58 - (temperature / 2)); u8g2.drawLine(13, 48, 13, 58 - (temperature / 2)); } - } else if (temperature > 106) { + } + else if (temperature > 106) { u8g2.drawLine(9, 48, 9, 5); u8g2.drawLine(10, 48, 10, 4); u8g2.drawLine(11, 48, 11, 3); u8g2.drawLine(12, 48, 12, 4); u8g2.drawLine(13, 48, 13, 5); - } else { + } + else { u8g2.drawLine(9, 48, 9, 58 - (temperature / 2)); u8g2.drawLine(10, 48, 10, 58 - (temperature / 2)); u8g2.drawLine(11, 48, 11, 58 - (temperature / 2)); @@ -88,7 +90,8 @@ void printScreen() if (pidOutput < 99) { u8g2.print(pidOutput / 10, 1); - } else { + } + else { u8g2.print(pidOutput / 10, 0); } @@ -110,7 +113,8 @@ void printScreen() else { u8g2.print(totalBrewTime / 1000, 1); // Activate if pre-infusion and one decimal place or alternatively none } - } else { + } + else { // Show uptime of machine u8g2.print(langstring_uptime); float seconds = millis() / 1000; @@ -138,7 +142,8 @@ void printScreen() for (int b = 0; b <= signalBars; b++) { u8g2.drawVLine(45 + (b * 2), 10 - (b * 2), b * 2); } - } else { + } + else { u8g2.drawXBMP(40, 2, 8, 8, antenna_NOK_u8g2); u8g2.setCursor(88, 1); u8g2.print("RC: "); @@ -155,7 +160,8 @@ void printScreen() u8g2.print(""); } } - } else { + } + else { u8g2.setCursor(40, 1); u8g2.print(langstring_offlinemode); } diff --git a/src/Displaytemplatetemponly.h b/src/Displaytemplatetemponly.h index 85ee8daf..b8403355 100644 --- a/src/Displaytemplatetemponly.h +++ b/src/Displaytemplatetemponly.h @@ -18,8 +18,8 @@ void printScreen() { if ((machineState == kAtSetpoint || machineState == kPidNormal || machineState == kBrewDetectionTrailing) || ((machineState == kBrew || machineState == kShotTimerAfterBrew) && SHOTTIMER == 0) || // shottimer == 0, auch Bezug anzeigen machineState == kCoolDown || ((machineState == kInit || machineState == kColdStart) && HEATINGLOGO == 0) || - ((machineState == kPidOffline) && OFFLINEGLOGO == 0)) { - + ((machineState == kPidOffline) && OFFLINEGLOGO == 0)) + { if (!sensorError) { u8g2.clearBuffer(); @@ -31,18 +31,21 @@ void printScreen() { u8g2.setCursor(13, 12); u8g2.setFont(u8g2_font_fub35_tf); u8g2.print(temperature, 1); - } else { + } + else { u8g2.setCursor(-1, 12); u8g2.setFont(u8g2_font_fub35_tf); u8g2.print(temperature, 1); } } - } else { + } + else { if (temperature < 99.999) { u8g2.setCursor(13, 12); u8g2.setFont(u8g2_font_fub35_tf); u8g2.print(temperature, 1); - } else { + } + else { u8g2.setCursor(-1, 12); u8g2.setFont(u8g2_font_fub35_tf); u8g2.print(temperature, 1); @@ -58,7 +61,8 @@ void printScreen() { u8g2.drawFrame(116, 28, 12, 12); u8g2.drawXBMP(118, 30, 8, 8, antenna_NOK_u8g2); } - } else { + } + else { u8g2.drawFrame(116, 28, 12, 12); u8g2.setCursor(120, 30); u8g2.print("O"); diff --git a/src/display.h b/src/display.h index 6529b466..e193cd44 100644 --- a/src/display.h +++ b/src/display.h @@ -8,7 +8,6 @@ #if (OLED_DISPLAY != 0) - /** * @brief initialize display */ @@ -21,6 +20,14 @@ void u8g2_prepare(void) { u8g2.setDisplayRotation(DISPLAYROTATE); } +/** + * @brief Show water empty icon in upper right corner if water supply is low + */ +void displayWaterIcon(int x, int y) { + if (!waterFull) { + u8g2.drawXBMP(x, y, 8, 8, water_EMPTY_u8g2); + } +} /** * @brief print message @@ -54,39 +61,22 @@ void displayLogo(String displaymessagetext, String displaymessagetext2) { // Rancilio startup logo switch (machine) { case RancilioSilvia: // Rancilio - u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height, - startLogoRancilio_bits); + u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height, startLogoRancilio_bits); break; case RancilioSilviaE: // Rancilio - u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height, - startLogoRancilio_bits); + u8g2.drawXBMP(41, 2, startLogoRancilio_width, startLogoRancilio_height, startLogoRancilio_bits); break; case Gaggia: // Gaggia - u8g2.drawXBMP(0, 2, startLogoGaggia_width, startLogoGaggia_height, - startLogoGaggia_bits); + u8g2.drawXBMP(0, 2, startLogoGaggia_width, startLogoGaggia_height, startLogoGaggia_bits); break; case QuickMill: // Quickmill - u8g2.drawXBMP(22, 0, startLogoQuickMill_width, startLogoQuickMill_height, - startLogoQuickMill_bits); + u8g2.drawXBMP(22, 0, startLogoQuickMill_width, startLogoQuickMill_height, startLogoQuickMill_bits); break; } - u8g2.sendBuffer(); -} -/** - * @brief calibration mode - * - * @param display_distance - */ -void displayDistance(int display_distance) { - u8g2.clearBuffer(); - u8g2.setCursor(13, 12); - u8g2.setFont(u8g2_font_fub20_tf); - u8g2.printf("%d", display_distance); - u8g2.print("mm"); u8g2.sendBuffer(); } @@ -103,6 +93,7 @@ void displayShottimer(void) { u8g2.setCursor(64, 25); u8g2.print(timeBrewed / 1000, 1); u8g2.setFont(u8g2_font_profont11_tf); + displayWaterIcon(119, 1); u8g2.sendBuffer(); } @@ -117,6 +108,7 @@ void displayShottimer(void) { u8g2.setCursor(64, 25); u8g2.print(lastbrewTime / 1000, 1); u8g2.setFont(u8g2_font_profont11_tf); + displayWaterIcon(119, 1); u8g2.sendBuffer(); } @@ -134,6 +126,7 @@ void displayShottimer(void) { u8g2.print(weightBrew, 0); u8g2.print("g"); u8g2.setFont(u8g2_font_profont11_tf); + displayWaterIcon(119, 1); u8g2.sendBuffer(); } @@ -148,6 +141,7 @@ void displayShottimer(void) { u8g2.print(weightBrew, 0); u8g2.print(" g"); u8g2.setFont(u8g2_font_profont11_tf); + displayWaterIcon(119, 1); u8g2.sendBuffer(); } #endif @@ -172,7 +166,8 @@ void Displaymachinestate() { for (int b = 0; b <= signalBars; b++) { u8g2.drawVLine(45 + (b * 2), 10 - (b * 2), b * 2); } - } else { + } + else { u8g2.drawXBMP(40, 2, 8, 8, antenna_NOK_u8g2); u8g2.setCursor(88, 1); u8g2.print("RC: "); @@ -184,7 +179,8 @@ void Displaymachinestate() { u8g2.setCursor(60, 1); u8g2.setFont(u8g2_font_profont11_tf); u8g2.print("MQTT"); - } else { + } + else { u8g2.setCursor(60, 2); u8g2.print(""); } @@ -242,6 +238,15 @@ void Displaymachinestate() { u8g2.setFont(u8g2_font_profont22_tf); u8g2.print(temperature, 0); u8g2.setCursor(64, 25); + displayWaterIcon(119, 1); + u8g2.sendBuffer(); + } + + // Water empty + if (machineState == kWaterEmpty) { + u8g2.clearBuffer(); + u8g2.drawXBMP( 45, 0, water_empty_big_width, water_empty_big_height, water_EMPTY_big_u8g2); + u8g2.setFont(u8g2_font_profont11_tf); u8g2.sendBuffer(); } @@ -252,11 +257,13 @@ void Displaymachinestate() { #if OLED_DISPLAY != 0 displayMessage(langstring_bckffinished[0], langstring_bckffinished[1], "", "", "", ""); #endif - } else if (backflushState == 10) { + } + else if (backflushState == 10) { #if OLED_DISPLAY != 0 displayMessage(langstring_bckfactivated[0], langstring_bckfactivated[1], "", "", "", ""); #endif - } else if (backflushState > 10) { + } + else if (backflushState > 10) { #if OLED_DISPLAY != 0 displayMessage(langstring_bckfrunning[0], String(flushCycles), langstring_bckfrunning[1], String(maxflushCycles), "", ""); #endif @@ -307,4 +314,5 @@ void Displaymachinestate() { displayMessage("EEPROM Error, please set Values", "", "", "", "", ""); } } + #endif diff --git a/src/icon.h b/src/icon.h index c981fc53..875bfd7c 100644 --- a/src/icon.h +++ b/src/icon.h @@ -27,6 +27,8 @@ #define OFFLogo_height 53 #define steamlogo_width 60 #define steamlogo_height 58 +#define water_empty_big_width 47 +#define water_empty_big_height 64 static const unsigned char PROGMEM logo_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x01, 0xff, 0x00, 0x03, 0x83, 0x80, 0x03, 0x01, 0x80, 0x06, @@ -226,9 +228,51 @@ static const unsigned char PROGMEM antenna_NOK_u8g2[] = { B10001000 }; +static const unsigned char PROGMEM water_EMPTY_u8g2[] = { + B00001001, + B01001010, + B00011100, + B00010100, + B00101110, + B00111110, + B01011100, + B10000000 +}; + +// "water empty logo" +static const unsigned char PROGMEM water_EMPTY_big_u8g2[] = { + 0x00,0x00,0xfc,0x07,0x00,0x00,0x00,0x80,0xff,0x3f,0x00,0x00,0x00,0xe0, + 0x07,0xfc,0x00,0x00,0x00,0xf0,0x00,0xe0,0x01,0x00,0x00,0x3c,0xf0,0x81, + 0x03,0x00,0x00,0x1e,0xfe,0x0f,0x07,0x00,0x00,0x87,0x1f,0x3f,0x0e,0x00, + 0x00,0xc3,0x01,0x78,0x1c,0x00,0x80,0xf3,0x00,0xe0,0x38,0x00,0xc0,0x31, + 0x00,0xc0,0x31,0x00,0xc0,0x18,0x00,0x80,0x73,0x00,0xe0,0x1c,0x00,0x00, + 0x67,0x00,0x60,0x0c,0x00,0x00,0xe6,0x00,0x60,0x0e,0x00,0x00,0xc6,0x00, + 0x60,0x06,0x00,0x00,0xcc,0x00,0x70,0x06,0x00,0x00,0xcc,0x00,0x30,0x06, + 0x00,0x00,0xcc,0x00,0xfc,0x0f,0x00,0x00,0xcc,0x00,0xfc,0x1f,0x00,0x00, + 0xcc,0x00,0x0c,0x18,0x00,0x00,0xcc,0x00,0x0c,0x18,0x00,0x00,0xcc,0x00, + 0x0c,0x18,0x00,0x00,0xcc,0x00,0x0c,0x18,0x00,0x00,0xcc,0x01,0x0e,0x18, + 0x00,0x00,0xcc,0x01,0x06,0x38,0x00,0x00,0xcc,0x01,0x0e,0x38,0x00,0x00, + 0xcc,0x01,0xfe,0x3f,0x00,0x00,0xcc,0x01,0xfc,0x1f,0x00,0x00,0xcc,0x01, + 0x00,0x00,0x00,0x00,0xcc,0x01,0x00,0x00,0x00,0x00,0xcc,0x01,0x00,0x00, + 0x80,0x03,0xcc,0x01,0x00,0x00,0xc0,0x07,0xcc,0x01,0x00,0x00,0xe0,0x0f, + 0xcc,0x01,0x80,0x00,0x60,0x1c,0xcc,0x01,0xc0,0x01,0x70,0x38,0xfe,0x01, + 0xe0,0x03,0xe0,0x70,0xfe,0x03,0x70,0x03,0xc0,0xe1,0x86,0x03,0x30,0x06, + 0x80,0xe3,0x06,0x03,0x38,0x0e,0x00,0x77,0x06,0x03,0x1c,0x0c,0x00,0x7e, + 0x06,0x03,0x0c,0x1c,0x00,0xfc,0x86,0x03,0x4e,0x18,0x00,0xc0,0x87,0x03, + 0xc6,0x30,0x00,0x80,0xff,0x03,0x47,0x30,0x00,0x00,0xff,0x03,0x03,0x70, + 0x00,0x00,0x86,0x03,0x03,0x60,0x00,0x00,0x07,0x03,0x73,0x60,0x00,0x00, + 0x03,0x07,0x63,0x70,0x00,0x00,0x03,0x07,0x47,0x30,0x00,0x00,0x07,0x03, + 0x0e,0x38,0x00,0x00,0x8e,0x03,0x1c,0x1c,0x00,0x00,0xfe,0x03,0xf8,0x0f, + 0x00,0x00,0xfe,0x03,0xf0,0x07,0x00,0x00,0x86,0x03,0x00,0x00,0x00,0x00, + 0x86,0x03,0x00,0x00,0x00,0x00,0x06,0x03,0x00,0x00,0x00,0x00,0x06,0x03, + 0x00,0x00,0x00,0x00,0x06,0x03,0x00,0x00,0x00,0x00,0x8e,0x03,0x00,0x00, + 0x00,0xf0,0xff,0x7f,0x00,0x00,0x00,0xf0,0xff,0x7f,0x00,0x00,0x00,0x30, + 0x00,0x60,0x00,0x00,0x00,0x30,0x00,0x60,0x00,0x00,0x00,0xf0,0xff,0x7f, + 0x00,0x00,0x00,0xf0,0xff,0x7f +}; + // 'logo', 64x59px -static const unsigned char brewlogo_bits_u8g2 [] PROGMEM = -{ +static const unsigned char brewlogo_bits_u8g2 [] PROGMEM = { 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/main.cpp b/src/main.cpp index 1e94da63..0bf3dee3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,6 +73,7 @@ enum MachineState { kSteam = 40, kCoolDown = 45, kBackflush = 50, + kWaterEmpty = 70, kEmergencyStop = 80, kPidOffline = 90, kStandby = 95, @@ -152,6 +153,7 @@ void setBDPIDTunings(); void loopcalibrate(); void looppid(); void loopLED(); +void loopWater(); void printMachineState(); char const* machinestateEnumToString(MachineState machineState); void initSteamQM(); @@ -248,6 +250,14 @@ int backflushON = 0; // 1 = backflush mode active int flushCycles = 0; // number of active flush cycles int backflushState = 10; // counter for state machine +// Water sensor +boolean waterFull = true; +unsigned long lastWaterCheck; +const unsigned long waterCheckInterval = 200; // Check water level every 200 ms +int waterCheckConsecutiveReads = 0; // Counter for consecutive readings of water sensor +const int waterCountsNeeded = 3; // Number of same readings to change water sensing + + // Moving average for software brew detection double tempRateAverage = 0; // average value of temp values double tempChangeRateAverageMin = 0; @@ -943,6 +953,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1014,6 +1028,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1063,6 +1081,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1111,9 +1133,14 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } + break; case kBrew: @@ -1178,6 +1205,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1214,6 +1245,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1236,6 +1271,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1276,6 +1315,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1294,6 +1337,10 @@ void handleMachineState() { machineState = kPidOffline; } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1313,6 +1360,20 @@ void handleMachineState() { } break; + case kWaterEmpty: + if (waterFull) { + machineState = kPidNormal; + } + + if (pidON == 0) { + machineState = kPidOffline; + } + + if (sensorError) { + machineState = kSensorError; + } + break; + case kPidOffline: if (pidON == 1) { if (coldstart) { @@ -1325,6 +1386,10 @@ void handleMachineState() { } } + if (!waterFull) { + machineState = kWaterEmpty; + } + if (sensorError) { machineState = kSensorError; } @@ -1393,6 +1458,8 @@ char const* machinestateEnumToString(MachineState machineState) { return "Cool Down"; case kBackflush: return "Backflush"; + case kWaterEmpty: + return "Water Empty"; case kEmergencyStop: return "Emergency Stop"; case kPidOffline: @@ -2049,6 +2116,12 @@ void setup() { pinMode(PIN_STATUSLED, OUTPUT); } + #if WATER_SENS == 1 + pinMode(PIN_WATERSENSOR, INPUT_PULLUP); + #elif WATER_SENS == 2 + pinMode(PIN_WATERSENSOR, INPUT_PULLDOWN); + #endif + #if OLED_DISPLAY != 0 u8g2.setI2CAddress(oled_i2c * 2); u8g2.begin(); @@ -2150,6 +2223,10 @@ void loop() { loopLED(); } + if (WATER_SENS > 0) { + loopWater(); + } + checkForRemoteSerialClients(); } @@ -2239,9 +2316,15 @@ void looppid() { checkPressure(); #endif - brew(); checkSteamON(); + if(machineState != kWaterEmpty) { + brew(); + } + + checkSteamSwitch(); + checkPowerSwitch(); + // set setpoint depending on steam or brew mode if (steamON == 1) { setpoint = steamSetpoint; @@ -2250,8 +2333,6 @@ void looppid() { } setEmergencyStopTemp(); - checkPowerSwitch(); - checkSteamSwitch(); if (standbyModeOn && machineState != kStandby) { updateStandbyTimer(); @@ -2278,7 +2359,7 @@ void looppid() { } #endif - if (machineState == kPidOffline || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || brewPIDdisabled) { + if (machineState == kPidOffline || machineState == kWaterEmpty || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || brewPIDdisabled) { if (pidMode == 1) { // Force PID shutdown pidMode = 0; @@ -2392,6 +2473,45 @@ void loopLED() { } } +void loopWater() { + if ((millis() - lastWaterCheck) > waterCheckInterval) { + lastWaterCheck = millis(); + + bool isWaterDetected = digitalRead(PIN_WATERSENSOR) == (WATER_SENS == 1 ? LOW : HIGH); + + if (isWaterDetected) { + // Water is detected, increment counter if it was previously empty + if (!waterFull) { + waterCheckConsecutiveReads++; + + if (waterCheckConsecutiveReads >= waterCountsNeeded) { + waterFull = true; + debugPrintln("Water full"); + waterCheckConsecutiveReads = 0; + } + } + else { + waterCheckConsecutiveReads = 0; + } + } + else { + // No water detected, increment counter if it was previously full + if (waterFull) { + waterCheckConsecutiveReads++; + + if (waterCheckConsecutiveReads >= waterCountsNeeded) { + waterFull = false; + debugPrintln("Water empty"); + waterCheckConsecutiveReads = 0; + } + } + else { + waterCheckConsecutiveReads = 0; + } + } + } +} + void setBackflush(int backflush) { backflushON = backflush; } diff --git a/src/userConfig_sample.h b/src/userConfig_sample.h index efc0e2e4..9560279f 100644 --- a/src/userConfig_sample.h +++ b/src/userConfig_sample.h @@ -62,6 +62,7 @@ enum MACHINE { #define TRIGGERTYPE HIGH // LOW = low trigger, HIGH = high trigger relay for pump & valve #define PRESSURESENSOR 0 // 0 = no pressure sensor connected, 1 = pressure sensor connected #define TEMP_LED 1 // Blink status LED when temp is in range +#define WATER_SENS 0 // 0 = no water sensor, 1 = water sensor XKC-Y25-NPN connected, 2 = XKC-Y25-PNP connected // Brew Scale #define SCALE_SAMPLES 2 // Load cell sample rate