diff --git a/src/brewHandler.h b/src/brewHandler.h index cd586e0e..316a1196 100644 --- a/src/brewHandler.h +++ b/src/brewHandler.h @@ -51,7 +51,7 @@ double timeBrewed = 0; // total brewed time double lastBrewTimeMillis = 0; // for shottimer delay after disarmed button double lastBrewTime = 0; unsigned long startingTime = 0; // start time of brew -boolean brewPIDDisabled = false; // is PID disabled for delay after brew has started? +boolean pidBrewDisabled = false; // is PID disabled for delay after brew has started? // Shot timer with or without scale #if FEATURE_SCALE == 1 diff --git a/src/defaults.h b/src/defaults.h index 86ef035c..381c1d0a 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -20,37 +20,31 @@ int writeSysParamsToStorage(void); #define STR(x) STR_HELPER(x) // default parameters -#define SETPOINT 95 // brew temperature setpoint -#define TEMPOFFSET 0 // brew temperature setpoint -#define STEAMSETPOINT 120 // steam temperature setpoint -#define SCALE_CALIBRATION_FACTOR 1.00 // Raw data is divided by this value to convert to readable data -#define SCALE2_CALIBRATION_FACTOR 1.00 // Raw data is divided by this value to convert to readable data -#define SCALE_KNOWN_WEIGHT 267.00 // Calibration weight for scale (weight of the tray) #define AGGKP 62 // PID Kp (regular phase) #define AGGTN 52 // PID Tn (regular phase) #define AGGTV 11.5 // PID Tv (regular phase) #define AGGIMAX 55 // PID Integrator Max (regular phase) -#define STARTKP 45 // PID Kp (coldstart phase) -#define STARTTN 130 // PID Tn (coldstart phase) #define STEAMKP 150 // PID kp (steam phase) #define AGGBKP 50 // PID Kp (brew detection phase) #define AGGBTN 0 // PID Tn (brew detection phase) #define AGGBTV 20 // PID Tv (brew detection phase) -#define BREW_TIME 25 // brew time in seconds (only used if pump is being controlled) -#define BREW_SW_TIME 25 // keep brew PID params for this many seconds after detection (only for software BD) -#define BREW_PID_DELAY 10 // delay until enabling PID controller during brew (no heating during this time) +#define PID_BREW_DELAY 10 // delay until enabling PID controller during brew (no heating during this time) #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 BREW_SW_TIME 25 // keep brew PID params for this many seconds after detection (only for software BD) +#define BREWTEMPOFFSET 0 // brew temperature setpoint +#define SETPOINT 95 // brew temperature setpoint +#define STEAMSETPOINT 120 // steam temperature setpoint +#define BREW_TIME 25 // brew time in seconds (only used if pump is being controlled) #define PRE_INFUSION_TIME 2 // pre-infusion time in seconds #define PRE_INFUSION_PAUSE_TIME 5 // pre-infusion pause time in seconds #define SCALE_WEIGHTSETPOINT 30 // Target weight in grams +#define SCALE_CALIBRATION_FACTOR 1.00 // Raw data is divided by this value to convert to readable data +#define SCALE2_CALIBRATION_FACTOR 1.00 // Raw data is divided by this value to convert to readable data +#define SCALE_KNOWN_WEIGHT 267.00 // Calibration weight for scale (weight of the tray) #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 @@ -59,35 +53,33 @@ int writeSysParamsToStorage(void); #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 PID_KP_STEAM_MIN 0 +#define PID_KP_STEAM_MAX 500 +#define PID_KP_BREW_MIN 0 +#define PID_KP_BREW_MAX 999 +#define PID_TN_BREW_MIN 0 +#define PID_TN_BREW_MAX 999 +#define PID_TV_BREW_MIN 0 +#define PID_TV_BREW_MAX 999 +#define PID_BREW_DELAY_MIN 0 +#define PID_BREW_DELAY_MAX 60 +#define BD_THRESHOLD_MIN 0 +#define BD_THRESHOLD_MAX 999 +#define BREW_SW_TIME_MIN 1 +#define BREW_SW_TIME_MAX 180 +#define BREW_TEMP_OFFSET_MIN 0 +#define BREW_TEMP_OFFSET_MAX 20 #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 diff --git a/src/embeddedWebserver.h b/src/embeddedWebserver.h index 9db4542d..014c045a 100644 --- a/src/embeddedWebserver.h +++ b/src/embeddedWebserver.h @@ -58,7 +58,7 @@ void serverSetup(); void setEepromWriteFcn(int (*fcnPtr)(void)); // editable vars are specified in main.cpp -#define EDITABLE_VARS_LEN 33 +#define EDITABLE_VARS_LEN 31 extern std::map editableVars; // EEPROM @@ -245,7 +245,7 @@ void serverSetup() { // set up dynamic routes (endpoints) server.on("/toggleSteam", HTTP_POST, [](AsyncWebServerRequest* request) { - int steam = flipUintValue(steamON); + int steam = flipUintValue(steamOn); setSteamMode(steam); LOGF(DEBUG, "Toggle steam mode: %i", steam); @@ -255,7 +255,7 @@ void serverSetup() { server.on("/togglePid", HTTP_POST, [](AsyncWebServerRequest* request) { LOGF(DEBUG, "/togglePid requested, method: %d", request->method()); - int status = flipUintValue(pidON); + int status = flipUintValue(pidOn); setPidStatus(status); LOGF(DEBUG, "Toggle PID state: %d\n", status); diff --git a/src/main.cpp b/src/main.cpp index 6efc0cba..0a21b686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,7 +180,7 @@ void setBackflush(int backflush); void setScaleTare(int tare); void setScaleCalibration(int tare); void setNormalPIDTunings(); -void setBDPIDTunings(); +void setBrewPidTunings(); void loopcalibrate(); void looppid(); void loopLED(); @@ -199,18 +199,16 @@ void updateStandbyTimer(void); void resetStandbyTimer(void); // system parameters -uint8_t pidON = 0; // 1 = control loop in closed loop +uint8_t pidOn = 0; // 1 = control loop in closed loop double brewSetpoint = SETPOINT; -double brewTempOffset = TEMPOFFSET; +double brewTempOffset = BREWTEMPOFFSET; double setpoint = brewSetpoint; double steamSetpoint = STEAMSETPOINT; float scaleCalibration = SCALE_CALIBRATION_FACTOR; float scale2Calibration = SCALE_CALIBRATION_FACTOR; float scaleKnownWeight = SCALE_KNOWN_WEIGHT; -uint8_t usePonM = 0; // 1 = use PonM for cold start PID, 0 = use normal PID for cold start +uint8_t pidPonmOn = 0; // 1 = use PonM; PID, 0 = use normal PID double steamKp = STEAMKP; -double startKp = STARTKP; -double startTn = STARTTN; double aggKp = AGGKP; double aggTn = AGGTN; double aggTv = AGGTV; @@ -221,7 +219,7 @@ double preinfusionPause = PRE_INFUSION_PAUSE_TIME; // preinfusion pause time in double weightSetpoint = SCALE_WEIGHTSETPOINT; // PID - values for offline brew detection -uint8_t useBDPID = 0; +uint8_t pidBrewOn = 0; double aggbKp = AGGBKP; double aggbTn = AGGBTN; double aggbTv = AGGBTV; @@ -235,7 +233,7 @@ double aggbKi = aggbKp / aggbTn; double aggbKd = aggbTv * aggbKp; double brewtimesoftware = BREW_SW_TIME; // use userConfig time until disabling BD PID double brewSensitivity = BD_SENSITIVITY; // use userConfig brew detection sensitivity -double brewPIDDelay = BREW_PID_DELAY; // use userConfig brew detection PID delay +double pidBrewDelay = PID_BREW_DELAY; // use userConfig brew detection PID delay uint8_t standbyModeOn = 0; double standbyModeTime = STANDBY_MODE_TIME; @@ -243,35 +241,33 @@ double standbyModeTime = STANDBY_MODE_TIME; #include "standby.h" // system parameter EEPROM storage wrappers (current value as pointer to variable, minimum, maximum, optional storage ID) -SysPara sysParaPidOn(&pidON, 0, 1, STO_ITEM_PID_ON); -SysPara sysParaUsePonM(&usePonM, 0, 1, STO_ITEM_PID_START_PONM); -SysPara sysParaPidKpStart(&startKp, PID_KP_START_MIN, PID_KP_START_MAX, STO_ITEM_PID_KP_START); -SysPara sysParaPidTnStart(&startTn, PID_TN_START_MIN, PID_TN_START_MAX, STO_ITEM_PID_TN_START); +SysPara sysParaPidOn(&pidOn, 0, 1, STO_ITEM_PID_ON); +SysPara sysParaPidPonmOn(&pidPonmOn, 0, 1, STO_ITEM_PID_PONM_ON); SysPara sysParaPidKpReg(&aggKp, PID_KP_REGULAR_MIN, PID_KP_REGULAR_MAX, STO_ITEM_PID_KP_REGULAR); SysPara sysParaPidTnReg(&aggTn, PID_TN_REGULAR_MIN, PID_TN_REGULAR_MAX, STO_ITEM_PID_TN_REGULAR); SysPara sysParaPidTvReg(&aggTv, PID_TV_REGULAR_MIN, PID_TV_REGULAR_MAX, STO_ITEM_PID_TV_REGULAR); SysPara sysParaPidIMaxReg(&aggIMax, PID_I_MAX_REGULAR_MIN, PID_I_MAX_REGULAR_MAX, STO_ITEM_PID_I_MAX_REGULAR); -SysPara sysParaPidKpBd(&aggbKp, PID_KP_BD_MIN, PID_KP_BD_MAX, STO_ITEM_PID_KP_BD); -SysPara sysParaPidTnBd(&aggbTn, PID_TN_BD_MIN, PID_KP_BD_MAX, STO_ITEM_PID_TN_BD); -SysPara sysParaPidTvBd(&aggbTv, PID_TV_BD_MIN, PID_TV_BD_MAX, STO_ITEM_PID_TV_BD); -SysPara sysParaBrewSetpoint(&brewSetpoint, BREW_SETPOINT_MIN, BREW_SETPOINT_MAX, STO_ITEM_BREW_SETPOINT); -SysPara sysParaTempOffset(&brewTempOffset, BREW_TEMP_OFFSET_MIN, BREW_TEMP_OFFSET_MAX, STO_ITEM_BREW_TEMP_OFFSET); -SysPara sysParaBrewPIDDelay(&brewPIDDelay, BREW_PID_DELAY_MIN, BREW_PID_DELAY_MAX, STO_ITEM_BREW_PID_DELAY); -SysPara sysParaUseBDPID(&useBDPID, 0, 1, STO_ITEM_USE_BD_PID); -SysPara sysParaBrewTime(&brewTime, BREW_TIME_MIN, BREW_TIME_MAX, STO_ITEM_BREW_TIME); +SysPara sysParaPidKpSteam(&steamKp, PID_KP_STEAM_MIN, PID_KP_STEAM_MAX, STO_ITEM_PID_KP_STEAM); +SysPara sysParaPidBrewOn(&pidBrewOn, 0, 1, STO_ITEM_PID_BREW_ON); +SysPara sysParaPidKpBrew(&aggbKp, PID_KP_BREW_MIN, PID_KP_BREW_MAX, STO_ITEM_PID_KP_BREW); +SysPara sysParaPidTnBrew(&aggbTn, PID_TN_BREW_MIN, PID_KP_BREW_MAX, STO_ITEM_PID_TN_BREW); +SysPara sysParaPidTvBrew(&aggbTv, PID_TV_BREW_MIN, PID_TV_BREW_MAX, STO_ITEM_PID_TV_BREW); +SysPara sysParaPidBrewDelay(&pidBrewDelay, PID_BREW_DELAY_MIN, PID_BREW_DELAY_MAX, STO_ITEM_PID_BREW_DELAY); SysPara sysParaBrewSwTime(&brewtimesoftware, BREW_SW_TIME_MIN, BREW_SW_TIME_MAX, STO_ITEM_BREW_SW_TIME); SysPara sysParaBrewThresh(&brewSensitivity, BD_THRESHOLD_MIN, BD_THRESHOLD_MAX, STO_ITEM_BD_THRESHOLD); -SysPara sysParaWifiCredentialsSaved(&wifiCredentialsSaved, 0, 1, STO_ITEM_WIFI_CREDENTIALS_SAVED); +SysPara sysParaBrewTempOffset(&brewTempOffset, BREW_TEMP_OFFSET_MIN, BREW_TEMP_OFFSET_MAX, STO_ITEM_BREW_TEMP_OFFSET); +SysPara sysParaBrewSetpoint(&brewSetpoint, BREW_SETPOINT_MIN, BREW_SETPOINT_MAX, STO_ITEM_BREW_SETPOINT); +SysPara sysParaSteamSetpoint(&steamSetpoint, STEAM_SETPOINT_MIN, STEAM_SETPOINT_MAX, STO_ITEM_STEAM_SETPOINT); +SysPara sysParaBrewTime(&brewTime, BREW_TIME_MIN, BREW_TIME_MAX, STO_ITEM_BREW_TIME); 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 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); -SysPara sysParaStandbyModeOn(&standbyModeOn, 0, 1, STO_ITEM_STANDBY_MODE_ON); -SysPara sysParaStandbyModeTime(&standbyModeTime, STANDBY_MODE_TIME_MIN, STANDBY_MODE_TIME_MAX, STO_ITEM_STANDBY_MODE_TIME); SysPara sysParaScaleCalibration(&scaleCalibration, -100000, 100000, STO_ITEM_SCALE_CALIBRATION_FACTOR); SysPara sysParaScale2Calibration(&scale2Calibration, -100000, 100000, STO_ITEM_SCALE2_CALIBRATION_FACTOR); SysPara sysParaScaleKnownWeight(&scaleKnownWeight, 0, 2000, STO_ITEM_SCALE_KNOWN_WEIGHT); +SysPara sysParaWifiCredentialsSaved(&wifiCredentialsSaved, 0, 1, STO_ITEM_WIFI_CREDENTIALS_SAVED); +SysPara sysParaStandbyModeOn(&standbyModeOn, 0, 1, STO_ITEM_STANDBY_MODE_ON); +SysPara sysParaStandbyModeTime(&standbyModeTime, STANDBY_MODE_TIME_MIN, STANDBY_MODE_TIME_MAX, STO_ITEM_STANDBY_MODE_TIME); // Other variables boolean emergencyStop = false; // Emergency stop if temperature is too high @@ -281,7 +277,6 @@ 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 @@ -302,14 +297,8 @@ double previousInput = 0; // Variables to hold PID values (Temp input, Heater output) double temperature, pidOutput; -int steamON = 0; -int steamFirstON = 0; - -#if startTn == 0 -double startKi = 0; -#else -double startKi = startKp / startTn; -#endif +int steamOn = 0; +int steamFirstOn = 0; #if aggTn == 0 double aggKi = 0; @@ -682,7 +671,7 @@ void initSteamQM() { lastTimeOptocouplerOn = millis(); // time when optocoupler changes from ON to OFF steamQM_active = true; timeOptocouplerOn = 0; - steamON = 1; + steamOn = 1; } boolean checkSteamOffQM() { @@ -717,7 +706,7 @@ void handleMachineState() { machineState = kSensorError; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } else { @@ -737,7 +726,7 @@ void handleMachineState() { } } - if (steamON == 1) { + if (steamOn == 1) { machineState = kSteam; if (standbyModeOn) { @@ -759,10 +748,10 @@ void handleMachineState() { if (standbyModeOn && standbyModeRemainingTimeMillis == 0) { machineState = kStandby; - pidON = 0; + pidOn = 0; } - if (pidON == 0 && machineState != kStandby) { + if (pidOn == 0 && machineState != kStandby) { machineState = kPidDisabled; } @@ -796,7 +785,7 @@ void handleMachineState() { machineState = kBrewDetectionTrailing; } - if (steamON == 1) { + if (steamOn == 1) { machineState = kSteam; } @@ -804,7 +793,7 @@ void handleMachineState() { machineState = kEmergencyStop; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -821,7 +810,7 @@ void handleMachineState() { machineState = kBrewDetectionTrailing; } - if (steamON == 1) { + if (steamOn == 1) { machineState = kSteam; } @@ -833,7 +822,7 @@ void handleMachineState() { machineState = kEmergencyStop; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -858,7 +847,7 @@ void handleMachineState() { machineState = kBrew; } - if (steamON == 1) { + if (steamOn == 1) { machineState = kSteam; } @@ -870,7 +859,7 @@ void handleMachineState() { machineState = kEmergencyStop; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -884,7 +873,7 @@ void handleMachineState() { break; case kSteam: - if (steamON == 0) { + if (steamOn == 0) { machineState = kPidNormal; } @@ -896,7 +885,7 @@ void handleMachineState() { machineState = kBackflush; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -918,7 +907,7 @@ void handleMachineState() { machineState = kEmergencyStop; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -936,7 +925,7 @@ void handleMachineState() { machineState = kPidNormal; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -950,7 +939,7 @@ void handleMachineState() { machineState = kPidNormal; } - if (pidON == 0) { + if (pidOn == 0) { machineState = kPidDisabled; } @@ -960,7 +949,7 @@ void handleMachineState() { break; case kPidDisabled: - if (pidON == 1) { + if (pidOn == 1) { // Enter regular PID operations machineState = kPidNormal; } @@ -984,14 +973,14 @@ void handleMachineState() { brewDetection(); - if (pidON || steamON || isBrewDetected) { - pidON = 1; + if (pidOn || steamOn || isBrewDetected) { + pidOn = 1; resetStandbyTimer(); #if OLED_DISPLAY != 0 u8g2.setPowerSave(0); #endif - if (steamON) { + if (steamOn) { machineState = kSteam; } else if (isBrewDetected) { @@ -1138,49 +1127,21 @@ void setup() { Logger::init(23); editableVars["PID_ON"] = { - .displayName = "Enable PID Controller", .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sPIDSection, .position = 1, .show = [] { return true; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&pidON}; - - editableVars["START_USE_PONM"] = {.displayName = F("Enable PonM"), - .hasHelpText = true, - .helpText = F("Use PonM mode (details) while heating up the machine. " - "Otherwise, just use the same PID values that are used later"), - .type = kUInt8, - .section = sPIDSection, - .position = 2, - .show = [] { return true; }, - .minValue = 0, - .maxValue = 1, - .ptr = (void*)&usePonM}; + .displayName = "Enable PID Controller", .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sPIDSection, .position = 1, .show = [] { return true; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&pidOn}; - editableVars["START_KP"] = {.displayName = F("Start Kp"), - .hasHelpText = true, - .helpText = F("Proportional gain for cold start controller. This value is not " - "used with the the error as usual but the absolute value of the " - "temperature and counteracts the integral part as the temperature " - "rises. Ideally, both parameters are set so that they balance each " - "other out when the target temperature is reached."), - .type = kDouble, - .section = sPIDSection, - .position = 3, - .show = [] { return true && usePonM; }, - .minValue = PID_KP_START_MIN, - .maxValue = PID_KP_START_MAX, - .ptr = (void*)&startKp}; - - editableVars["START_TN"] = {.displayName = F("Start Tn"), - .hasHelpText = true, - .helpText = F("Integral gain for cold start controller (PonM mode, details)"), - .type = kDouble, - .section = sPIDSection, - .position = 4, - .show = [] { return true && usePonM; }, - .minValue = PID_TN_START_MIN, - .maxValue = PID_TN_START_MAX, - .ptr = (void*)&startTn}; + editableVars["PID_PONM_ON"] = {.displayName = F("Enable PonM"), + .hasHelpText = true, + .helpText = F("Use PonM mode (details) while heating up the machine. " + "Otherwise, just use the same PID values that are used later"), + .type = kUInt8, + .section = sPIDSection, + .position = 2, + .show = [] { return true; }, + .minValue = 0, + .maxValue = 1, + .ptr = (void*)&pidPonmOn}; editableVars["PID_KP"] = {.displayName = F("PID Kp"), .hasHelpText = true, @@ -1191,7 +1152,7 @@ void setup() { "difference. E.g. 5°C difference will result in P*5 Watts of heater output."), .type = kDouble, .section = sPIDSection, - .position = 5, + .position = 3, .show = [] { return true; }, .minValue = PID_KP_REGULAR_MIN, .maxValue = PID_KP_REGULAR_MAX, @@ -1207,7 +1168,7 @@ void setup() { "proportional action. The smaller this value, the faster the integral term changes."), .type = kDouble, .section = sPIDSection, - .position = 6, + .position = 4, .show = [] { return true; }, .minValue = PID_TN_REGULAR_MIN, .maxValue = PID_TN_REGULAR_MAX, @@ -1222,7 +1183,7 @@ void setup() { "if it is set too high or too low."), .type = kDouble, .section = sPIDSection, - .position = 7, + .position = 5, .show = [] { return true; }, .minValue = PID_TV_REGULAR_MIN, .maxValue = PID_TV_REGULAR_MAX, @@ -1235,7 +1196,7 @@ void setup() { "setpoint has been reached and is depending on machine type and whether the boiler is insulated or not."), .type = kDouble, .section = sPIDSection, - .position = 8, + .position = 6, .show = [] { return true; }, .minValue = PID_I_MAX_REGULAR_MIN, .maxValue = PID_I_MAX_REGULAR_MAX, @@ -1246,35 +1207,16 @@ void setup() { .helpText = F("Proportional gain for the steaming mode (I or D are not used)"), .type = kDouble, .section = sPIDSection, - .position = 9, + .position = 7, .show = [] { return true; }, .minValue = PID_KP_STEAM_MIN, .maxValue = PID_KP_STEAM_MAX, .ptr = (void*)&steamKp}; - editableVars["TEMP"] = {.displayName = F("Temperature"), - .hasHelpText = false, - .helpText = "", - .type = kDouble, - .section = sPIDSection, - .position = 10, - .show = [] { return false; }, - .minValue = 0, - .maxValue = 200, - .ptr = (void*)&temperature}; - - editableVars["BREW_SETPOINT"] = {.displayName = F("Set point (°C)"), - .hasHelpText = true, - .helpText = F("The temperature that the PID will attempt to reach and hold"), - .type = kDouble, - .section = sTempSection, - .position = 11, - .show = [] { return true; }, - .minValue = BREW_SETPOINT_MIN, - .maxValue = BREW_SETPOINT_MAX, - .ptr = (void*)&brewSetpoint}; + editableVars["TEMP"] = { + .displayName = F("Temperature"), .hasHelpText = false, .helpText = "", .type = kDouble, .section = sPIDSection, .position = 8, .show = [] { return false; }, .minValue = 0, .maxValue = 200, .ptr = (void*)&temperature}; - editableVars["BREW_TEMP_OFFSET"] = {.displayName = F("Offset (°C)"), + editableVars["BREW_TEMP_OFFSET"] = {.displayName = F("Brew Temp Offset (°C)"), .hasHelpText = true, .helpText = F("Optional offset that is added to the user-visible " "setpoint. Can be used to compensate sensor offsets and " @@ -1282,18 +1224,29 @@ void setup() { "so that the setpoint represents the approximate brew temperature."), .type = kDouble, .section = sTempSection, - .position = 12, + .position = 9, .show = [] { return true; }, .minValue = BREW_TEMP_OFFSET_MIN, .maxValue = BREW_TEMP_OFFSET_MAX, .ptr = (void*)&brewTempOffset}; + editableVars["BREW_SETPOINT"] = {.displayName = F("Set point (°C)"), + .hasHelpText = true, + .helpText = F("The temperature that the PID will attempt to reach and hold"), + .type = kDouble, + .section = sTempSection, + .position = 10, + .show = [] { return true; }, + .minValue = BREW_SETPOINT_MIN, + .maxValue = BREW_SETPOINT_MAX, + .ptr = (void*)&brewSetpoint}; + editableVars["STEAM_SETPOINT"] = {.displayName = F("Steam Set point (°C)"), .hasHelpText = true, .helpText = F("The temperature that the PID will use for steam mode"), .type = kDouble, .section = sTempSection, - .position = 13, + .position = 11, .show = [] { return true; }, .minValue = STEAM_SETPOINT_MIN, .maxValue = STEAM_SETPOINT_MAX, @@ -1304,120 +1257,120 @@ void setup() { .helpText = F("Stop brew after this time. Set to 0 to deactivate brew-by-time-feature."), .type = kDouble, .section = sBrewSection, - .position = 14, + .position = 12, .show = [] { return true && FEATURE_BREWCONTROL == 1; }, .minValue = BREW_TIME_MIN, .maxValue = BREW_TIME_MAX, .ptr = (void*)&brewTime}; - editableVars["BREW_PREINFUSIONPAUSE"] = {.displayName = F("Preinfusion Pause Time (s)"), - .hasHelpText = false, - .helpText = "", - .type = kDouble, - .section = sBrewSection, - .position = 15, - .show = [] { return true && FEATURE_BREWCONTROL == 1; }, - .minValue = PRE_INFUSION_PAUSE_MIN, - .maxValue = PRE_INFUSION_PAUSE_MAX, - .ptr = (void*)&preinfusionPause}; - editableVars["BREW_PREINFUSION"] = {.displayName = F("Preinfusion Time (s)"), .hasHelpText = false, .helpText = "", .type = kDouble, .section = sBrewSection, - .position = 16, + .position = 13, .show = [] { return true && FEATURE_BREWCONTROL == 1; }, .minValue = PRE_INFUSION_TIME_MIN, .maxValue = PRE_INFUSION_TIME_MAX, .ptr = (void*)&preinfusion}; + editableVars["BREW_PREINFUSIONPAUSE"] = {.displayName = F("Preinfusion Pause Time (s)"), + .hasHelpText = false, + .helpText = "", + .type = kDouble, + .section = sBrewSection, + .position = 14, + .show = [] { return true && FEATURE_BREWCONTROL == 1; }, + .minValue = PRE_INFUSION_PAUSE_MIN, + .maxValue = PRE_INFUSION_PAUSE_MAX, + .ptr = (void*)&preinfusionPause}; + editableVars["SCALE_WEIGHTSETPOINT"] = {.displayName = F("Brew weight setpoint (g)"), .hasHelpText = true, .helpText = F("Brew is running until this weight has been measured. Set to 0 to deactivate brew-by-weight-feature."), .type = kDouble, .section = sBrewSection, - .position = 17, + .position = 15, .show = [] { return true && FEATURE_SCALE == 1; }, .minValue = WEIGHTSETPOINT_MIN, .maxValue = WEIGHTSETPOINT_MAX, .ptr = (void*)&weightSetpoint}; - editableVars["PID_BD_DELAY"] = {.displayName = F("Brew PID Delay (s)"), - .hasHelpText = true, - .helpText = F("Delay time in seconds during which the PID will be " - "disabled once a brew is detected. This prevents too " - "high brew temperatures with boiler machines like Rancilio " - "Silvia. Set to 0 for thermoblock machines."), - .type = kDouble, - .section = sBDSection, - .position = 18, - .show = [] { return true; }, - .minValue = BREW_PID_DELAY_MIN, - .maxValue = BREW_PID_DELAY_MAX, - .ptr = (void*)&brewPIDDelay}; - - editableVars["PID_BD_ON"] = {.displayName = F("Enable Brew PID"), - .hasHelpText = true, - .helpText = F("Use separate PID parameters while brew is running"), - .type = kUInt8, - .section = sBDSection, - .position = 19, - .show = [] { return true && FEATURE_BREWDETECTION == 1; }, - .minValue = 0, - .maxValue = 1, - .ptr = (void*)&useBDPID}; - - editableVars["PID_BD_KP"] = {.displayName = F("BD Kp"), - .hasHelpText = true, - .helpText = F("Proportional gain (in Watts/°C) for the PID when brewing has been " - "detected. Use this controller to either increase heating during the " - "brew to counter temperature drop from fresh cold water in the boiler. " - "Some machines, e.g. Rancilio Silvia, actually need to heat less or not " - "at all during the brew because of high temperature stability " - "(Details)"), - .type = kDouble, - .section = sBDSection, - .position = 20, - .show = [] { return true && FEATURE_BREWDETECTION == 1 && useBDPID; }, - .minValue = PID_KP_BD_MIN, - .maxValue = PID_KP_BD_MAX, - .ptr = (void*)&aggbKp}; - - editableVars["PID_BD_TN"] = {.displayName = F("BD Tn (=Kp/Ki)"), - .hasHelpText = true, - .helpText = F("Integral time constant (in seconds) for the PID when " - "brewing has been detected."), - .type = kDouble, - .section = sBDSection, - .position = 21, - .show = [] { return true && FEATURE_BREWDETECTION == 1 && useBDPID; }, - .minValue = PID_TN_BD_MIN, - .maxValue = PID_TN_BD_MAX, - .ptr = (void*)&aggbTn}; - - editableVars["PID_BD_TV"] = {.displayName = F("BD Tv (=Kd/Kp)"), - .hasHelpText = true, - .helpText = F("Differential time constant (in seconds) for the PID " - "when brewing has been detected."), - .type = kDouble, - .section = sBDSection, - .position = 22, - .show = [] { return true && FEATURE_BREWDETECTION == 1 && useBDPID; }, - .minValue = PID_TV_BD_MIN, - .maxValue = PID_TV_BD_MAX, - .ptr = (void*)&aggbTv}; + editableVars["PID_BREW_DELAY"] = {.displayName = F("PID Brew Delay (s)"), + .hasHelpText = true, + .helpText = F("Delay time in seconds during which the PID will be " + "disabled once a brew is detected. This prevents too " + "high brew temperatures with boiler machines like Rancilio " + "Silvia. Set to 0 for thermoblock machines."), + .type = kDouble, + .section = sBDSection, + .position = 16, + .show = [] { return true; }, + .minValue = PID_BREW_DELAY_MIN, + .maxValue = PID_BREW_DELAY_MAX, + .ptr = (void*)&pidBrewDelay}; + + editableVars["PID_BREW_ON"] = {.displayName = F("Enable Brew PID"), + .hasHelpText = true, + .helpText = F("Use separate PID parameters while brew is running"), + .type = kUInt8, + .section = sBDSection, + .position = 17, + .show = [] { return true && FEATURE_BREWDETECTION == 1; }, + .minValue = 0, + .maxValue = 1, + .ptr = (void*)&pidBrewOn}; + + editableVars["PID_BREW_KP"] = {.displayName = F("PID Brew Kp"), + .hasHelpText = true, + .helpText = F("Proportional gain (in Watts/°C) for the PID when brewing has been " + "detected. Use this controller to either increase heating during the " + "brew to counter temperature drop from fresh cold water in the boiler. " + "Some machines, e.g. Rancilio Silvia, actually need to heat less or not " + "at all during the brew because of high temperature stability " + "(Details)"), + .type = kDouble, + .section = sBDSection, + .position = 18, + .show = [] { return true && FEATURE_BREWDETECTION == 1 && pidBrewOn; }, + .minValue = PID_KP_BREW_MIN, + .maxValue = PID_KP_BREW_MAX, + .ptr = (void*)&aggbKp}; + + editableVars["PID_BREW_TN"] = {.displayName = F("PID Brew Tn (=Kp/Ki)"), + .hasHelpText = true, + .helpText = F("Integral time constant (in seconds) for the PID when " + "brewing has been detected."), + .type = kDouble, + .section = sBDSection, + .position = 19, + .show = [] { return true && FEATURE_BREWDETECTION == 1 && pidBrewOn; }, + .minValue = PID_TN_BREW_MIN, + .maxValue = PID_TN_BREW_MAX, + .ptr = (void*)&aggbTn}; + + editableVars["PID_BREW_TV"] = {.displayName = F("PID Brew Tv (=Kd/Kp)"), + .hasHelpText = true, + .helpText = F("Differential time constant (in seconds) for the PID " + "when brewing has been detected."), + .type = kDouble, + .section = sBDSection, + .position = 20, + .show = [] { return true && FEATURE_BREWDETECTION == 1 && pidBrewOn; }, + .minValue = PID_TV_BREW_MIN, + .maxValue = PID_TV_BREW_MAX, + .ptr = (void*)&aggbTv}; editableVars["PID_BD_TIME"] = {.displayName = F("PID BD Time (s)"), .hasHelpText = true, - .helpText = F("Fixed time in seconds for which the BD PID will stay " + .helpText = F("Fixed time in seconds for which the BREW PID will stay " "enabled (also after Brew switch is inactive again)."), .type = kDouble, .section = sBDSection, - .position = 23, - .show = [] { return true && FEATURE_BREWDETECTION == 1 && (useBDPID || BREWDETECTION_TYPE == 1); }, + .position = 21, + .show = [] { return true && FEATURE_BREWDETECTION == 1 && (pidBrewOn || BREWDETECTION_TYPE == 1); }, .minValue = BREW_SW_TIME_MIN, .maxValue = BREW_SW_TIME_MAX, .ptr = (void*)&brewtimesoftware}; @@ -1430,24 +1383,24 @@ void setup() { "Needs to be >0 also for Hardware switch detection."), .type = kDouble, .section = sBDSection, - .position = 24, + .position = 22, .show = [] { return true && BREWDETECTION_TYPE == 1; }, .minValue = BD_THRESHOLD_MIN, .maxValue = BD_THRESHOLD_MAX, .ptr = (void*)&brewSensitivity}; editableVars["STEAM_MODE"] = { - .displayName = F("Steam Mode"), .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sOtherSection, .position = 25, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&steamON}; + .displayName = F("Steam Mode"), .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sOtherSection, .position = 23, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&steamOn}; editableVars["BACKFLUSH_ON"] = { - .displayName = F("Backflush"), .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sOtherSection, .position = 26, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&backflushOn}; + .displayName = F("Backflush"), .hasHelpText = false, .helpText = "", .type = kUInt8, .section = sOtherSection, .position = 24, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)&backflushOn}; editableVars["STANDBY_MODE_ON"] = {.displayName = F("Enable Standby Timer"), .hasHelpText = true, .helpText = F("Turn heater off after standby time has elapsed."), .type = kUInt8, .section = sPowerSection, - .position = 27, + .position = 25, .show = [] { return true; }, .minValue = 0, .maxValue = 1, @@ -1458,7 +1411,7 @@ void setup() { .helpText = F("Time in minutes until the heater is turned off. Timer is reset by brew detection."), .type = kDouble, .section = sPowerSection, - .position = 28, + .position = 26, .show = [] { return true; }, .minValue = STANDBY_MODE_TIME_MIN, .maxValue = STANDBY_MODE_TIME_MAX, @@ -1473,7 +1426,7 @@ void setup() { .helpText = "", .type = kUInt8, .section = sScaleSection, - .position = 30, + .position = 27, .show = [] { return false; }, .minValue = 0, .maxValue = 1, @@ -1484,7 +1437,7 @@ void setup() { .helpText = "", .type = kFloat, .section = sScaleSection, - .position = 31, + .position = 28, .show = [] { return true; }, .minValue = 0, .maxValue = 2000, @@ -1495,7 +1448,7 @@ void setup() { .helpText = "", .type = kFloat, .section = sScaleSection, - .position = 32, + .position = 29, .show = [] { return true; }, .minValue = -100000, .maxValue = 100000, @@ -1506,7 +1459,7 @@ void setup() { .helpText = "", .type = kFloat, .section = sScaleSection, - .position = 32, + .position = 30, .show = [] { return SCALE_TYPE == 0; }, .minValue = -100000, .maxValue = 100000, @@ -1514,7 +1467,7 @@ void setup() { #endif editableVars["VERSION"] = { - .displayName = F("Version"), .hasHelpText = false, .helpText = "", .type = kCString, .section = sOtherSection, .position = 33, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)sysVersion}; + .displayName = F("Version"), .hasHelpText = false, .helpText = "", .type = kCString, .section = sOtherSection, .position = 31, .show = [] { return false; }, .minValue = 0, .maxValue = 1, .ptr = (void*)sysVersion}; // when adding parameters, set EDITABLE_VARS_LEN to max of .position #if (FEATURE_PRESSURESENSOR == 1) @@ -1522,21 +1475,19 @@ void setup() { #endif // Editable values reported to MQTT - mqttVars["pidON"] = [] { return &editableVars.at("PID_ON"); }; - mqttVars["brewSetpoint"] = [] { return &editableVars.at("BREW_SETPOINT"); }; - mqttVars["brewTempOffset"] = [] { return &editableVars.at("BREW_TEMP_OFFSET"); }; - mqttVars["steamON"] = [] { return &editableVars.at("STEAM_MODE"); }; - mqttVars["steamSetpoint"] = [] { return &editableVars.at("STEAM_SETPOINT"); }; - mqttVars["brewPidDelay"] = [] { return &editableVars.at("PID_BD_DELAY"); }; - mqttVars["backflushOn"] = [] { return &editableVars.at("BACKFLUSH_ON"); }; - mqttVars["startUsePonM"] = [] { return &editableVars.at("START_USE_PONM"); }; - mqttVars["startKp"] = [] { return &editableVars.at("START_KP"); }; - mqttVars["startTn"] = [] { return &editableVars.at("START_TN"); }; + mqttVars["pidOn"] = [] { return &editableVars.at("PID_ON"); }; + mqttVars["pidPonmOn"] = [] { return &editableVars.at("PID_PONM_ON"); }; mqttVars["aggKp"] = [] { return &editableVars.at("PID_KP"); }; mqttVars["aggTn"] = [] { return &editableVars.at("PID_TN"); }; mqttVars["aggTv"] = [] { return &editableVars.at("PID_TV"); }; mqttVars["aggIMax"] = [] { return &editableVars.at("PID_I_MAX"); }; mqttVars["steamKp"] = [] { return &editableVars.at("STEAM_KP"); }; + mqttVars["pidBrewDelay"] = [] { return &editableVars.at("PID_BREW_DELAY"); }; + mqttVars["brewTempOffset"] = [] { return &editableVars.at("BREW_TEMP_OFFSET"); }; + mqttVars["brewSetpoint"] = [] { return &editableVars.at("BREW_SETPOINT"); }; + mqttVars["steamOn"] = [] { return &editableVars.at("STEAM_MODE"); }; + mqttVars["steamSetpoint"] = [] { return &editableVars.at("STEAM_SETPOINT"); }; + mqttVars["backflushOn"] = [] { return &editableVars.at("BACKFLUSH_ON"); }; mqttVars["standbyModeOn"] = [] { return &editableVars.at("STANDBY_MODE_ON"); }; if (FEATURE_BREWCONTROL == 1) { @@ -1557,10 +1508,10 @@ void setup() { } if (FEATURE_BREWDETECTION == 1) { - mqttVars["pidUseBD"] = [] { return &editableVars.at("PID_BD_ON"); }; - mqttVars["aggbKp"] = [] { return &editableVars.at("PID_BD_KP"); }; - mqttVars["aggbTn"] = [] { return &editableVars.at("PID_BD_TN"); }; - mqttVars["aggbTv"] = [] { return &editableVars.at("PID_BD_TV"); }; + mqttVars["pidBrewOn"] = [] { return &editableVars.at("PID_BREW_ON"); }; + mqttVars["aggbKp"] = [] { return &editableVars.at("PID_BREW_KP"); }; + mqttVars["aggbTn"] = [] { return &editableVars.at("PID_BREW_TN"); }; + mqttVars["aggbTv"] = [] { return &editableVars.at("PID_BREW_TV"); }; if (BREWDETECTION_TYPE == 1) { mqttVars["brewTimer"] = [] { return &editableVars.at("PID_BD_TIME"); }; @@ -1673,7 +1624,7 @@ void setup() { wm.disconnect(); // no wm readSysParamsFromStorage(); // get all parameters from storage offlineMode = 1; // offline mode - pidON = 1; // pid on + pidOn = 1; // pid on } // Start the logger @@ -1797,7 +1748,7 @@ void looppid() { sendTempEvent(temperature, brewSetpoint, pidOutput / 10); // pidOutput is promill, so /10 to get percent value lastTempEvent = millis(); - if (pidON) { + if (pidOn) { LOGF(TRACE, "Current PID mode: %s", bPID.GetPonE() ? "PonE" : "PonM"); // P-Part @@ -1845,10 +1796,10 @@ void looppid() { checkPowerSwitch(); // set setpoint depending on steam or brew mode - if (steamON == 1) { + if (steamOn == 1) { setpoint = steamSetpoint; } - else if (steamON == 0) { + else if (steamOn == 0) { setpoint = brewSetpoint; } @@ -1861,7 +1812,7 @@ void looppid() { printDisplayTimer(); #endif - if (machineState == kPidDisabled || machineState == kWaterEmpty || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || brewPIDDisabled) { + if (machineState == kPidDisabled || machineState == kWaterEmpty || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || pidBrewDisabled) { if (bPID.GetMode() == 1) { // Force PID shutdown bPID.SetMode(0); @@ -1877,46 +1828,29 @@ void looppid() { // Regular PID operation if (machineState == kPidNormal) { - if (usePonM) { - if (startTn != 0) { - startKi = startKp / startTn; - } - else { - startKi = 0; - } - - if (lastmachinestatepid != machineState) { - LOGF(DEBUG, "new PID-Values: P=%.1f I=%.1f D=%.1f", startKp, startKi, 0.0); - lastmachinestatepid = machineState; - } - - bPID.SetTunings(startKp, startKi, 0, P_ON_M); - } - else { - setNormalPIDTunings(); - } + setNormalPIDTunings(); } - // BD PID + // PID Brew if (machineState >= kBrew && machineState <= kBrewDetectionTrailing) { - if (brewPIDDelay > 0 && timeBrewed > 0 && timeBrewed < brewPIDDelay * 1000) { - // disable PID for brewPIDDelay seconds, enable PID again with new tunings after that - if (!brewPIDDisabled) { - brewPIDDisabled = true; + if (pidBrewDelay > 0 && timeBrewed > 0 && timeBrewed < pidBrewDelay * 1000) { + // disable PID for pidBrewDelay seconds, enable PID again with new tunings after that + if (!pidBrewDisabled) { + pidBrewDisabled = true; bPID.SetMode(MANUAL); - LOGF(DEBUG, "disabled PID, waiting for %d seconds before enabling PID again", brewPIDDelay); + LOGF(DEBUG, "disabled PID, waiting for %d seconds before enabling PID again", pidBrewDelay); } } else { - if (brewPIDDisabled) { + if (pidBrewDisabled) { // enable PID again bPID.SetMode(AUTOMATIC); - brewPIDDisabled = false; + pidBrewDisabled = false; LOG(DEBUG, "Enabled PID again after delay"); } - if (useBDPID) { - setBDPIDTunings(); + if (pidBrewOn) { + setBrewPidTunings(); } else { setNormalPIDTunings(); @@ -1988,24 +1922,24 @@ void setScaleTare(int tare) { #endif void setSteamMode(int steamMode) { - steamON = steamMode; + steamOn = steamMode; - if (steamON == 1) { - steamFirstON = 1; + if (steamOn == 1) { + steamFirstOn = 1; } - if (steamON == 0) { - steamFirstON = 0; + if (steamOn == 0) { + steamFirstOn = 0; } } void setPidStatus(int pidStatus) { - pidON = pidStatus; + pidOn = pidStatus; writeSysParamsToStorage(); } void setNormalPIDTunings() { - // Prevent overwriting of brewdetection values + // Prevent overwriting of brew pid values // calc ki, kd if (aggTn != 0) { aggKi = aggKp / aggTn; @@ -2023,10 +1957,15 @@ void setNormalPIDTunings() { lastmachinestatepid = machineState; } - bPID.SetTunings(aggKp, aggKi, aggKd, 1); + if (pidPonmOn) { + bPID.SetTunings(aggKp, aggKi, aggKd, P_ON_M); + } + else { + bPID.SetTunings(aggKp, aggKi, aggKd, P_ON_E); + } } -void setBDPIDTunings() { +void setBrewPidTunings() { // calc ki, kd if (aggbTn != 0) { aggbKi = aggbKp / aggbTn; @@ -2042,7 +1981,12 @@ void setBDPIDTunings() { lastmachinestatepid = machineState; } - bPID.SetTunings(aggbKp, aggbKi, aggbKd, 1); + if (pidPonmOn) { + bPID.SetTunings(aggbKp, aggbKi, aggbKd, P_ON_M); + } + else { + bPID.SetTunings(aggbKp, aggbKi, aggbKd, P_ON_E); + } } /** @@ -2052,34 +1996,32 @@ void setBDPIDTunings() { */ int readSysParamsFromStorage(void) { if (sysParaPidOn.getStorage() != 0) return -1; - if (sysParaUsePonM.getStorage() != 0) return -1; - if (sysParaPidKpStart.getStorage() != 0) return -1; - if (sysParaPidTnStart.getStorage() != 0) return -1; + if (sysParaPidPonmOn.getStorage() != 0) return -1; if (sysParaPidKpReg.getStorage() != 0) return -1; if (sysParaPidTnReg.getStorage() != 0) return -1; if (sysParaPidTvReg.getStorage() != 0) return -1; if (sysParaPidIMaxReg.getStorage() != 0) return -1; - if (sysParaBrewSetpoint.getStorage() != 0) return -1; - if (sysParaTempOffset.getStorage() != 0) return -1; - if (sysParaBrewPIDDelay.getStorage() != 0) return -1; - if (sysParaUseBDPID.getStorage() != 0) return -1; - if (sysParaPidKpBd.getStorage() != 0) return -1; - if (sysParaPidTnBd.getStorage() != 0) return -1; - if (sysParaPidTvBd.getStorage() != 0) return -1; - if (sysParaBrewTime.getStorage() != 0) return -1; + if (sysParaPidKpSteam.getStorage() != 0) return -1; + if (sysParaPidBrewOn.getStorage() != 0) return -1; + if (sysParaPidKpBrew.getStorage() != 0) return -1; + if (sysParaPidTnBrew.getStorage() != 0) return -1; + if (sysParaPidTvBrew.getStorage() != 0) return -1; + if (sysParaPidBrewDelay.getStorage() != 0) return -1; if (sysParaBrewSwTime.getStorage() != 0) return -1; if (sysParaBrewThresh.getStorage() != 0) return -1; + if (sysParaBrewTempOffset.getStorage() != 0) return -1; + if (sysParaBrewSetpoint.getStorage() != 0) return -1; + if (sysParaSteamSetpoint.getStorage() != 0) return -1; + if (sysParaBrewTime.getStorage() != 0) return -1; if (sysParaPreInfTime.getStorage() != 0) return -1; if (sysParaPreInfPause.getStorage() != 0) return -1; - if (sysParaPidKpSteam.getStorage() != 0) return -1; - if (sysParaSteamSetpoint.getStorage() != 0) return -1; if (sysParaWeightSetpoint.getStorage() != 0) return -1; - if (sysParaWifiCredentialsSaved.getStorage() != 0) return -1; - if (sysParaStandbyModeOn.getStorage() != 0) return -1; - if (sysParaStandbyModeTime.getStorage() != 0) return -1; if (sysParaScaleCalibration.getStorage() != 0) return -1; if (sysParaScale2Calibration.getStorage() != 0) return -1; if (sysParaScaleKnownWeight.getStorage() != 0) return -1; + if (sysParaWifiCredentialsSaved.getStorage() != 0) return -1; + if (sysParaStandbyModeOn.getStorage() != 0) return -1; + if (sysParaStandbyModeTime.getStorage() != 0) return -1; return 0; } @@ -2091,34 +2033,32 @@ int readSysParamsFromStorage(void) { */ int writeSysParamsToStorage(void) { if (sysParaPidOn.setStorage() != 0) return -1; - if (sysParaUsePonM.setStorage() != 0) return -1; - if (sysParaPidKpStart.setStorage() != 0) return -1; - if (sysParaPidTnStart.setStorage() != 0) return -1; + if (sysParaPidPonmOn.setStorage() != 0) return -1; if (sysParaPidKpReg.setStorage() != 0) return -1; if (sysParaPidTnReg.setStorage() != 0) return -1; if (sysParaPidTvReg.setStorage() != 0) return -1; if (sysParaPidIMaxReg.setStorage() != 0) return -1; - if (sysParaBrewSetpoint.setStorage() != 0) return -1; - if (sysParaTempOffset.setStorage() != 0) return -1; - if (sysParaBrewPIDDelay.setStorage() != 0) return -1; - if (sysParaUseBDPID.setStorage() != 0) return -1; - if (sysParaPidKpBd.setStorage() != 0) return -1; - if (sysParaPidTnBd.setStorage() != 0) return -1; - if (sysParaPidTvBd.setStorage() != 0) return -1; - if (sysParaBrewTime.setStorage() != 0) return -1; + if (sysParaPidKpSteam.setStorage() != 0) return -1; + if (sysParaPidBrewOn.setStorage() != 0) return -1; + if (sysParaPidKpBrew.setStorage() != 0) return -1; + if (sysParaPidTnBrew.setStorage() != 0) return -1; + if (sysParaPidTvBrew.setStorage() != 0) return -1; + if (sysParaPidBrewDelay.setStorage() != 0) return -1; if (sysParaBrewSwTime.setStorage() != 0) return -1; if (sysParaBrewThresh.setStorage() != 0) return -1; + if (sysParaBrewTempOffset.setStorage() != 0) return -1; + if (sysParaBrewSetpoint.setStorage() != 0) return -1; + if (sysParaSteamSetpoint.setStorage() != 0) return -1; + if (sysParaBrewTime.setStorage() != 0) return -1; if (sysParaPreInfTime.setStorage() != 0) return -1; if (sysParaPreInfPause.setStorage() != 0) return -1; - if (sysParaPidKpSteam.setStorage() != 0) return -1; - if (sysParaSteamSetpoint.setStorage() != 0) return -1; if (sysParaWeightSetpoint.setStorage() != 0) return -1; - if (sysParaWifiCredentialsSaved.setStorage() != 0) return -1; - if (sysParaStandbyModeOn.setStorage() != 0) return -1; - if (sysParaStandbyModeTime.setStorage() != 0) return -1; if (sysParaScaleCalibration.setStorage() != 0) return -1; if (sysParaScale2Calibration.setStorage() != 0) return -1; if (sysParaScaleKnownWeight.setStorage() != 0) return -1; + if (sysParaWifiCredentialsSaved.setStorage() != 0) return -1; + if (sysParaStandbyModeOn.setStorage() != 0) return -1; + if (sysParaStandbyModeTime.setStorage() != 0) return -1; return storageCommit(); } diff --git a/src/mqtt.h b/src/mqtt.h index f4611b14..744a53d3 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -162,8 +162,8 @@ void assignMQTTParam(char* param, double value) { case kUInt8: *(uint8_t*)var->ptr = value; - if (strcasecmp(param, "steamON") == 0) { - steamFirstON = value; + if (strcasecmp(param, "steamOn") == 0) { + steamFirstOn = value; } mqtt_publish(param, number2string(value), true); @@ -507,10 +507,8 @@ int sendHASSIODiscoveryMsg() { // Number Devices DiscoveryObject brewSetpoint = GenerateNumberDevice("brewSetpoint", "Brew setpoint", BREW_SETPOINT_MIN, BREW_SETPOINT_MAX, 0.1, "°C"); DiscoveryObject steamSetPoint = GenerateNumberDevice("steamSetpoint", "Steam setpoint", STEAM_SETPOINT_MIN, STEAM_SETPOINT_MAX, 0.1, "°C"); - DiscoveryObject brewTempOffset = GenerateNumberDevice("brewTempOffset", "Brew Temp. Offset", BREW_TEMP_OFFSET_MIN, BREW_TEMP_OFFSET_MAX, 0.1, "°C"); - DiscoveryObject brewPidDelay = GenerateNumberDevice("brewPidDelay", "Brew Pid Delay", BREW_PID_DELAY_MIN, BREW_PID_DELAY_MAX, 0.1, ""); - DiscoveryObject startKp = GenerateNumberDevice("startKp", "Start kP", PID_KP_START_MIN, PID_KP_START_MAX, 0.1, ""); - DiscoveryObject startTn = GenerateNumberDevice("startTn", "Start Tn", PID_TN_START_MIN, PID_TN_START_MAX, 0.1, ""); + DiscoveryObject brewTempOffset = GenerateNumberDevice("brewtempOffset", "Brew Temp. Offset", BREW_TEMP_OFFSET_MIN, BREW_TEMP_OFFSET_MAX, 0.1, "°C"); + DiscoveryObject pidBrewDelay = GenerateNumberDevice("pidBrewDelay", "Pid Brew Delay", PID_BREW_DELAY_MIN, PID_BREW_DELAY_MAX, 0.1, ""); DiscoveryObject steamKp = GenerateNumberDevice("steamKp", "Start Kp", PID_KP_STEAM_MIN, PID_KP_STEAM_MAX, 0.1, ""); DiscoveryObject aggKp = GenerateNumberDevice("aggKp", "aggKp", PID_KP_REGULAR_MIN, PID_KP_REGULAR_MAX, 0.1, ""); DiscoveryObject aggTn = GenerateNumberDevice("aggTn", "aggTn", PID_TN_REGULAR_MIN, PID_TN_REGULAR_MAX, 0.1, ""); @@ -529,10 +527,10 @@ int sendHASSIODiscoveryMsg() { #endif // Switch Devices - DiscoveryObject pidOn = GenerateSwitchDevice("pidON", "Use PID"); - DiscoveryObject steamON = GenerateSwitchDevice("steamON", "Steam"); + DiscoveryObject pidOn = GenerateSwitchDevice("pidOn", "PID On"); + DiscoveryObject steamOn = GenerateSwitchDevice("steamOn", "Steam"); DiscoveryObject backflushOn = GenerateSwitchDevice("backflushOn", "Backflush"); - DiscoveryObject startUsePonM = GenerateSwitchDevice("startUsePonM", "Use PonM"); + DiscoveryObject pidPonmOn = GenerateSwitchDevice("pidPonmOn", "PID PonM On"); // Button Devices DiscoveryObject scaleCalibrateButton = GenerateButtonDevice("scaleCalibrationOn", "Calibrate Scale"); @@ -541,9 +539,7 @@ int sendHASSIODiscoveryMsg() { std::vector discoveryObjects = {brewSetpoint, steamSetPoint, brewTempOffset, - brewPidDelay, - startKp, - startTn, + pidBrewDelay, steamKp, aggKp, aggTn, @@ -554,9 +550,9 @@ int sendHASSIODiscoveryMsg() { machineStateDevice, brewtime, pidOn, - steamON, + steamOn, backflushOn, - startUsePonM + pidPonmOn #if FEATURE_PRESSURESENSOR == 1 , diff --git a/src/powerHandler.h b/src/powerHandler.h index e85e3ff4..94a2a23a 100644 --- a/src/powerHandler.h +++ b/src/powerHandler.h @@ -13,11 +13,11 @@ void checkPowerSwitch() { if (POWERSWITCH_TYPE == Switch::TOGGLE) { // Set pidON to 1 when powerswitch is HIGH if ((powerSwitchReading == HIGH && machineState != kStandby) || (powerSwitchReading == LOW && machineState == kStandby)) { - pidON = 1; + pidOn = 1; } else { // Set pidON to 0 when powerswitch is not HIGH - pidON = 0; + pidOn = 0; } } else if (POWERSWITCH_TYPE == Switch::MOMENTARY) { @@ -27,11 +27,11 @@ void checkPowerSwitch() { // only toggle heating power if the new button state is HIGH if (currStatePowerSwitch == HIGH) { - if (pidON == 0) { - pidON = 1; + if (pidOn == 0) { + pidOn = 1; } else { - pidON = 0; + pidOn = 0; } } } diff --git a/src/steamHandler.h b/src/steamHandler.h index 9dcff5a5..d74430e9 100644 --- a/src/steamHandler.h +++ b/src/steamHandler.h @@ -13,24 +13,24 @@ void checkSteamSwitch() { if (STEAMSWITCH_TYPE == Switch::TOGGLE) { // Set steamON to 1 when steamswitch is HIGH if (steamSwitchReading == HIGH) { - steamON = 1; + steamOn = 1; } // if activated via web interface then steamFirstON == 1, prevent override - if (steamSwitchReading == LOW && !steamFirstON) { - steamON = 0; + if (steamSwitchReading == LOW && !steamFirstOn) { + 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; + steamOn = 0; steamQM_active = false; lastTimeOptocouplerOn = 0; } else { - steamON = 1; + steamOn = 1; } } } @@ -41,11 +41,11 @@ void checkSteamSwitch() { // only toggle heating power if the new button state is HIGH if (currStateSteamSwitch == HIGH) { - if (steamON == 0) { - steamON = 1; + if (steamOn == 0) { + steamOn = 1; } else { - steamON = 0; + steamOn = 0; } } } diff --git a/src/storage.h b/src/storage.h index ee54171c..13c1fde1 100644 --- a/src/storage.h +++ b/src/storage.h @@ -10,39 +10,34 @@ // storage items typedef enum { STO_ITEM_PID_ON, // PID on/off state - STO_ITEM_PID_START_PONM, // Use PonM for cold start phase (otherwise use normal PID and same params) - STO_ITEM_PID_KP_START, // PID P part at cold start phase - STO_ITEM_PID_TN_START, // PID I part at cold start phase + STO_ITEM_PID_PONM_ON, // PID PonM on/off STO_ITEM_PID_KP_REGULAR, // PID P part at regular operation STO_ITEM_PID_TN_REGULAR, // PID I part at regular operation STO_ITEM_PID_TV_REGULAR, // PID D part at regular operation STO_ITEM_PID_I_MAX_REGULAR, // PID Integrator upper limit - STO_ITEM_PID_KP_BD, // PID P part at brew detection phase - STO_ITEM_PID_TN_BD, // PID I part at brew detection phase - STO_ITEM_PID_TV_BD, // PID D part at brew detection phase - STO_ITEM_BREW_SETPOINT, // brew setpoint - STO_ITEM_BREW_TEMP_OFFSET, // brew temp offset - STO_ITEM_USE_BD_PID, // use separate PID for brew detection (otherwise continue with regular PID) - STO_ITEM_BREW_TIME, // brew time - STO_ITEM_BREW_SW_TIME, // brew software time - STO_ITEM_BREW_PID_DELAY, // brew PID delay + STO_ITEM_PID_KP_STEAM, // PID P part at steam phase + STO_ITEM_PID_BREW_ON, // PID during brewing (otherwise continue with regular PID) + STO_ITEM_PID_KP_BREW, // PID P part during brewing + STO_ITEM_PID_TN_BREW, // PID I part during brewing + STO_ITEM_PID_TV_BREW, // PID D part during brewing + STO_ITEM_PID_BREW_DELAY, // PID brew delay STO_ITEM_BD_THRESHOLD, // brew detection limit - STO_ITEM_WIFI_CREDENTIALS_SAVED, // flag for wifisetup + STO_ITEM_BREW_SW_TIME, // brew software time + STO_ITEM_BREW_TEMP_OFFSET, // brew temp offset (offset boiler/thermoblock to group head) + STO_ITEM_BREW_SETPOINT, // setpoint for Brew mode + STO_ITEM_STEAM_SETPOINT, // setpoint for Steam mode + STO_ITEM_BREW_TIME, // brew time STO_ITEM_PRE_INFUSION_TIME, // pre-infusion time STO_ITEM_PRE_INFUSION_PAUSE, // pre-infusion pause - 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 + STO_ITEM_WEIGHTSETPOINT, // Brew weight setpoint + STO_ITEM_SCALE_CALIBRATION_FACTOR, // calibration factor for scale + STO_ITEM_SCALE2_CALIBRATION_FACTOR, // calibration factor for scale 2 + STO_ITEM_SCALE_KNOWN_WEIGHT, // calibration weight for scale STO_ITEM_WIFI_SSID, // Wifi SSID STO_ITEM_WIFI_PASSWORD, // Wifi password - STO_ITEM_WEIGHTSETPOINT, // Brew weight setpoint + STO_ITEM_WIFI_CREDENTIALS_SAVED, // flag for wifisetup STO_ITEM_STANDBY_MODE_ON, // Enable tandby mode - STO_ITEM_STANDBY_MODE_TIME, // Time until heater is turned off - STO_ITEM_SCALE_CALIBRATION_FACTOR, // Calibration factor for scale - STO_ITEM_SCALE2_CALIBRATION_FACTOR, // Calibration factor for scale 2 - STO_ITEM_SCALE_KNOWN_WEIGHT, // Calibration weight for scale - STO_ITEM_RESERVED_30, // reserved - STO_ITEM_RESERVED_21, // reserved + STO_ITEM_STANDBY_MODE_TIME, // time until heater is turned off /* WHEN ADDING NEW ITEMS, THE FOLLOWING HAS TO BE UPDATED: * - storage structure: sto_data_t @@ -66,97 +61,68 @@ typedef enum { // storage data structure typedef struct __attribute__((packed)) { - // Any 'freeToUse' areas ensure the compatibility to origin EEPROM layout and can be used by new value. + uint8_t pidOn; + uint8_t pidPonmOn; double pidKpRegular; - uint8_t reserved1[2]; double pidTnRegular; - uint8_t pidOn; - uint8_t freeToUse1; double pidTvRegular; double pidIMaxRegular; - uint8_t freeToUse2; - double brewSetpoint; + double pidKpSteam; + uint8_t pidBrewOn; + double pidKpBrew; + double pidTnBrew; + double pidTvBrew; + double pidBrewDelaySec; + double brewDetectionThreshold; + double brewSwTimeSec; double brewTempOffset; - uint8_t freeToUse3; + double brewSetpoint; + double steamSetpoint; double brewTimeMs; - float scaleCalibration; double preInfusionTimeMs; - float scaleKnownWeight; double preInfusionPauseMs; - uint8_t freeToUse6[21]; - uint8_t pidBdOn; - double pidKpBd; + double weightSetpoint; + float scaleCalibration; 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]; + float scaleKnownWeight; char wifiSSID[25 + 1]; char wifiPassword[25 + 1]; - double weightSetpoint; - double steamkp; - double steamSetpoint; + uint8_t wifiCredentialsSaved; uint8_t standbyModeOn; double standbyModeTime; } sto_data_t; // 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 - 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 - STEAMKP, // STO_ITEM_PID_KP_STEAM - STEAMSETPOINT, // STO_ITEM_STEAM_SETPOINT - STANDBY_MODE_ON, // STO_ITEM_STANDBY_MODE_ON - STANDBY_MODE_TIME // STO_ITEM_STANDBY_MODE_TIME + 0, // STO_ITEM_PID_ON + 0, // STO_ITEM_PONM_ON + AGGKP, // STO_ITEM_PID_KP_REGULAR + AGGTN, // STO_ITEM_PID_TN_REGULAR + AGGTV, // STO_ITEM_PID_TV_REGULAR + AGGIMAX, // STO_ITEM_PID_I_MAX_REGULAR + STEAMKP, // STO_ITEM_PID_KP_STEAM + 0, // STO_ITEM_PID_BREW_ON + AGGBKP, // STO_ITEM_PID_KP_BREW + AGGBTN, // STO_ITEM_PID_TN_BREW + AGGBTV, // STO_ITEM_PID_TV_BREW + PID_BREW_DELAY, // STO_ITEM_PID_BREW_DELAY + BD_SENSITIVITY, // STO_ITEM_BD_THRESHOLD + BREW_SW_TIME, // STO_ITEM_BREW_SW_TIME + BREWTEMPOFFSET, // STO_ITEM_BREW_TEMP_OFFSET + SETPOINT, // STO_ITEM_BREW_SETPOINT + STEAMSETPOINT, // STO_ITEM_STEAM_SETPOINT + BREW_TIME, // STO_ITEM_BREW_TIME + PRE_INFUSION_TIME, // STO_ITEM_PRE_INFUSION_TIME + PRE_INFUSION_PAUSE_TIME, // STO_ITEM_PRE_INFUSION_PAUSE + SCALE_WEIGHTSETPOINT, // STO_ITEM_WEIGHTSETPOINT + SCALE_CALIBRATION_FACTOR, // STO_ITEM_SCALE_CALIBRATION_FACTOR + SCALE2_CALIBRATION_FACTOR, // STO_ITEM_SCALE2_CALIBRATION_FACTOR + SCALE_KNOWN_WEIGHT, // STO_ITEM_SCALE_KNOWN_WEIGHT + "", // STO_ITEM_WIFI_SSID + "", // STO_ITEM_WIFI_PASSWORD + WIFI_CREDENTIALS_SAVED, // STO_ITEM_WIFI_CREDENTIALS_SAVED + STANDBY_MODE_ON, // STO_ITEM_STANDBY_MODE_ON + STANDBY_MODE_TIME // STO_ITEM_STANDBY_MODE_TIME }; /** @@ -174,6 +140,16 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize = uint16_t size; switch (itemId) { + case STO_ITEM_PID_ON: + addr = offsetof(sto_data_t, pidOn); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidOn); + break; + + case STO_ITEM_PID_PONM_ON: + addr = offsetof(sto_data_t, pidPonmOn); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidPonmOn); + break; + case STO_ITEM_PID_KP_REGULAR: addr = offsetof(sto_data_t, pidKpRegular); size = STRUCT_MEMBER_SIZE(sto_data_t, pidKpRegular); @@ -194,89 +170,94 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize = size = STRUCT_MEMBER_SIZE(sto_data_t, pidIMaxRegular); break; - case STO_ITEM_BREW_SETPOINT: - addr = offsetof(sto_data_t, brewSetpoint); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewSetpoint); + case STO_ITEM_PID_KP_STEAM: + addr = offsetof(sto_data_t, pidKpSteam); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidKpSteam); break; - case STO_ITEM_BREW_TEMP_OFFSET: - addr = offsetof(sto_data_t, brewTempOffset); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewTempOffset); + case STO_ITEM_PID_BREW_ON: + addr = offsetof(sto_data_t, pidBrewOn); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidBrewOn); break; - case STO_ITEM_BREW_TIME: - addr = offsetof(sto_data_t, brewTimeMs); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewTimeMs); + case STO_ITEM_PID_KP_BREW: + addr = offsetof(sto_data_t, pidKpBrew); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidKpBrew); break; - case STO_ITEM_PRE_INFUSION_TIME: - addr = offsetof(sto_data_t, preInfusionTimeMs); - size = STRUCT_MEMBER_SIZE(sto_data_t, preInfusionTimeMs); + case STO_ITEM_PID_TN_BREW: + addr = offsetof(sto_data_t, pidTnBrew); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidTnBrew); break; - case STO_ITEM_PRE_INFUSION_PAUSE: - addr = offsetof(sto_data_t, preInfusionPauseMs); - size = STRUCT_MEMBER_SIZE(sto_data_t, preInfusionPauseMs); + case STO_ITEM_PID_TV_BREW: + addr = offsetof(sto_data_t, pidTvBrew); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidTvBrew); break; - case STO_ITEM_BREW_PID_DELAY: - addr = offsetof(sto_data_t, brewPIDDelaySec); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewPIDDelaySec); + case STO_ITEM_PID_BREW_DELAY: + addr = offsetof(sto_data_t, pidBrewDelaySec); + size = STRUCT_MEMBER_SIZE(sto_data_t, pidBrewDelaySec); break; - case STO_ITEM_USE_BD_PID: - addr = offsetof(sto_data_t, pidBdOn); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidBdOn); + case STO_ITEM_BD_THRESHOLD: + addr = offsetof(sto_data_t, brewDetectionThreshold); + size = STRUCT_MEMBER_SIZE(sto_data_t, brewDetectionThreshold); break; - case STO_ITEM_PID_KP_BD: - addr = offsetof(sto_data_t, pidKpBd); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidKpBd); + case STO_ITEM_BREW_SW_TIME: + addr = offsetof(sto_data_t, brewSwTimeSec); + size = STRUCT_MEMBER_SIZE(sto_data_t, brewSwTimeSec); break; - case STO_ITEM_PID_TN_BD: - addr = offsetof(sto_data_t, pidTnBd); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidTnBd); + case STO_ITEM_BREW_TEMP_OFFSET: + addr = offsetof(sto_data_t, brewTempOffset); + size = STRUCT_MEMBER_SIZE(sto_data_t, brewTempOffset); break; - case STO_ITEM_PID_TV_BD: - addr = offsetof(sto_data_t, pidTvBd); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidTvBd); + case STO_ITEM_BREW_SETPOINT: + addr = offsetof(sto_data_t, brewSetpoint); + size = STRUCT_MEMBER_SIZE(sto_data_t, brewSetpoint); break; - case STO_ITEM_BREW_SW_TIME: - addr = offsetof(sto_data_t, brewSwTimeSec); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewSwTimeSec); + case STO_ITEM_STEAM_SETPOINT: + addr = offsetof(sto_data_t, steamSetpoint); + size = STRUCT_MEMBER_SIZE(sto_data_t, steamSetpoint); break; - case STO_ITEM_BD_THRESHOLD: - addr = offsetof(sto_data_t, brewDetectionThreshold); - size = STRUCT_MEMBER_SIZE(sto_data_t, brewDetectionThreshold); + case STO_ITEM_BREW_TIME: + addr = offsetof(sto_data_t, brewTimeMs); + size = STRUCT_MEMBER_SIZE(sto_data_t, brewTimeMs); break; - case STO_ITEM_WIFI_CREDENTIALS_SAVED: - addr = offsetof(sto_data_t, wifiCredentialsSaved); - size = STRUCT_MEMBER_SIZE(sto_data_t, wifiCredentialsSaved); + case STO_ITEM_PRE_INFUSION_TIME: + addr = offsetof(sto_data_t, preInfusionTimeMs); + size = STRUCT_MEMBER_SIZE(sto_data_t, preInfusionTimeMs); break; - case STO_ITEM_PID_START_PONM: - addr = offsetof(sto_data_t, useStartPonM); - size = STRUCT_MEMBER_SIZE(sto_data_t, useStartPonM); + case STO_ITEM_PRE_INFUSION_PAUSE: + addr = offsetof(sto_data_t, preInfusionPauseMs); + size = STRUCT_MEMBER_SIZE(sto_data_t, preInfusionPauseMs); + break; + + case STO_ITEM_WEIGHTSETPOINT: + addr = offsetof(sto_data_t, weightSetpoint); + size = STRUCT_MEMBER_SIZE(sto_data_t, weightSetpoint); break; - case STO_ITEM_PID_KP_START: - addr = offsetof(sto_data_t, pidKpStart); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidKpStart); + case STO_ITEM_SCALE_CALIBRATION_FACTOR: + addr = offsetof(sto_data_t, scaleCalibration); + size = STRUCT_MEMBER_SIZE(sto_data_t, scaleCalibration); break; - case STO_ITEM_PID_TN_START: - addr = offsetof(sto_data_t, pidTnStart); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidTnStart); + case STO_ITEM_SCALE2_CALIBRATION_FACTOR: + addr = offsetof(sto_data_t, scale2Calibration); + size = STRUCT_MEMBER_SIZE(sto_data_t, scale2Calibration); break; - case STO_ITEM_SOFT_AP_ENABLED_CHECK: - addr = offsetof(sto_data_t, softApEnabledCheck); - size = STRUCT_MEMBER_SIZE(sto_data_t, softApEnabledCheck); + case STO_ITEM_SCALE_KNOWN_WEIGHT: + addr = offsetof(sto_data_t, scaleKnownWeight); + size = STRUCT_MEMBER_SIZE(sto_data_t, scaleKnownWeight); break; case STO_ITEM_WIFI_SSID: @@ -289,24 +270,9 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize = size = STRUCT_MEMBER_SIZE(sto_data_t, wifiPassword); break; - case STO_ITEM_PID_ON: - addr = offsetof(sto_data_t, pidOn); - size = STRUCT_MEMBER_SIZE(sto_data_t, pidOn); - break; - - case STO_ITEM_PID_KP_STEAM: - addr = offsetof(sto_data_t, steamkp); - size = STRUCT_MEMBER_SIZE(sto_data_t, steamkp); - break; - - case STO_ITEM_WEIGHTSETPOINT: - addr = offsetof(sto_data_t, weightSetpoint); - size = STRUCT_MEMBER_SIZE(sto_data_t, weightSetpoint); - break; - - case STO_ITEM_STEAM_SETPOINT: - addr = offsetof(sto_data_t, steamSetpoint); - size = STRUCT_MEMBER_SIZE(sto_data_t, steamSetpoint); + case STO_ITEM_WIFI_CREDENTIALS_SAVED: + addr = offsetof(sto_data_t, wifiCredentialsSaved); + size = STRUCT_MEMBER_SIZE(sto_data_t, wifiCredentialsSaved); break; case STO_ITEM_STANDBY_MODE_ON: @@ -319,21 +285,6 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize = size = STRUCT_MEMBER_SIZE(sto_data_t, standbyModeTime); break; - case STO_ITEM_SCALE_CALIBRATION_FACTOR: - addr = offsetof(sto_data_t, scaleCalibration); - size = STRUCT_MEMBER_SIZE(sto_data_t, scaleCalibration); - break; - - case STO_ITEM_SCALE2_CALIBRATION_FACTOR: - addr = offsetof(sto_data_t, scale2Calibration); - size = STRUCT_MEMBER_SIZE(sto_data_t, scale2Calibration); - break; - - case STO_ITEM_SCALE_KNOWN_WEIGHT: - addr = offsetof(sto_data_t, scaleKnownWeight); - size = STRUCT_MEMBER_SIZE(sto_data_t, scaleKnownWeight); - break; - default: LOGF(ERROR, "invalid item ID %i!", itemId); addr = -1;