Skip to content

Commit

Permalink
rename Feature_Water_Sens
Browse files Browse the repository at this point in the history
rename water tank sensor in total
-> FEATURE_WATERTANKSENSOR
-> waterTankFull/waterTankEmpty
-> kWaterTankEmpty
  • Loading branch information
LoQue90 committed Sep 15, 2024
1 parent 8d2c083 commit 22af930
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 94 deletions.
6 changes: 3 additions & 3 deletions src/brewHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void checkbrewswitch() {
// Convert momentary brew switch input to brew switch state
switch (brewSwitchState) {
case kBrewSwitchIdle:
if (currBrewSwitchStateMomentary == HIGH && machineState != kWaterEmpty) {
if (currBrewSwitchStateMomentary == HIGH && machineState != kWaterTankEmpty) {
brewSwitchState = kBrewSwitchBrew;
LOG(DEBUG, "brewSwitchState = kBrewSwitchIdle; waiting for brew switch input");
}
Expand All @@ -106,7 +106,7 @@ void checkbrewswitch() {
}

// Brew switch more than brewSwitchMomentaryLongPress pressed - start flushing
if (currBrewSwitchStateMomentary == HIGH && brewSwitch->longPressDetected() && machineState != kWaterEmpty) {
if (currBrewSwitchStateMomentary == HIGH && brewSwitch->longPressDetected() && machineState != kWaterTankEmpty) {
brewSwitchState = kBrewSwitchFlushOff;
valveRelay.on();
pumpRelay.on();
Expand Down Expand Up @@ -263,7 +263,7 @@ void brew() {
// state machine for brew
switch (currBrewState) {
case kBrewIdle: // waiting step for brew switch turning on
if (currStateBrewSwitch == HIGH && backflushState == 10 && backflushOn == 0 && brewSwitchWasOff && machineState != kWaterEmpty) {
if (currStateBrewSwitch == HIGH && backflushState == 10 && backflushOn == 0 && brewSwitchWasOff && machineState != kWaterTankEmpty) {
startingTime = millis();

if (preinfusionPause == 0 || preinfusion == 0) {
Expand Down
40 changes: 20 additions & 20 deletions src/display/bitmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

#pragma once

#define CleverCoffee_Logo_width 40
#define CleverCoffee_Logo_height 40
#define Rancilio_Silvia_Logo_width 52
#define Rancilio_Silvia_Logo_height 49
#define Gaggia_Classic_Logo_width 46
#define Gaggia_Classic_Logo_height 49
#define Heating_Logo_width 40
#define Heating_Logo_height 40
#define Off_Logo_width 52
#define Off_Logo_height 53
#define Steam_Logo_width 40
#define Steam_Logo_height 40
#define Brew_Cup_Logo_width 40
#define Brew_Cup_Logo_height 40
#define Water_Empty_Logo_width 47
#define Water_Empty_Logo_height 64
#define Manual_Flush_Logo_width 40
#define Manual_Flush_Logo_height 40
#define CleverCoffee_Logo_width 40
#define CleverCoffee_Logo_height 40
#define Rancilio_Silvia_Logo_width 52
#define Rancilio_Silvia_Logo_height 49
#define Gaggia_Classic_Logo_width 46
#define Gaggia_Classic_Logo_height 49
#define Heating_Logo_width 40
#define Heating_Logo_height 40
#define Off_Logo_width 52
#define Off_Logo_height 53
#define Steam_Logo_width 40
#define Steam_Logo_height 40
#define Brew_Cup_Logo_width 40
#define Brew_Cup_Logo_height 40
#define Water_Tank_Empty_Logo_width 47
#define Water_Tank_Empty_Logo_height 64
#define Manual_Flush_Logo_width 40
#define Manual_Flush_Logo_height 40

// clang-format off

Expand All @@ -50,7 +50,7 @@ static const unsigned char Antenna_NOK_Icon[] U8X8_PROGMEM = {
B10001000
};

static const unsigned char Water_Empty_Icon[] U8X8_PROGMEM = {
static const unsigned char Water_Tank_Empty_Icon[] U8X8_PROGMEM = {
B00001001,
B01001010,
B00011100,
Expand Down Expand Up @@ -176,7 +176,7 @@ static const unsigned char Brew_Cup_Logo[] U8X8_PROGMEM = {
0xff, 0xff, 0x07, 0xf8, 0xff, 0xff, 0xff, 0x03
};

static const unsigned char Water_Empty_Logo[] U8X8_PROGMEM = {
static const unsigned char Water_Tank_Empty_Logo[] U8X8_PROGMEM = {
0x00,0x00,0xfc,0x07,0x00,0x00,0x00,0x80,0xff,0x3f,0x00,0x00,0x00,0xe0,
0x07,0xfc,0x00,0x00,0x00,0xf0,0x00,0xe0,0x01,0x00,0x00,0x3c,0xf0,0x81,
0x03,0x00,0x00,0x1e,0xfe,0x0f,0x07,0x00,0x00,0x87,0x1f,0x3f,0x0e,0x00,
Expand Down
8 changes: 4 additions & 4 deletions src/display/displayCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void u8g2_prepare(void) {
* @brief Draw a water empty icon at the given coordinates if water supply is low
*/
void displayWaterIcon(int x, int y) {
if (!waterFull) {
u8g2.drawXBMP(x, y, 8, 8, Water_Empty_Icon);
if (!waterTankFull) {
u8g2.drawXBMP(x, y, 8, 8, Water_Tank_Empty_Icon);
}
}

Expand Down Expand Up @@ -350,9 +350,9 @@ bool displayMachineState() {
return true;
}
// Water empty
else if (machineState == kWaterEmpty && brewSwitchState != kBrewSwitchFlushOff) {
else if (machineState == kWaterTankEmpty && brewSwitchState != kBrewSwitchFlushOff) {
u8g2.clearBuffer();
u8g2.drawXBMP(45, 0, Water_Empty_Logo_width, Water_Empty_Logo_height, Water_Empty_Logo);
u8g2.drawXBMP(45, 0, Water_Tank_Empty_Logo_width, Water_Tank_Empty_Logo_height, Water_Tank_Empty_Logo);
u8g2.setFont(u8g2_font_profont11_tf);
u8g2.sendBuffer();
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/hardware/pinmapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#define PIN_ROTARY_SW 5 // Rotary encoder switch

// Sensors
#define PIN_TEMPSENSOR 16
#define PIN_WATERSENSOR 23
#define PIN_HXDAT 32 // Brew scale data pin 1
#define PIN_HXDAT2 25 // Brew scale data pin 2
#define PIN_HXCLK 33 // Brew scale clock pin
#define PIN_TEMPSENSOR 16
#define PIN_WATERTANKSENSOR 23
#define PIN_HXDAT 32 // Brew scale data pin 1
#define PIN_HXDAT2 25 // Brew scale data pin 2
#define PIN_HXCLK 33 // Brew scale clock pin

/**
* Output pins
Expand Down
80 changes: 40 additions & 40 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum MachineState {
kBrewDetectionTrailing = 35,
kSteam = 40,
kBackflush = 50,
kWaterEmpty = 70,
kWaterTankEmpty = 70,
kEmergencyStop = 80,
kPidDisabled = 90,
kStandby = 95,
Expand Down Expand Up @@ -148,7 +148,7 @@ const unsigned long intervalPressure = 100;
unsigned long previousMillisPressure; // initialisation at the end of init()
#endif

Switch* waterSensor;
Switch* waterTankSensor;

GPIOPin* statusLedPin;
GPIOPin* brewLedPin;
Expand Down Expand Up @@ -184,7 +184,7 @@ void setBDPIDTunings();
void loopcalibrate();
void looppid();
void loopLED();
void checkWater();
void checkWaterTank();
void printMachineState();
char const* machinestateEnumToString(MachineState machineState);
void initSteamQM();
Expand Down Expand Up @@ -284,11 +284,11 @@ int flushCycles = 0; // number of active flush cycles

int backflushState = 10;

// Water sensor
boolean waterFull = true;
Timer loopWater(&checkWater, 200); // Check water level every 200 ms
int waterCheckConsecutiveReads = 0; // Counter for consecutive readings of water sensor
const int waterCountsNeeded = 3; // Number of same readings to change water sensing
// Water tank sensor
boolean waterTankFull = true;
Timer loopWaterTank(&checkWaterTank, 200); // Check water tank level every 200 ms
int waterTankCheckConsecutiveReads = 0; // Counter for consecutive readings of water tank sensor
const int waterTankCountsNeeded = 3; // Number of same readings to change water tank sensing

// Moving average for software brew detection
unsigned long timeBrewDetection = 0;
Expand Down Expand Up @@ -709,8 +709,8 @@ boolean checkSteamOffQM() {
void handleMachineState() {
switch (machineState) {
case kInit:
if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand Down Expand Up @@ -766,8 +766,8 @@ void handleMachineState() {
machineState = kPidDisabled;
}

if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand Down Expand Up @@ -837,8 +837,8 @@ void handleMachineState() {
machineState = kPidDisabled;
}

if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand Down Expand Up @@ -874,8 +874,8 @@ void handleMachineState() {
machineState = kPidDisabled;
}

if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand All @@ -900,8 +900,8 @@ void handleMachineState() {
machineState = kPidDisabled;
}

if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand All @@ -922,8 +922,8 @@ void handleMachineState() {
machineState = kPidDisabled;
}

if (!waterFull && (backflushState == kBackflushWaitBrewswitchOn || backflushState == kBackflushWaitBrewswitchOff)) {
machineState = kWaterEmpty;
if (!waterTankFull && (backflushState == kBackflushWaitBrewswitchOn || backflushState == kBackflushWaitBrewswitchOff)) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand All @@ -945,8 +945,8 @@ void handleMachineState() {
}
break;

case kWaterEmpty:
if (waterFull) {
case kWaterTankEmpty:
if (waterTankFull) {
machineState = kPidNormal;
}

Expand All @@ -965,8 +965,8 @@ void handleMachineState() {
machineState = kPidNormal;
}

if (!waterFull) {
machineState = kWaterEmpty;
if (!waterTankFull) {
machineState = kWaterTankEmpty;
}

if (tempSensor->hasError()) {
Expand Down Expand Up @@ -1042,8 +1042,8 @@ char const* machinestateEnumToString(MachineState machineState) {
return "Steam";
case kBackflush:
return "Backflush";
case kWaterEmpty:
return "Water Empty";
case kWaterTankEmpty:
return "Water Tank Empty";
case kEmergencyStop:
return "Emergency Stop";
case kPidDisabled:
Expand Down Expand Up @@ -1634,8 +1634,8 @@ void setup() {
// TODO Addressable LEDs
}

if (FEATURE_WATER_SENS == 1) {
waterSensor = new IOSwitch(PIN_WATERSENSOR, (WATER_SENS_TYPE == Switch::NORMALLY_OPEN ? GPIOPin::IN_PULLDOWN : GPIOPin::IN_PULLUP), Switch::TOGGLE, WATER_SENS_TYPE);
if (FEATURE_WATERTANKSENSOR == 1) {
waterTankSensor = new IOSwitch(PIN_WATERTANKSENSOR, (WATERTANKSENSOR_TYPE == Switch::NORMALLY_OPEN ? GPIOPin::IN_PULLDOWN : GPIOPin::IN_PULLUP), Switch::TOGGLE, WATERTANKSENSOR_TYPE);
}

#if OLED_DISPLAY != 0
Expand Down Expand Up @@ -1732,8 +1732,8 @@ void loop() {
// Accept potential connections for remote logging
Logger::update();

// Update water sensor
loopWater();
// Update water tank sensor
loopWaterTank();

// Update PID settings & machine state
looppid();
Expand Down Expand Up @@ -1861,7 +1861,7 @@ void looppid() {
printDisplayTimer();
#endif

if (machineState == kPidDisabled || machineState == kWaterEmpty || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || brewPIDDisabled) {
if (machineState == kPidDisabled || machineState == kWaterTankEmpty || machineState == kSensorError || machineState == kEmergencyStop || machineState == kEepromError || machineState == kStandby || brewPIDDisabled) {
if (bPID.GetMode() == 1) {
// Force PID shutdown
bPID.SetMode(0);
Expand Down Expand Up @@ -1956,20 +1956,20 @@ void loopLED() {
}
}

void checkWater() {
if (FEATURE_WATER_SENS != 1) {
void checkWaterTank() {
if (FEATURE_WATERTANKSENSOR != 1) {
return;
}

bool isWaterDetected = waterSensor->isPressed();
bool isWaterDetected = waterTankSensor->isPressed();

if (isWaterDetected && !waterFull) {
waterFull = true;
LOG(INFO, "Water full");
if (isWaterDetected && !waterTankFull) {
waterTankFull = true;
LOG(INFO, "Water tank full");
}
else if (!isWaterDetected && waterFull) {
waterFull = false;
LOG(WARNING, "Water empty");
else if (!isWaterDetected && waterTankFull) {
waterTankFull = false;
LOG(WARNING, "Water tank empty");
}
}

Expand Down
44 changes: 22 additions & 22 deletions src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ enum MACHINE {
#define WIFICONNECTIONDELAY 10000 // delay between reconnects in ms

// PID & Hardware
#define FEATURE_BREWCONTROL 0 // 0 = deactivated, 1 = activated
#define FEATURE_BREWDETECTION 1 // 0 = deactivated, 1 = activated
#define BREWDETECTION_TYPE 1 // 1 = Software (FEATURE_BREWCONTROL 0), 2 = Hardware (FEATURE_BREWCONTROL 1), 3 = Optocoupler (FEATURE_BREWCONTROL 0)
#define FEATURE_POWERSWITCH 0 // 0 = deactivated, 1 = activated
#define POWERSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define POWERSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define FEATURE_BREWSWITCH 0 // 0 = deactivated, 1 = activated
#define BREWSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define BREWSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define FEATURE_STEAMSWITCH 0 // 0 = deactivated, 1 = activated
#define STEAMSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define OPTOCOUPLER_TYPE HIGH // BREWDETECTION 3 configuration; HIGH or LOW trigger optocoupler
#define STEAMSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define HEATER_SSR_TYPE Relay::HIGH_TRIGGER // HIGH_TRIGGER = relay switches when input is HIGH, vice versa for LOW_TRIGGER
#define PUMP_VALVE_SSR_TYPE Relay::HIGH_TRIGGER // HIGH_TRIGGER = relay switches when input is HIGH, vice versa for LOW_TRIGGER
#define FEATURE_STATUS_LED 0 // Blink status LED when temp is in range, 0 = deactivated, 1 = activated
#define FEATURE_BREW_LED 0 // Turn on brew LED when brew is started, 0 = deactivated, 1 = activated
#define LED_TYPE LED::STANDARD // STANDARD_LED for an LED connected to a GPIO pin, WS2812 for adressable LEDs
#define FEATURE_WATER_SENS 0 // 0 = deactivated, 1 = activated
#define WATER_SENS_TYPE Switch::NORMALLY_CLOSED // Switch::NORMALLY_CLOSED for sensor XKC-Y25-NPN or Switch::NORMALLY_OPEN for XKC-Y25-PNP

#define FEATURE_PRESSURESENSOR 0 // 0 = deactivated, 1 = activated
#define FEATURE_BREWCONTROL 0 // 0 = deactivated, 1 = activated
#define FEATURE_BREWDETECTION 1 // 0 = deactivated, 1 = activated
#define BREWDETECTION_TYPE 1 // 1 = Software (FEATURE_BREWCONTROL 0), 2 = Hardware (FEATURE_BREWCONTROL 1), 3 = Optocoupler (FEATURE_BREWCONTROL 0)
#define FEATURE_POWERSWITCH 0 // 0 = deactivated, 1 = activated
#define POWERSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define POWERSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define FEATURE_BREWSWITCH 0 // 0 = deactivated, 1 = activated
#define BREWSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define BREWSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define FEATURE_STEAMSWITCH 0 // 0 = deactivated, 1 = activated
#define STEAMSWITCH_TYPE Switch::TOGGLE // Switch::TOGGLE or Switch::MOMENTARY (trigger)
#define OPTOCOUPLER_TYPE HIGH // BREWDETECTION 3 configuration; HIGH or LOW trigger optocoupler
#define STEAMSWITCH_MODE Switch::NORMALLY_OPEN // Switch::NORMALLY_OPEN or Switch::NORMALLY_CLOSED
#define HEATER_SSR_TYPE Relay::HIGH_TRIGGER // HIGH_TRIGGER = relay switches when input is HIGH, vice versa for LOW_TRIGGER
#define PUMP_VALVE_SSR_TYPE Relay::HIGH_TRIGGER // HIGH_TRIGGER = relay switches when input is HIGH, vice versa for LOW_TRIGGER
#define FEATURE_STATUS_LED 0 // Blink status LED when temp is in range, 0 = deactivated, 1 = activated
#define FEATURE_BREW_LED 0 // Turn on brew LED when brew is started, 0 = deactivated, 1 = activated
#define LED_TYPE LED::STANDARD // STANDARD_LED for an LED connected to a GPIO pin, WS2812 for adressable LEDs
#define FEATURE_WATERTANKSENSOR 0 // 0 = deactivated, 1 = activated
#define WATERTANKSENSOR_TYPE Switch::NORMALLY_CLOSED // Switch::NORMALLY_CLOSED for sensor XKC-Y25-NPN or Switch::NORMALLY_OPEN for XKC-Y25-PNP

#define FEATURE_PRESSURESENSOR 0 // 0 = deactivated, 1 = activated

// Brew Scale
#define FEATURE_SCALE 0 // 0 = deactivated, 1 = activated
Expand Down

0 comments on commit 22af930

Please sign in to comment.