Skip to content

Commit

Permalink
move backflush vars into storage
Browse files Browse the repository at this point in the history
also remove all reserver or freeToUse stuff from storage
  • Loading branch information
LoQue90 committed Sep 27, 2024
1 parent 1fabd22 commit e30c35d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 88 deletions.
12 changes: 6 additions & 6 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ void backflush() {
break;

case kBackflushFilling:
if (millis() - startingTime > FILLTIME) {
if (millis() - startingTime > (backflushFillTime * 1000)) {
startingTime = millis();
backflushState = kBackflushFlushingStart;
}
Expand All @@ -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;
}

Expand All @@ -221,7 +221,7 @@ void backflush() {
LOG(INFO, "Backflush: Finished!");
valveRelay.off();
pumpRelay.off();
flushCycles = 0;
currBackflushCycles = 0;
backflushState = kBackflushWaitBrewswitchOn;
}

Expand Down
97 changes: 53 additions & 44 deletions src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/display/displayCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 15 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -264,6 +267,9 @@ SysPara<double> sysParaBrewThresh(&brewSensitivity, BD_THRESHOLD_MIN, BD_THRESHO
SysPara<uint8_t> sysParaWifiCredentialsSaved(&wifiCredentialsSaved, 0, 1, STO_ITEM_WIFI_CREDENTIALS_SAVED);
SysPara<double> sysParaPreInfTime(&preinfusion, PRE_INFUSION_TIME_MIN, PRE_INFUSION_TIME_MAX, STO_ITEM_PRE_INFUSION_TIME);
SysPara<double> sysParaPreInfPause(&preinfusionPause, PRE_INFUSION_PAUSE_MIN, PRE_INFUSION_PAUSE_MAX, STO_ITEM_PRE_INFUSION_PAUSE);
SysPara<uint8_t> sysParaBackflushCycles(&maxBackflushCycles, BACKFLUSH_CYCLES_MIN, BACKFLUSH_CYCLES_MAX, STO_ITEM_BACKFLUSH_CYCLES);
SysPara<double> sysParaBackflushFillTime(&backflushFillTime, BACKFLUSH_FILL_TIME_MIN, BACKFLUSH_FILL_TIME_MAX, STO_ITEM_BACKFLUSH_FILL_TIME);
SysPara<double> sysParaBackflushFlushTime(&backflushFlushTime, BACKFLUSH_FLUSH_TIME_MIN, BACKFLUSH_FLUSH_TIME_MAX, STO_ITEM_BACKFLUSH_FLUSH_TIME);
SysPara<double> sysParaPidKpSteam(&steamKp, PID_KP_STEAM_MIN, PID_KP_STEAM_MAX, STO_ITEM_PID_KP_STEAM);
SysPara<double> sysParaSteamSetpoint(&steamSetpoint, STEAM_SETPOINT_MIN, STEAM_SETPOINT_MAX, STO_ITEM_STEAM_SETPOINT);
SysPara<double> sysParaWeightSetpoint(&weightSetpoint, WEIGHTSETPOINT_MIN, WEIGHTSETPOINT_MAX, STO_ITEM_WEIGHTSETPOINT);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e30c35d

Please sign in to comment.