Skip to content

Commit

Permalink
Handling new restrictions separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0-bit committed Apr 13, 2023
1 parent 25846bb commit ddd146a
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 19 deletions.
Binary file modified lcd-hmi/nextion-lcd.HMI
Binary file not shown.
Binary file modified nextion-basic-lcd.tft
Binary file not shown.
Binary file modified nextion-discovery-lcd.tft
Binary file not shown.
8 changes: 8 additions & 0 deletions src/eeprom_data/eeprom_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "eeprom_metadata.h"
#include "legacy/eeprom_data_v4.h"
#include "legacy/eeprom_data_v5.h"
#include "legacy/eeprom_data_v6.h"

namespace {

Expand Down Expand Up @@ -46,6 +47,8 @@ namespace {
defaultData.graphBrew = true;
defaultData.brewDeltaState = true;
defaultData.switchPhaseOnThreshold = false;
defaultData.switchPhaseOnPressureBelow = 0.5f;
defaultData.switchPhaseOnFirstDrops = true;
defaultData.basketPrefill = false;
defaultData.scalesF1 = 3920;
defaultData.scalesF2 = 4210;
Expand Down Expand Up @@ -132,6 +135,11 @@ bool eepromWrite(eepromValues_t eepromValuesNew) {
return false;
}

if (eepromValuesNew.switchPhaseOnPressureBelow < 0) {
LOG_ERROR(errMsg);
return false;
}

eepromMetadata.timestamp = millis();
eepromMetadata.version = EEPROM_DATA_VERSION;
eepromMetadata.values = eepromValuesNew;
Expand Down
13 changes: 6 additions & 7 deletions src/eeprom_data/eeprom_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
*/

/**
* Version 6:
* - Pressure as float:
* - pressureProfilingStart
* - pressureProfilingFinish
* - preinfusionBar
* - preinfusionFlowPressureTarget
* - flowProfilePressureTarget
* Version 7:
* - Add two more restrictions:
* - switchPhaseOnPressureBelow
* - switchPhaseOnFirstDrops
*/
struct eepromValues_t {
uint16_t setpoint;
Expand Down Expand Up @@ -67,6 +64,8 @@ struct eepromValues_t {
bool graphBrew;
bool brewDeltaState;
bool switchPhaseOnThreshold;
float switchPhaseOnPressureBelow;
bool switchPhaseOnFirstDrops;
bool basketPrefill;
int scalesF1;
int scalesF2;
Expand Down
2 changes: 1 addition & 1 deletion src/eeprom_data/eeprom_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <Arduino.h>

#define EEPROM_DATA_VERSION 6
#define EEPROM_DATA_VERSION 7

#define EEPROM_METADATA_T(__eepromValues_tName) \
{ \
Expand Down
127 changes: 127 additions & 0 deletions src/eeprom_data/legacy/eeprom_data_v6.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* 09:32 15/03/2023 - change triggering comment */
#ifndef EEPROM_DATA_V6_H
#define EEPROM_DATA_V6_H

#include "../eeprom_data.h"
#include "../eeprom_metadata.h"

/**
* current data version definition below
*
* changing the schema requires bumping version number. this forces a schema update
* on boards with a lower version after flash. to make this graceful for users:
* - archive the current version in its corresponding header in legacy/
* - in that header, make sure to register the upgrade function for
* the loader to pick it up
* - bump up the version in eeprom_metadata.h
* - make schema changes
*
* adding fields to data below shouldn't require changes to legacy upgrade
* functions - they just won't populate the new field, and it will use
* default value.
*
* removing fields might require deleting assignments in existing legacy
* functions that reference them. this will pop up as a compile time failure
*/

/**
* Version 6:
* - Pressure as float:
* - pressureProfilingStart
* - pressureProfilingFinish
* - preinfusionBar
* - preinfusionFlowPressureTarget
* - flowProfilePressureTarget
*/
struct eepromValues_t_v6 {
uint16_t setpoint;
uint16_t steamSetPoint;
uint16_t offsetTemp;
uint16_t hpwr;
uint16_t mainDivider;
uint16_t brewDivider;
float pressureProfilingStart;
float pressureProfilingFinish;
uint16_t pressureProfilingHold;
uint16_t pressureProfilingLength;
bool pressureProfilingState;
bool preinfusionState;
uint16_t preinfusionSec;
float preinfusionBar;
uint16_t preinfusionSoak;
uint16_t preinfusionRamp;
bool preinfusionFlowState;
float preinfusionFlowVol;
uint16_t preinfusionFlowTime;
uint16_t preinfusionFlowSoakTime;
float preinfusionFlowPressureTarget;
bool flowProfileState;
float flowProfileStart;
float flowProfileEnd;
float flowProfilePressureTarget;
uint16_t flowProfileCurveSpeed;
uint16_t powerLineFrequency;
uint16_t lcdSleep;
bool warmupState;
bool homeOnShotFinish;
bool graphBrew;
bool brewDeltaState;
bool switchPhaseOnThreshold;
bool basketPrefill;
int scalesF1;
int scalesF2;
float pumpFlowAtZero;
bool stopOnWeightState;
float shotDose;
float shotStopOnCustomWeight;
uint16_t shotPreset;
};

static bool upgradeSchema_v6(eepromValues_t &targetValues, eepromValues_t_v6 &loadedValues) {
targetValues.setpoint = loadedValues.setpoint;
targetValues.steamSetPoint = loadedValues.steamSetPoint;
targetValues.offsetTemp = loadedValues.offsetTemp;
targetValues.hpwr = loadedValues.hpwr;
targetValues.mainDivider = loadedValues.mainDivider;
targetValues.brewDivider = loadedValues.brewDivider;
targetValues.pressureProfilingStart = (float) loadedValues.pressureProfilingStart;

This comment has been minimized.

Copy link
@matiasjrossi

matiasjrossi Apr 13, 2023

Collaborator

fyi, these explicit float casts are not necessary in 6 to 7 upgrade. they were necessary from older versions because 6 changed the data type. should be harmless though.

This comment has been minimized.

Copy link
@Zer0-bit

Zer0-bit Apr 13, 2023

Owner

Yeah i figured this is not necessary but thought it'd be a nice test of the schema migration stability as well as maybe save someone's life if they migrate from an older version(probs not cause these are all incremental as far as i see lol)

targetValues.pressureProfilingFinish = (float) loadedValues.pressureProfilingFinish;
targetValues.pressureProfilingHold = loadedValues.pressureProfilingHold;
targetValues.pressureProfilingLength = loadedValues.pressureProfilingLength;
targetValues.pressureProfilingState = loadedValues.pressureProfilingState;
targetValues.preinfusionState = loadedValues.preinfusionState;
targetValues.preinfusionSec = loadedValues.preinfusionSec;
targetValues.preinfusionBar = (float) loadedValues.preinfusionBar;
targetValues.preinfusionSoak = loadedValues.preinfusionSoak;
targetValues.preinfusionRamp = loadedValues.preinfusionRamp;
targetValues.preinfusionFlowState = loadedValues.preinfusionFlowState;
targetValues.preinfusionFlowVol = loadedValues.preinfusionFlowVol;
targetValues.preinfusionFlowTime = loadedValues.preinfusionFlowTime;
targetValues.preinfusionFlowSoakTime = loadedValues.preinfusionFlowSoakTime;
targetValues.preinfusionFlowPressureTarget = (float) loadedValues.preinfusionFlowPressureTarget;
targetValues.flowProfileState = loadedValues.flowProfileState;
targetValues.flowProfileStart = loadedValues.flowProfileStart;
targetValues.flowProfileEnd = loadedValues.flowProfileEnd;
targetValues.flowProfilePressureTarget = (float) loadedValues.flowProfilePressureTarget;
targetValues.flowProfileCurveSpeed = loadedValues.flowProfileCurveSpeed;
targetValues.powerLineFrequency = loadedValues.powerLineFrequency;
targetValues.lcdSleep = loadedValues.lcdSleep;
targetValues.warmupState = loadedValues.warmupState;
targetValues.homeOnShotFinish = loadedValues.homeOnShotFinish;
targetValues.graphBrew = loadedValues.graphBrew;
targetValues.brewDeltaState = loadedValues.brewDeltaState;
targetValues.switchPhaseOnThreshold = loadedValues.switchPhaseOnThreshold;
targetValues.basketPrefill = loadedValues.basketPrefill;
targetValues.scalesF1 = loadedValues.scalesF1;
targetValues.scalesF2 = loadedValues.scalesF2;
targetValues.pumpFlowAtZero = loadedValues.pumpFlowAtZero;
targetValues.stopOnWeightState = loadedValues.stopOnWeightState;
targetValues.shotDose = loadedValues.shotDose;
targetValues.shotStopOnCustomWeight = loadedValues.shotStopOnCustomWeight;
targetValues.shotPreset = loadedValues.shotPreset;
return true;
}

REGISTER_LEGACY_EEPROM_DATA(6, eepromValues_t_v6, upgradeSchema_v6)

#endif
6 changes: 4 additions & 2 deletions src/functional/predictive_weight.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ class PredictiveWeight {
}

void reset() {
outputFlowStarted = false;
isForceStarted = false;
puckResistance = 0.f;
resistanceDelta = 0.f;
isForceStarted = false;
outputFlowStarted = false;
predictiveTargetReached = false;

}
};

Expand Down
1 change: 1 addition & 0 deletions src/gaggiuino.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const float calibrationPressure = 4.5f;
#else
const float calibrationPressure = 0.65f;
#endif
const float firstDropsConstant = 0.9f;

//Timers
unsigned long systemHealthTimer;
Expand Down
17 changes: 9 additions & 8 deletions src/gaggiuino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ void lcdTrigger1(void) {
eepromCurrentValues.shotDose = lcdValues.shotDose;
eepromCurrentValues.shotPreset = lcdValues.shotPreset;
eepromCurrentValues.shotStopOnCustomWeight = lcdValues.shotStopOnCustomWeight;
eepromCurrentValues.switchPhaseOnPressureBelow = lcdValues.switchPhaseOnPressureBelow;
eepromCurrentValues.switchPhaseOnFirstDrops = lcdValues.switchPhaseOnFirstDrops;
break;
default:
break;
Expand Down Expand Up @@ -477,6 +479,7 @@ static void updateProfilerPhases(void) {
float shotTarget = -1.f;
float stopOnPressureAbove = -1;
float switchPhaseOnDrip = -1;
float pressureBelowRestriction = -1;

if (runningCfg.stopOnWeightState) {
shotTarget = (runningCfg.shotStopOnCustomWeight < 1.f)
Expand All @@ -498,20 +501,18 @@ static void updateProfilerPhases(void) {
if (runningCfg.preinfusionState) {
if (runningCfg.preinfusionFlowState) { // flow based PI enabled
// For now handling phase switching on restrictions here but as this grow will have to deal with it otherwise.
if (runningCfg.switchPhaseOnThreshold) {
stopOnPressureAbove = runningCfg.preinfusionFlowPressureTarget;
switchPhaseOnDrip = 0.9f;
}
stopOnPressureAbove = runningCfg.switchPhaseOnThreshold ? runningCfg.preinfusionFlowPressureTarget : -1;
switchPhaseOnDrip = runningCfg.switchPhaseOnFirstDrops ? firstDropsConstant : -1;
pressureBelowRestriction = runningCfg.switchPhaseOnPressureBelow > 0 ? runningCfg.switchPhaseOnPressureBelow : -1;

addFlowPhase(Transition{runningCfg.preinfusionFlowVol}, runningCfg.preinfusionFlowPressureTarget, runningCfg.preinfusionFlowTime * 1000, stopOnPressureAbove, switchPhaseOnDrip);
addFlowPhase(Transition{0.f}, 0, runningCfg.preinfusionFlowSoakTime * 1000, -1, switchPhaseOnDrip);
preInfusionFinishBar = fmaxf(0.f, runningCfg.preinfusionFlowPressureTarget);
} else { // pressure based PI enabled
// For now handling phase switching on restrictions here but as this grow will have to deal with it otherwise.
if (runningCfg.switchPhaseOnThreshold) {
stopOnPressureAbove = runningCfg.preinfusionBar;
switchPhaseOnDrip = 0.9f;
}
stopOnPressureAbove = runningCfg.switchPhaseOnThreshold ? runningCfg.preinfusionBar : -1;
switchPhaseOnDrip = runningCfg.switchPhaseOnFirstDrops ? firstDropsConstant : -1;
pressureBelowRestriction = runningCfg.switchPhaseOnPressureBelow > 0 ? runningCfg.switchPhaseOnPressureBelow : -1;

addPressurePhase(Transition{(float) runningCfg.preinfusionBar}, 4.5f, runningCfg.preinfusionSec * 1000, stopOnPressureAbove, switchPhaseOnDrip);
addPressurePhase(Transition{0.f}, -1, runningCfg.preinfusionSoak * 1000, -1, switchPhaseOnDrip);
Expand Down
5 changes: 4 additions & 1 deletion src/lcd/nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void lcdUploadCfg(eepromValues_t &eepromCurrentValues) {
myNex.writeNum("brewSettings.btTempDelta.val", eepromCurrentValues.brewDeltaState);

myNex.writeNum("switchPhaseOnThreshold", eepromCurrentValues.switchPhaseOnThreshold);
myNex.writeNum("brewSettings.btPhaseSwitch.val", eepromCurrentValues.switchPhaseOnThreshold);
myNex.writeNum("brewSettings.pBelow.val", eepromCurrentValues.switchPhaseOnPressureBelow * 10.f);
myNex.writeNum("firstDrip", eepromCurrentValues.switchPhaseOnFirstDrops);

myNex.writeNum("shotState", eepromCurrentValues.stopOnWeightState);
myNex.writeNum("shotDose", eepromCurrentValues.shotDose * 10.f);
Expand Down Expand Up @@ -185,6 +186,8 @@ eepromValues_t lcdDownloadCfg(void) {
lcdCfg.lcdSleep = myNex.readNumber("systemSleepTime") / 60;
lcdCfg.brewDeltaState = myNex.readNumber("deltaState");
lcdCfg.switchPhaseOnThreshold = myNex.readNumber("switchPhaseOnThreshold");
lcdCfg.switchPhaseOnPressureBelow = myNex.readNumber("brewSettings.pBelow.val") / 10.f;
lcdCfg.switchPhaseOnFirstDrops = myNex.readNumber("firstDrip");

lcdCfg.scalesF1 = myNex.readNumber("morePower.lc1.val");
lcdCfg.scalesF2 = myNex.readNumber("morePower.lc2.val");
Expand Down

0 comments on commit ddd146a

Please sign in to comment.