Skip to content

Commit

Permalink
rebuild brew switch
Browse files Browse the repository at this point in the history
set steamswitch off, normal switch or trigger on website
  • Loading branch information
LoQue90 committed Feb 25, 2023
1 parent c044e77 commit 410cfd0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/EmbeddedWebserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void serverSetup();
void setEepromWriteFcn(int (*fcnPtr)(void));

// editable vars are specified in main.cpp
#define EDITABLE_VARS_LEN 29
#define EDITABLE_VARS_LEN 30
extern std::map<String, editable_t> editableVars;


Expand Down
7 changes: 7 additions & 0 deletions src/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct __attribute__((packed)) {
double steamkp;
double steamSetpoint;
uint8_t powerSwitchType;
uint8_t brewSwitchType;
uint8_t steamSwitchType;
} sto_data_t;

Expand Down Expand Up @@ -111,6 +112,7 @@ static const sto_data_t itemDefaults PROGMEM = {
STEAMKP, // STO_ITEM_PID_KP_STEAM
STEAMSETPOINT, // STO_ITEM_STEAM_SETPOINT
POWERSWITCHTYPE, // STO_ITEM_POWER_SWITCHTYPE
BREWSWITCHTYPE, // STO_ITEM_BREW_SWITCHTYPE
STEAMSWITCHTYPE // STO_ITEM_STEAM_SWITCHTYPE
};

