Skip to content

Commit

Permalink
Incorporate review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianSperrle committed Jan 26, 2024
1 parent ecb36cb commit 16c601f
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 70 deletions.
6 changes: 3 additions & 3 deletions data/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ <h5 class="card-title">
</td>
</template>
<template v-if="param.name == 'TARE_ON'">
<td><b>Toggle Tare Mode</b></td>
<td><b>Tare Scale</b></td>
<td><span id="tare_state"></span></td>
<td>
<form action="/toggleTare" method="post">
<form action="/toggleTareScale" method="post">
<input type="hidden" id="varTARE_ON" name="varTARE_ON" />
<input type="submit" class="btn btn-primary" :value="param.value == 1 ? 'Off' : 'On'" id="tare_toggle" />
</form>
</td>
</template>
<template v-if="param.name == 'CALIBRATION_ON'">
<td><b>Toggle Calibration Mode</b></td>
<td><b>Scale Calibration Mode</b></td>
<td><span id="calibration_state"></span></td>
<td>
<form>
Expand Down
8 changes: 4 additions & 4 deletions data/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ const vueApp = Vue.createApp({
0: 'PID Parameters',
1: 'Temperature and Preinfusion',
2: 'Brew Detection and Brew PID Parameters',
3: 'Power Settings',
4: 'Scale Parameters'
3: 'Scale Parameters',
4: 'Power Settings'
}
return sectionNames[sectionId]
},
confirmSubmission() {
if (confirm('Are you sure you want to toggle the calibration?')) {
if (confirm('Are you sure you want to start the scale calibration?')) {
const requestOptions = {
method: "POST",
cache: 'no-cache'
};
fetch("/toggleCalibration", requestOptions)
fetch("/toggleScaleCalibration", requestOptions)
}
}
},
Expand Down
16 changes: 8 additions & 8 deletions src/EmbeddedWebserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,20 @@ void serverSetup() {
});

