diff --git a/src/brewHandler.h b/src/brewHandler.h index cd586e0e..90c61d36 100644 --- a/src/brewHandler.h +++ b/src/brewHandler.h @@ -153,7 +153,7 @@ void backflush() { backflushState = kBackflushWaitBrewswitchOff; // Force reset in case backflushOn is reset during backflush! LOG(INFO, "Backflush: Disabled via Webinterface"); } - else if (offlineMode == 1 || currBrewState > kBrewIdle || maxflushCycles <= 0 || backflushOn == 0) { + else if (offlineMode == 1 || currBrewState > kBrewIdle || maxBackflushCycles <= 0 || backflushOn == 0) { return; } @@ -189,7 +189,7 @@ void backflush() { break; case kBackflushFilling: - if (millis() - startingTime > FILLTIME) { + if (millis() - startingTime > (backflushFillTime * 1000)) { startingTime = millis(); backflushState = kBackflushFlushingStart; } @@ -200,17 +200,17 @@ void backflush() { LOG(INFO, "Backflush: Flushing to drip tray..."); valveRelay.off(); pumpRelay.off(); - flushCycles++; + currBackflushCycles++; backflushState = kBackflushFlushing; break; case kBackflushFlushing: - if (millis() - startingTime > flushTime && flushCycles < maxflushCycles) { + if (millis() - startingTime > (backflushFlushTime * 10000) && currBackflushCycles < maxBackflushCycles) { startingTime = millis(); backflushState = kBackflushFillingStart; } - else if (flushCycles >= maxflushCycles) { + else if (currBackflushCycles >= maxBackflushCycles) { backflushState = kBackflushWaitBrewswitchOff; } @@ -221,7 +221,7 @@ void backflush() { LOG(INFO, "Backflush: Finished!"); valveRelay.off(); pumpRelay.off(); - flushCycles = 0; + currBackflushCycles = 0; backflushState = kBackflushWaitBrewswitchOn; } diff --git a/src/defaults.h b/src/defaults.h index 86ef035c..173db7bb 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -42,52 +42,61 @@ int writeSysParamsToStorage(void); #define BD_SENSITIVITY 120 // brew detection sensitivity, be careful: if too low, then there is the risk of wrong brew detection and rising temperature #define PRE_INFUSION_TIME 2 // pre-infusion time in seconds #define PRE_INFUSION_PAUSE_TIME 5 // pre-infusion pause time in seconds +#define BACKFLUSH_CYCLES 5 // number of cycles the backflush should run +#define BACKFLUSH_FILL_TIME 5 // time in seconds the pump is running during backflush +#define BACKFLUSH_FLUSH_TIME 10 // time in seconds the 3-way valve is open during backflush #define SCALE_WEIGHTSETPOINT 30 // Target weight in grams #define WIFI_CREDENTIALS_SAVED 0 // Flag if wifi setup is done. 0: not set up, 1: credentials set up via wifi manager #define STANDBY_MODE_ON 0 // Standby mode off by default #define STANDBY_MODE_TIME 30 // Time in minutes until the heater is turned off -#define PID_KP_START_MIN 0 -#define PID_KP_START_MAX 999 -#define PID_TN_START_MIN 0 -#define PID_TN_START_MAX 999 -#define PID_KP_REGULAR_MIN 0 -#define PID_KP_REGULAR_MAX 999 -#define PID_TN_REGULAR_MIN 0 -#define PID_TN_REGULAR_MAX 999 -#define PID_TV_REGULAR_MIN 0 -#define PID_TV_REGULAR_MAX 999 -#define PID_I_MAX_REGULAR_MIN 0 -#define PID_I_MAX_REGULAR_MAX 999 -#define PID_KP_BD_MIN 0 -#define PID_KP_BD_MAX 999 -#define PID_TN_BD_MIN 0 -#define PID_TN_BD_MAX 999 -#define PID_TV_BD_MIN 0 -#define PID_TV_BD_MAX 999 -#define BREW_SETPOINT_MIN 20 -#define BREW_SETPOINT_MAX 110 -#define STEAM_SETPOINT_MIN 100 -#define STEAM_SETPOINT_MAX 140 -#define BREW_TEMP_OFFSET_MIN 0 -#define BREW_TEMP_OFFSET_MAX 20 -#define BREW_TEMP_TIME_MIN 1 -#define BREW_TEMP_TIME_MAX 180 -#define BREW_TIME_MIN 0 -#define BREW_TIME_MAX 180 -#define BREW_PID_DELAY_MIN 0 -#define BREW_PID_DELAY_MAX 60 -#define BREW_SW_TIME_MIN 1 -#define BREW_SW_TIME_MAX 180 -#define BD_THRESHOLD_MIN 0 -#define BD_THRESHOLD_MAX 999 -#define PRE_INFUSION_TIME_MIN 0 -#define PRE_INFUSION_TIME_MAX 60 -#define PRE_INFUSION_PAUSE_MIN 0 -#define PRE_INFUSION_PAUSE_MAX 60 -#define WEIGHTSETPOINT_MIN 0 -#define WEIGHTSETPOINT_MAX 500 -#define PID_KP_STEAM_MIN 0 -#define PID_KP_STEAM_MAX 500 -#define STANDBY_MODE_TIME_MIN 30 -#define STANDBY_MODE_TIME_MAX 120 +#define PID_KP_START_MIN 0 +#define PID_KP_START_MAX 999 +#define PID_TN_START_MIN 0 +#define PID_TN_START_MAX 999 +#define PID_KP_REGULAR_MIN 0 +#define PID_KP_REGULAR_MAX 999 +#define PID_TN_REGULAR_MIN 0 +#define PID_TN_REGULAR_MAX 999 +#define PID_TV_REGULAR_MIN 0 +#define PID_TV_REGULAR_MAX 999 +#define PID_I_MAX_REGULAR_MIN 0 +#define PID_I_MAX_REGULAR_MAX 999 +#define PID_KP_BD_MIN 0 +#define PID_KP_BD_MAX 999 +#define PID_TN_BD_MIN 0 +#define PID_TN_BD_MAX 999 +#define PID_TV_BD_MIN 0 +#define PID_TV_BD_MAX 999 +#define BREW_SETPOINT_MIN 20 +#define BREW_SETPOINT_MAX 110 +#define STEAM_SETPOINT_MIN 100 +#define STEAM_SETPOINT_MAX 140 +#define BREW_TEMP_OFFSET_MIN 0 +#define BREW_TEMP_OFFSET_MAX 20 +#define BREW_TEMP_TIME_MIN 1 +#define BREW_TEMP_TIME_MAX 180 +#define BREW_TIME_MIN 0 +#define BREW_TIME_MAX 180 +#define BREW_PID_DELAY_MIN 0 +#define BREW_PID_DELAY_MAX 60 +#define BREW_SW_TIME_MIN 1 +#define BREW_SW_TIME_MAX 180 +#define BD_THRESHOLD_MIN 0 +#define BD_THRESHOLD_MAX 999 +#define PRE_INFUSION_TIME_MIN 0 +#define PRE_INFUSION_TIME_MAX 60 +#define PRE_INFUSION_PAUSE_MIN 0 +#define PRE_INFUSION_PAUSE_MAX 60 +#define BACKFLUSH_CYCLES_MIN 5 +#define BACKFLUSH_CYCLES_MAX 20 +#define BACKFLUSH_FILL_TIME_MIN 5 +#define BACKFLUSH_FILL_TIME_MAX 20 +#define BACKFLUSH_FLUSH_TIME_MIN 5 +#define BACKFLUSH_FLUSH_TIME_MAX 20 +#define WEIGHTSETPOINT_MIN 0 +#define WEIGHTSETPOINT_MAX 500 +#define PID_KP_STEAM_MIN 0 +#define PID_KP_STEAM_MAX 500 +#define STANDBY_MODE_TIME_MIN 30 +#define STANDBY_MODE_TIME_MAX 120 diff --git a/src/display/displayCommon.h b/src/display/displayCommon.h index 73ab97d7..a1427d2c 100644 --- a/src/display/displayCommon.h +++ b/src/display/displayCommon.h @@ -384,9 +384,9 @@ bool displayMachineState() { default: u8g2.setFont(u8g2_font_fub17_tf); u8g2.setCursor(42, 42); - u8g2.print(flushCycles + 1, 0); + u8g2.print(currBackflushCycles + 1, 0); u8g2.print("/"); - u8g2.print(maxflushCycles, 0); + u8g2.print(maxBackflushCycles, 0); break; } diff --git a/src/main.cpp b/src/main.cpp index 6efc0cba..c84e7699 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,9 +122,12 @@ unsigned int wifiReconnects = 0; // actual number of reconnects const char* OTApass = OTAPASS; // Backflush values -const unsigned long fillTime = FILLTIME; -const unsigned long flushTime = FLUSHTIME; -int maxflushCycles = MAXFLUSHCYCLES; +uint8_t maxBackflushCycles = BACKFLUSH_CYCLES; +double backflushFillTime = BACKFLUSH_FILL_TIME; +double backflushFlushTime = BACKFLUSH_FLUSH_TIME; +int backflushOn = 0; +int backflushState = 10; +int currBackflushCycles = 0; // number of active flush cycles // Optocoupler unsigned long previousMillisOptocouplerReading = millis(); @@ -264,6 +267,9 @@ SysPara sysParaBrewThresh(&brewSensitivity, BD_THRESHOLD_MIN, BD_THRESHO SysPara sysParaWifiCredentialsSaved(&wifiCredentialsSaved, 0, 1, STO_ITEM_WIFI_CREDENTIALS_SAVED); SysPara sysParaPreInfTime(&preinfusion, PRE_INFUSION_TIME_MIN, PRE_INFUSION_TIME_MAX, STO_ITEM_PRE_INFUSION_TIME); SysPara sysParaPreInfPause(&preinfusionPause, PRE_INFUSION_PAUSE_MIN, PRE_INFUSION_PAUSE_MAX, STO_ITEM_PRE_INFUSION_PAUSE); +SysPara sysParaBackflushCycles(&maxBackflushCycles, BACKFLUSH_CYCLES_MIN, BACKFLUSH_CYCLES_MAX, STO_ITEM_BACKFLUSH_CYCLES); +SysPara sysParaBackflushFillTime(&backflushFillTime, BACKFLUSH_FILL_TIME_MIN, BACKFLUSH_FILL_TIME_MAX, STO_ITEM_BACKFLUSH_FILL_TIME); +SysPara sysParaBackflushFlushTime(&backflushFlushTime, BACKFLUSH_FLUSH_TIME_MIN, BACKFLUSH_FLUSH_TIME_MAX, STO_ITEM_BACKFLUSH_FLUSH_TIME); SysPara sysParaPidKpSteam(&steamKp, PID_KP_STEAM_MIN, PID_KP_STEAM_MAX, STO_ITEM_PID_KP_STEAM); SysPara sysParaSteamSetpoint(&steamSetpoint, STEAM_SETPOINT_MIN, STEAM_SETPOINT_MAX, STO_ITEM_STEAM_SETPOINT); SysPara sysParaWeightSetpoint(&weightSetpoint, WEIGHTSETPOINT_MIN, WEIGHTSETPOINT_MAX, STO_ITEM_WEIGHTSETPOINT); @@ -279,10 +285,6 @@ const double EmergencyStopTemp = 145; // Temp EmergencyStopTemp float inX = 0, inY = 0, inOld = 0, inSum = 0; // used for filterPressureValue() boolean brewDetected = 0; boolean setupDone = false; -int backflushOn = 0; // 1 = backflush mode active -int flushCycles = 0; // number of active flush cycles - -int backflushState = 10; // Water sensor boolean waterFull = true; @@ -2071,6 +2073,9 @@ int readSysParamsFromStorage(void) { if (sysParaBrewThresh.getStorage() != 0) return -1; if (sysParaPreInfTime.getStorage() != 0) return -1; if (sysParaPreInfPause.getStorage() != 0) return -1; + if (sysParaBackflushCycles.getStorage() != 0) return -1; + if (sysParaBackflushFillTime.getStorage() != 0) return -1; + if (sysParaBackflushFlushTime.getStorage() != 0) return -1; if (sysParaPidKpSteam.getStorage() != 0) return -1; if (sysParaSteamSetpoint.getStorage() != 0) return -1; if (sysParaWeightSetpoint.getStorage() != 0) return -1; @@ -2110,6 +2115,9 @@ int writeSysParamsToStorage(void) { if (sysParaBrewThresh.setStorage() != 0) return -1; if (sysParaPreInfTime.setStorage() != 0) return -1; if (sysParaPreInfPause.setStorage() != 0) return -1; + if (sysParaBackflushCycles.setStorage() != 0) return -1; + if (sysParaBackflushFillTime.setStorage() != 0) return -1; + if (sysParaBackflushFlushTime.setStorage() != 0) return -1; if (sysParaPidKpSteam.setStorage() != 0) return -1; if (sysParaSteamSetpoint.setStorage() != 0) return -1; if (sysParaWeightSetpoint.setStorage() != 0) return -1; diff --git a/src/storage.h b/src/storage.h index ee54171c..275b7780 100644 --- a/src/storage.h +++ b/src/storage.h @@ -30,6 +30,9 @@ typedef enum { STO_ITEM_WIFI_CREDENTIALS_SAVED, // flag for wifisetup STO_ITEM_PRE_INFUSION_TIME, // pre-infusion time STO_ITEM_PRE_INFUSION_PAUSE, // pre-infusion pause + STO_ITEM_BACKFLUSH_CYCLES, // number of cycles the backflush should run + STO_ITEM_BACKFLUSH_FILL_TIME, // time in ms the pump is running during backflush + STO_ITEM_BACKFLUSH_FLUSH_TIME, // time in ms the 3-way valve is open during backflush STO_ITEM_PID_KP_STEAM, // PID P part at steam phase STO_ITEM_STEAM_SETPOINT, // Setpoint for Steam mode STO_ITEM_SOFT_AP_ENABLED_CHECK, // soft AP enable state @@ -68,41 +71,33 @@ typedef enum { typedef struct __attribute__((packed)) { // Any 'freeToUse' areas ensure the compatibility to origin EEPROM layout and can be used by new value. double pidKpRegular; - uint8_t reserved1[2]; double pidTnRegular; uint8_t pidOn; - uint8_t freeToUse1; double pidTvRegular; double pidIMaxRegular; - uint8_t freeToUse2; double brewSetpoint; double brewTempOffset; - uint8_t freeToUse3; double brewTimeMs; float scaleCalibration; double preInfusionTimeMs; + uint8_t backflushCycles; + double backflushFillTimeMs; + double backflushFlushTimeMs; float scaleKnownWeight; double preInfusionPauseMs; - uint8_t freeToUse6[21]; uint8_t pidBdOn; double pidKpBd; float scale2Calibration; double pidTnBd; - uint8_t freeToUse8[2]; double pidTvBd; - uint8_t freeToUse9[2]; double brewSwTimeSec; double brewPIDDelaySec; - uint8_t freeToUse10; double brewDetectionThreshold; uint8_t wifiCredentialsSaved; uint8_t useStartPonM; double pidKpStart; - uint8_t freeToUse12[2]; uint8_t softApEnabledCheck; - uint8_t freeToUse13[9]; double pidTnStart; - uint8_t freeToUse14[2]; char wifiSSID[25 + 1]; char wifiPassword[25 + 1]; double weightSetpoint; @@ -115,41 +110,33 @@ typedef struct __attribute__((packed)) { // set item defaults static const sto_data_t itemDefaults PROGMEM = { AGGKP, // STO_ITEM_PID_KP_REGULAR - {0xFF, 0xFF}, // reserved (maybe for structure version) AGGTN, // STO_ITEM_PID_TN_REGULAR 0, // STO_ITEM_PID_ON - 0xFF, // free to use AGGTV, // STO_ITEM_PID_TV_REGULAR AGGIMAX, // STO_ITEM_PID_I_MAX_REGULAR - 0xFF, // free to use SETPOINT, // STO_ITEM_BREW_SETPOINT TEMPOFFSET, // STO_ITEM_BREW_TEMP_OFFSET - 0xFF, // free to use BREW_TIME, // STO_ITEM_BREW_TIME SCALE_CALIBRATION_FACTOR, // STO_ITEM_SCALE_CALIBRATION_FACTOR PRE_INFUSION_TIME, // STO_ITEM_PRE_INFUSION_TIME SCALE_KNOWN_WEIGHT, // STO_ITEM_SCALE_KNOWN_WEIGHT PRE_INFUSION_PAUSE_TIME, // STO_ITEM_PRE_INFUSION_PAUSE - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // free to use + BACKFLUSH_CYCLES, // STO_ITEM_BACKFLUSH_CYCLES + BACKFLUSH_FILL_TIME, // STO_ITEM_BACKFLUSH_FILLTIME + BACKFLUSH_FLUSH_TIME, // STO_ITEM_BACKFLUSH_FLUSHTIME 0, // STO_ITEM_USE_PID_BD AGGBKP, // STO_ITEM_PID_KP_BD SCALE2_CALIBRATION_FACTOR, // STO_ITEM_SCALE2_CALIBRATION_FACTOR AGGBTN, // STO_ITEM_PID_TN_BD - {0xFF, 0xFF}, // free to use AGGBTV, // STO_ITEM_PID_TV_BD - {0xFF, 0xFF}, // free to use BREW_SW_TIME, // STO_ITEM_BREW_SW_TIME BREW_PID_DELAY, // STO_ITEM_BREW_PID_DELAY - 0xFF, // free to use BD_SENSITIVITY, // STO_ITEM_BD_THRESHOLD WIFI_CREDENTIALS_SAVED, // STO_ITEM_WIFI_CREDENTIALS_SAVED 0, // STO_ITEM_USE_START_PON_M STARTKP, // STO_ITEM_PID_KP_START - {0xFF, 0xFF}, // free to use 0, // STO_ITEM_SOFT_AP_ENABLED_CHECK - {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // free to use STARTTN, // STO_ITEM_PID_TN_START - {0xFF, 0xFF}, // free to use "", // STO_ITEM_WIFI_SSID "", // STO_ITEM_WIFI_PASSWORD SCALE_WEIGHTSETPOINT, // STO_ITEM_WEIGHTSETPOINT @@ -219,6 +206,21 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize = size = STRUCT_MEMBER_SIZE(sto_data_t, preInfusionPauseMs); break; + case STO_ITEM_BACKFLUSH_CYCLES: + addr = offsetof(sto_data_t, backflushCycles); + size = STRUCT_MEMBER_SIZE(sto_data_t, backflushCycles); + break; + + case STO_ITEM_BACKFLUSH_FILL_TIME: + addr = offsetof(sto_data_t, backflushFillTimeMs); + size = STRUCT_MEMBER_SIZE(sto_data_t, backflushFillTimeMs); + break; + + case STO_ITEM_BACKFLUSH_FLUSH_TIME: + addr = offsetof(sto_data_t, backflushFlushTimeMs); + size = STRUCT_MEMBER_SIZE(sto_data_t, backflushFlushTimeMs); + break; + case STO_ITEM_BREW_PID_DELAY: addr = offsetof(sto_data_t, brewPIDDelaySec); size = STRUCT_MEMBER_SIZE(sto_data_t, brewPIDDelaySec); diff --git a/src/userConfig_sample.h b/src/userConfig_sample.h index 86e883d4..7849f7f5 100644 --- a/src/userConfig_sample.h +++ b/src/userConfig_sample.h @@ -78,11 +78,6 @@ enum MACHINE { #define SCALE_TYPE 0 // 0 = one HX711 per load cell, 1 = Only a single HX711 with two channels #define SCALE_SAMPLES 2 // Load cell sample rate -// Backflush values -#define FILLTIME 5000 // time in ms the pump is running -#define FLUSHTIME 10000 // time in ms the 3-way valve is open -> backflush -#define MAXFLUSHCYCLES 5 // number of cycles the backflush should run, 0 = disabled - // PlatformIO OTA #define OTA true // true = OTA activated, false = OTA deactivated #define OTAPASS "otapass" // Password for OTA updates