Expand Down Expand Up @@ -269,6 +271,11 @@ static inline int32_t getItemAddr(sto_item_id_t itemId, uint16_t* maxItemSize =
size = STRUCT_MEMBER_SIZE(sto_data_t, powerSwitchType);
break;

case STO_ITEM_BREW_SWITCHTYPE:
addr = offsetof(sto_data_t, brewSwitchType);
size = STRUCT_MEMBER_SIZE(sto_data_t, brewSwitchType);
break;

case STO_ITEM_STEAM_SWITCHTYPE:
addr = offsetof(sto_data_t, steamSwitchType);
size = STRUCT_MEMBER_SIZE(sto_data_t, steamSwitchType);
Expand Down
1 change: 1 addition & 0 deletions src/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef enum
STO_ITEM_RESERVED_28, // reserved
STO_ITEM_RESERVED_29, // reserved
STO_ITEM_POWER_SWITCHTYPE, // Power Switch off, normal switch or trigger
STO_ITEM_BREW_SWITCHTYPE, // Brew Switch off, normal switch or trigger
STO_ITEM_STEAM_SWITCHTYPE, // Steam Switch off, normal switch or trigger


Expand Down
36 changes: 16 additions & 20 deletions src/brewvoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,33 @@


/**
* @brief Digtalswitch OR Read analog input pin for BREW SWITCH
* @brief Digtalswitch input pin for BREW SWITCH
*/
void checkbrewswitch() {
#if BREWSWITCHTYPE == 1
#if (PIN_BREWSWITCH > 0)
// Digital GIPO
brewswitch = digitalRead(PIN_BREWSWITCH);
#endif
#if BREWSWITCHTYPE == 1
brewswitch = digitalRead(PIN_BREWSWITCH);
#endif

#if BREWSWITCHTYPE == 2
#if (PIN_BREWSWITCH > 0)
int reading = digitalRead(PIN_BREWSWITCH);
#if BREWSWITCHTYPE == 2 // TRIGGER
int reading = digitalRead(PIN_BREWSWITCH);

if (reading != brewswitchTrigger) {
// reset the debouncing timer
lastDebounceTimeBrewTrigger = millis();
}
if (reading != brewswitchTrigger) {
// reset the debouncing timer
lastDebounceTimeBrewTrigger = millis();
}

if ((millis() - lastDebounceTimeBrewTrigger) > debounceDelayBrewTrigger) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
if ((millis() - lastDebounceTimeBrewTrigger) > debounceDelayBrewTrigger) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonStateBrewTrigger) {
buttonStateBrewTrigger = reading;
// if the button state has changed:
if (reading != buttonStateBrewTrigger) {
buttonStateBrewTrigger = reading;
}
}

brewswitchTrigger = reading;
#endif


// Convert trigger signal to brew switch state
switch (brewswitchTriggerCase) {
Expand Down
7 changes: 5 additions & 2 deletions src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ int writeSysParamsToStorage(void);
#define PRE_INFUSION_PAUSE_TIME 5 // pre-infusion pause time in seconds
#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 POWERSWITCHTYPE 0 // Steamswitch 0 = disable, 1 = normal switch 2 = trigger
#define STEAMSWITCHTYPE 0 // Steamswitch 0 = disable, 1 = normal switch 2 = trigger
#define POWERSWITCHTYPE 0 // Power switch 0 = disable, 1 = normal switch 2 = trigger
#define BREWSWITCHTYPE 0 // Brew switch 0 = disable, 1 = normal switch 2 = trigger
#define STEAMSWITCHTYPE 0 // Steam switch 0 = disable, 1 = normal switch 2 = trigger

// Backflush values
#define FILLTIME 3000 // time in ms the pump is running
Expand Down Expand Up @@ -73,6 +74,8 @@ int writeSysParamsToStorage(void);
#define STEAM_SETPOINT_MAX 140
#define POWER_SWITCHTYPE_MIN 0
#define POWER_SWITCHTYPE_MAX 2
#define BREW_SWITCHTYPE_MIN 0
#define BREW_SWITCHTYPE_MAX 2
#define STEAM_SWITCHTYPE_MIN 0
#define STEAM_SWITCHTYPE_MAX 2
#define BREW_TEMP_OFFSET_MIN 0
Expand Down
29 changes: 27 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ double preinfusion = PRE_INFUSION_TIME; // preinfusion time in s
double preinfusionpause = PRE_INFUSION_PAUSE_TIME; // preinfusion pause time in s
double weightSetpoint = SCALE_WEIGHTSETPOINT;
uint8_t powerSwitchType = POWERSWITCHTYPE;
uint8_t brewSwitchType = BREWSWITCHTYPE;
uint8_t steamSwitchType = STEAMSWITCHTYPE;

// PID - values for offline brew detection
Expand Down Expand Up @@ -229,6 +230,7 @@ SysPara<double> sysParaPidKpSteam(&steamKp, PID_KP_STEAM_MIN, PID_KP_STEAM_MAX,
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);
SysPara<uint8_t> sysParaPowerSwitchType(&powerSwitchType, POWER_SWITCHTYPE_MIN, POWER_SWITCHTYPE_MAX, STO_ITEM_POWER_SWITCHTYPE);
SysPara<uint8_t> sysParaBrewSwitchType(&brewSwitchType, BREW_SWITCHTYPE_MIN, BREW_SWITCHTYPE_MAX, STO_ITEM_BREW_SWITCHTYPE);
SysPara<uint8_t> sysParaSteamSwitchType(&steamSwitchType, STEAM_SWITCHTYPE_MIN, STEAM_SWITCHTYPE_MAX, STO_ITEM_STEAM_SWITCHTYPE);

// Other variables
Expand Down Expand Up @@ -1843,13 +1845,27 @@ void setup() {
.maxValue = POWER_SWITCHTYPE_MAX,
.ptr = (void*)&powerSwitchType
};

editableVars["BREW_SWITCHTYPE"] = {
.displayName = "Brew switch type",
.hasHelpText = true,
.helpText = F("0 = switch disabled; 1 = normal switch; 2 = trigger switch"),
.type = kUInt8,
.section = sTempSection,
.position = 29,
.show = [] { return true; },
.minValue = BREW_SWITCHTYPE_MIN,
.maxValue = BREW_SWITCHTYPE_MAX,
.ptr = (void*)&brewSwitchType
};

editableVars["STEAM_SWITCHTYPE"] = {
.displayName = "Steam switch type",
.hasHelpText = true,
.helpText = F("0 = switch disabled; 1 = normal switch; 2 = trigger switch"),
.type = kUInt8,
.section = sTempSection,
.position = 29,
.position = 30,
.show = [] { return true; },
.minValue = STEAM_SWITCHTYPE_MIN,
.maxValue = STEAM_SWITCHTYPE_MAX,
Expand Down Expand Up @@ -1911,8 +1927,10 @@ void setup() {

//read storage to get hardware switch types
sysParaPowerSwitchType.getStorage();
sysParaBrewSwitchType.getStorage();
sysParaSteamSwitchType.getStorage();
debugPrintf("PowerSwitchType.getStorage: %i ",powerSwitchType);
debugPrintf("BrewSwitchType.getStorage: %i ",brewSwitchType);
debugPrintf("SteamSwitchType.getStorage: %i ",steamSwitchType);

// Define trigger type
Expand Down Expand Up @@ -1945,6 +1963,11 @@ void setup() {
pinMode(PIN_POWERSWITCH, INPUT);
}

// If brew switch is enabled
if (brewSwitchType > 0) {
pinMode(PIN_BREWSWITCH, INPUT);
}

// If steam switch is enabled
if (steamSwitchType > 0) {
pinMode(PIN_STEAMSWITCH, INPUT);
Expand All @@ -1955,7 +1978,7 @@ void setup() {
pinMode(PIN_BREWSWITCH, PINMODEVOLTAGESENSOR);
}
else {
pinMode(PIN_BREWSWITCH, INPUT_PULLDOWN);
pinMode(PIN_BREWSWITCH, INPUT);
}

// If OLED display is enabled
Expand Down Expand Up @@ -2361,6 +2384,7 @@ int readSysParamsFromStorage(void) {
if (sysParaWeightSetpoint.getStorage() != 0) return -1;
if (sysParaWifiCredentialsSaved.getStorage() != 0) return -1;
if (sysParaPowerSwitchType.getStorage() != 0) return -1;
if (sysParaBrewSwitchType.getStorage() != 0) return -1;
if (sysParaSteamSwitchType.getStorage() != 0) return -1;

return 0;
Expand Down Expand Up @@ -2397,6 +2421,7 @@ int writeSysParamsToStorage(void) {
if (sysParaWeightSetpoint.setStorage() != 0) return -1;
if (sysParaWifiCredentialsSaved.setStorage() != 0) return -1;
if (sysParaPowerSwitchType.setStorage() != 0) return -1;
if (sysParaBrewSwitchType.setStorage() != 0) return -1;
if (sysParaSteamSwitchType.setStorage() != 0) return -1;

return storageCommit();
Expand Down
1 change: 0 additions & 1 deletion src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ enum MACHINE {
#define ONLYPIDSCALE 0 // 0 = off , 1 = OnlyPID with Scale
#define BREWMODE 1 // 1 = Brew by time (with preinfusion); 2 = Brew by weight (from scale)
#define BREWDETECTION 0 // 0 = off, 1 = Software (Onlypid 1), 2 = Hardware (Onlypid 0), 3 = Sensor/Hardware for Only PID
#define BREWSWITCHTYPE 1 // 1 = normal Switch, 2 = Trigger Switch
#define TRIGGERTYPE HIGH // LOW = low trigger, HIGH = high trigger relay for pump & valve
#define VOLTAGESENSORTYPE HIGH // BREWDETECTION 3 configuration
#define PINMODEVOLTAGESENSOR INPUT // Mode INPUT_PULLUP, INPUT or INPUT_PULLDOWN_16 (Only Pin 16)
Expand Down

0 comments on commit 410cfd0

Please sign in to comment.