#if (ONLYPIDSCALE == 1 || BREWMODE == 2)
server.on("/toggleTare", HTTP_POST, [](AsyncWebServerRequest *request) {
int tare = flipUintValue(tareON);
server.on("/toggleTareScale", HTTP_POST, [](AsyncWebServerRequest *request) {
int tare = flipUintValue(scaleTareOn);

setTare(tare);
debugPrintf("Toggle tare mode: %i \n", tare);
setScaleTare(tare);
debugPrintf("Toggle scale tare mode: %i \n", tare);

request->redirect("/");
});

server.on("/toggleCalibration", HTTP_POST, [](AsyncWebServerRequest *request) {
int calibrate = flipUintValue(calibrationON);
server.on("/toggleScaleCalibration", HTTP_POST, [](AsyncWebServerRequest *request) {
int scaleCalibrate = flipUintValue(scaleCalibrationOn);

setCalibration(calibrate);
debugPrintf("Toggle calibration mode: %i \n", calibrate);
setScaleCalibration(scaleCalibrate);
debugPrintf("Toggle scale calibration mode: %i \n", scaleCalibrate);

request->redirect("/");
});
Expand Down
5 changes: 3 additions & 2 deletions src/MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void assignMQTTParam(char *param, double value) {
*(float *)var->ptr = value;
mqtt_publish(param, number2string(value), true);
break;

case kUInt8:
*(uint8_t *)var->ptr = value;

Expand Down Expand Up @@ -535,8 +536,8 @@ int sendHASSIODiscoveryMsg() {
DiscoveryObject startUsePonM = GenerateSwitchDevice("startUsePonM", "Use PonM");

// Button Devices
DiscoveryObject scaleCalibrateButton = GenerateButtonDevice("calibrationON", "Calibrate Scale");
DiscoveryObject scaleTareButton = GenerateButtonDevice("tareON", "Tare Scale");
DiscoveryObject scaleCalibrateButton = GenerateButtonDevice("scaleCalibrationOn", "Calibrate Scale");
DiscoveryObject scaleTareButton = GenerateButtonDevice("scaleTareOn", "Tare Scale");


std::vector<DiscoveryObject> discoveryObjects = {
Expand Down
5 changes: 1 addition & 4 deletions src/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef struct __attribute__((packed)) {
uint8_t freeToUse6[21];
uint8_t pidBdOn;
double pidKpBd;
#if SINGLE_HX711 == 1
#if SCALE_TYPE == 1
uint8_t freeToUse7[2];
#else
float scale2Calibration;
Expand Down Expand Up @@ -92,7 +92,6 @@ static const sto_data_t itemDefaults PROGMEM = {
0, // STO_ITEM_USE_PID_BD
AGGBKP, // STO_ITEM_PID_KP_BD
SCALE2_CALIBRATION_FACTOR, //STO_ITEM_SCALE2_CALIBRATION_FACTOR
// {0xFF, 0xFF}, // free to use
AGGBTN, // STO_ITEM_PID_TN_BD
{0xFF, 0xFF}, // free to use
AGGBTV, // STO_ITEM_PID_TV_BD
Expand Down Expand Up @@ -284,12 +283,10 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize =
size = STRUCT_MEMBER_SIZE(sto_data_t,scaleCalibration);
break;

#if SINGLE_HX711 == 0
case STO_ITEM_SCALE2_CALIBRATION_FACTOR:
addr = offsetof(sto_data_t,scale2Calibration );
size = STRUCT_MEMBER_SIZE(sto_data_t,scale2Calibration);
break;
#endif

case STO_ITEM_SCALE_KNOWN_WEIGHT:
addr = offsetof(sto_data_t,scaleKnownWeight );
Expand Down
6 changes: 3 additions & 3 deletions src/brewvoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ boolean brewPIDDisabled = false; // is PID disabled for delay

// Shot timer with or without scale
#if (ONLYPIDSCALE == 1 || BREWMODE == 2)
boolean calibrationON = 0;
boolean tareON = 0;
boolean scaleCalibrationOn = 0;
boolean scaleTareOn = 0;
int shottimerCounter = 10 ;
float calibrationValue = SCALE_CALIBRATION_FACTOR; // use calibration example to get value
float weight = 0; // value from HX711
Expand All @@ -62,7 +62,7 @@ boolean brewPIDDisabled = false; // is PID disabled for delay
const unsigned long intervalWeight = 200; // weight scale
unsigned long previousMillisScale; // initialisation at the end of init()
HX711_ADC LoadCell(PIN_HXDAT, PIN_HXCLK);
#if SINGLE_HX711 == 0
#if SCALE_TYPE == 0
HX711_ADC LoadCell2(PIN_HXDAT2, PIN_HXCLK);
#endif
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ int writeSysParamsToStorage(void);
#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
#if SINGLE_HX711 == 0
#define SCALE2_CALIBRATION_FACTOR 1.00 // Raw data is divided by this value to convert to readable data
#endif
#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)
Expand Down
2 changes: 1 addition & 1 deletion src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void displayShottimer(void) {
u8g2.drawXBMP(-1, 11, Brew_Cup_Logo_width, Brew_Cup_Logo_height, Brew_Cup_Logo);
u8g2.setFont(u8g2_font_profont22_tf);
u8g2.setCursor(64, 15);
u8g2.print(lastBrewTime/1000, 1);
u8g2.print(lastBrewTime / 1000, 1);
u8g2.print("s");
u8g2.setCursor(64, 38);
u8g2.print(weightBrew, 1);
Expand Down
36 changes: 13 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ bool coolingFlushDetectedQM = false;
void setSteamMode(int steamMode);
void setPidStatus(int pidStatus);
void setBackflush(int backflush);
void setTare(int tare);
void setCalibration(int tare);
void setScaleTare(int tare);
void setScaleCalibration(int tare);
void setNormalPIDTunings();
void setBDPIDTunings();
void loopcalibrate();
Expand Down Expand Up @@ -186,9 +186,7 @@ double brewTempOffset = TEMPOFFSET;
double setpoint = brewSetpoint;
double steamSetpoint = STEAMSETPOINT;
float scaleCalibration = SCALE_CALIBRATION_FACTOR;
#if SINGLE_HX711 == 0
float scale2Calibration = SCALE_CALIBRATION_FACTOR;
#endif
float scaleKnownWeight = SCALE_KNOWN_WEIGHT;
uint8_t usePonM = 0; // 1 = use PonM for cold start PID, 0 = use normal PID for cold start
double steamKp = STEAMKP;
Expand Down Expand Up @@ -253,9 +251,7 @@ SysPara<double> sysParaWeightSetpoint(&weightSetpoint, WEIGHTSETPOINT_MIN, WEIGH
SysPara<uint8_t> sysParaStandbyModeOn(&standbyModeOn, 0, 1, STO_ITEM_STANDBY_MODE_ON);
SysPara<double> sysParaStandbyModeTime(&standbyModeTime, STANDBY_MODE_TIME_MIN, STANDBY_MODE_TIME_MAX, STO_ITEM_STANDBY_MODE_TIME);
SysPara<float> sysParaScaleCalibration(&scaleCalibration, -100000, 100000, STO_ITEM_SCALE_CALIBRATION_FACTOR);
#if SINGLE_HX711 == 0
SysPara<float> sysParaScale2Calibration(&scale2Calibration, -100000, 100000, STO_ITEM_SCALE2_CALIBRATION_FACTOR);
#endif
SysPara<float> sysParaScaleKnownWeight(&scaleKnownWeight, 0, 2000, STO_ITEM_SCALE_KNOWN_WEIGHT);

// Other variables
Expand Down Expand Up @@ -346,8 +342,8 @@ enum SectionNames {
sPIDSection,
sTempSection,
sBDSection,
sPowerSection,
sScaleSection,
sPowerSection,
sOtherSection
};

Expand Down Expand Up @@ -1968,7 +1964,7 @@ void setup() {
.show = [] { return false; },
.minValue = 0,
.maxValue = 1,
.ptr = (void *)&tareON
.ptr = (void *)&scaleTareOn
};

editableVars["CALIBRATION_ON"] = {
Expand All @@ -1981,7 +1977,7 @@ void setup() {
.show = [] { return false; },
.minValue = 0,
.maxValue = 1,
.ptr = (void *)&calibrationON
.ptr = (void *)&scaleCalibrationOn
};

editableVars["SCALE_KNOWN_WEIGHT"] = {
Expand Down Expand Up @@ -2010,20 +2006,18 @@ void setup() {
.ptr = (void *)&scaleCalibration
};

#if SINGLE_HX711 == 0
editableVars["SCALE2_CALIBRATION"] = {
.displayName = F("Calibration factor scale 2"),
.hasHelpText = false,
.helpText = "",
.type = kFloat,
.section = sScaleSection,
.position = 32,
.show = [] { return true; },
.show = [] { return SCALE_TYPE == 0; },
.minValue = -100000,
.maxValue = 100000,
.ptr = (void *)&scale2Calibration
};
#endif
#endif

editableVars["VERSION"] = {
Expand Down Expand Up @@ -2071,12 +2065,12 @@ void setup() {
if (ONLYPIDSCALE == 1 || BREWMODE == 2) {
mqttVars["weightSetpoint"] = []{ return &editableVars.at("SCALE_WEIGHTSETPOINT"); };
mqttVars["scaleCalibration"] = []{ return &editableVars.at("SCALE_CALIBRATION"); };
#if SINGLE_HX711 == 0
#if SCALE_TYPE == 0
mqttVars["scale2Calibration"] = []{ return &editableVars.at("SCALE2_CALIBRATION"); };
#endif
mqttVars["scaleKnownWeight"] = []{ return &editableVars.at("SCALE_KNOWN_WEIGHT"); };
mqttVars["tareON"] = []{ return &editableVars.at("TARE_ON"); };
mqttVars["calibrationON"] = []{ return &editableVars.at("CALIBRATION_ON"); };
mqttVars["scaleTareOn"] = []{ return &editableVars.at("TARE_ON"); };
mqttVars["scaleCalibrationOn"] = []{ return &editableVars.at("CALIBRATION_ON"); };
}

if (FEATURE_BREWDETECTION == 1) {
Expand Down Expand Up @@ -2576,12 +2570,12 @@ void setBackflush(int backflush) {
}

#if (ONLYPIDSCALE == 1 || BREWMODE == 2)
void setCalibration(int calibration) {
calibrationON = calibration;
void setScaleCalibration(int calibration) {
scaleCalibrationOn = calibration;
}

void setTare(int tare) {
tareON = tare;
void setScaleTare(int tare) {
scaleTareOn = tare;
}
#endif

Expand Down Expand Up @@ -2674,9 +2668,7 @@ int readSysParamsFromStorage(void) {
if (sysParaStandbyModeOn.getStorage() != 0) return -1;
if (sysParaStandbyModeTime.getStorage() != 0) return -1;
if (sysParaScaleCalibration.getStorage() != 0) return -1;
#if SINGLE_HX711 == 0
if (sysParaScale2Calibration.getStorage() != 0) return -1;
#endif
if (sysParaScaleKnownWeight.getStorage() != 0) return -1;

return 0;
Expand Down Expand Up @@ -2715,9 +2707,7 @@ int writeSysParamsToStorage(void) {
if (sysParaStandbyModeOn.setStorage() != 0) return -1;
if (sysParaStandbyModeTime.setStorage() != 0) return -1;
if (sysParaScaleCalibration.setStorage() != 0) return -1;
#if SINGLE_HX711 == 0
if (sysParaScale2Calibration.setStorage() != 0) return -1;
#endif
if (sysParaScaleKnownWeight.setStorage() != 0) return -1;

return storageCommit();
Expand Down
2 changes: 1 addition & 1 deletion src/pinmapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
* Bidirectional Pins
*/
#define PIN_I2CSCL 22
#define PIN_I2CSDA 21
#define PIN_I2CSDA 21
Loading

0 comments on commit 16c601f

Please sign in to comment.