Skip to content

Commit

Permalink
adding Trigger for Steammode
Browse files Browse the repository at this point in the history
Steamswitch has now 3 modes:
off, switch or trigger
removed double pinmode declaration for Steamswitch
  • Loading branch information
LoQue90 committed Oct 1, 2023
1 parent de9f21a commit b4316fe
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ void refreshTemp() {

#include "brewvoid.h"
#include "powerswitchvoid.h"
#include "steamswitchvoid.h"
#include "scalevoid.h"

/**
Expand Down Expand Up @@ -857,15 +858,6 @@ float filterPressureValue(float input) {
* @brief steamON & Quickmill
*/
void checkSteamON() {
// check digital GIPO
if (digitalRead(PIN_STEAMSWITCH) == HIGH) {
steamON = 1;
}

// if activated via web interface then steamFirstON == 1, prevent override
if (digitalRead(PIN_STEAMSWITCH) == LOW && steamFirstON == 0) {
steamON = 0;
}

// monitor QuickMill thermoblock steam-mode
if (machine == QuickMill) {
Expand Down Expand Up @@ -2016,14 +2008,18 @@ void setup() {
pinMode(PIN_VALVE, OUTPUT);
pinMode(PIN_PUMP, OUTPUT);
pinMode(PIN_HEATER, OUTPUT);
pinMode(PIN_STEAMSWITCH, INPUT);
digitalWrite(PIN_VALVE, relayOFF);
digitalWrite(PIN_PUMP, relayOFF);
digitalWrite(PIN_HEATER, LOW);

// IF POWERSWITCH is connected
if (POWERSWITCHTYPE > 0) {
pinMode(PIN_POWERSWITCH, INPUT);
pinMode(PIN_POWERSWITCH, INPUT_PULLDOWN);
}

// IF STEAMSWITCH is connected
if (STEAMSWITCHTYPE > 0) {
pinMode(PIN_STEAMSWITCH, INPUT_PULLDOWN);
}

// IF Voltage sensor selected
Expand All @@ -2038,8 +2034,6 @@ void setup() {
pinMode(PIN_STATUSLED, OUTPUT);
}

pinMode(PIN_STEAMSWITCH, INPUT_PULLDOWN);

#if OLED_DISPLAY != 0
u8g2.setI2CAddress(oled_i2c * 2);
u8g2.begin();
Expand Down Expand Up @@ -2072,8 +2066,7 @@ void setup() {
mqtt.setServer(mqtt_server_ip, mqtt_server_port);
mqtt.setCallback(mqtt_callback);
checkMQTT();
#if MQTT_HASSIO_SUPPORT == 1
// Send Home Assistant MQTT discovery messages
#if MQTT_HASSIO_SUPPORT == 1 // Send Home Assistant MQTT discovery messages
sendHASSIODiscoveryMsg();
#endif
}
Expand Down Expand Up @@ -2239,11 +2232,13 @@ void looppid() {
checkSteamON();
setEmergencyStopTemp();
checkpowerswitch();
handleMachineState();
checksteamswitch();

if (standbyModeOn && machineState != kStandby) {
updateStandbyTimer();
}

handleMachineState(); // update machineState

if (INFLUXDB == 1 && offlineMode == 0 ) {
sendInflux();
Expand Down
61 changes: 61 additions & 0 deletions src/steamswitchvoid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file steamswitchvoid.h
*
* @brief
*/

/**
* @brief Digtalswitch input pin for STEAM SWITCH
*/

int laststeamswitchTrigger = LOW; // the previous reading from the input pin
int buttonStateSteamTrigger; // the current reading from the input pin
unsigned long lastDebounceTimeSteamTrigger = 0; // the last time the output pin was toggled
unsigned long debounceDelaySteamTrigger = 50; // the debounce time; increase if the output flickers

void checksteamswitch() {
#if STEAMSWITCHTYPE == 1
// Set steamON to 1 when steamswitch is HIGH
if (digitalRead(PIN_STEAMSWITCH) == HIGH) {
steamON = 1;
}

// if activated via web interface then steamFirstON == 1, prevent override
if (digitalRead(PIN_STEAMSWITCH) == LOW && steamFirstON == 0) {
steamON = 0;
}
#endif

#if STEAMSWITCHTYPE == 2 // TRIGGER
int reading = digitalRead(PIN_STEAMSWITCH);

if (reading != laststeamswitchTrigger) {
// reset the debouncing timer
lastDebounceTimeSteamTrigger = millis();
}

if ((millis() - lastDebounceTimeSteamTrigger) > debounceDelaySteamTrigger) {
// 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 != buttonStateSteamTrigger) {
buttonStateSteamTrigger = reading;

// only toggle heating power if the new button state is HIGH
if (buttonStateSteamTrigger == HIGH) {
if (steamON == 0) {
Serial.println("Turn Steam ON");
steamON = 1;
} else {
Serial.println("Turn Steam OFF");
steamON = 0;
}
}
}
}

laststeamswitchTrigger = reading;

#endif
}
1 change: 1 addition & 0 deletions src/userConfig_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum MACHINE {
#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 POWERSWITCHTYPE 0 // 0 = no switch connected, 1 = normal Switch, 2 = Trigger Switch
#define STEAMSWITCHTYPE 0 // 0 = no switch connected, 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 b4316fe

Please sign in to comment.