Allow cold brewing with heater off

This commit is contained in:
Rodrigo Arias Mallo 2025-10-16 21:12:58 +02:00
parent 55d0548ea8
commit 14592c6f55

View File

@ -22,7 +22,8 @@ enum machine_state {
DEBOUNCE,
HEATING,
HOT,
BREWING,
BREWING_HOT,
BREWING_COLD,
COOLING,
PANIC_OVERHEAT,
};
@ -186,7 +187,7 @@ void proc_buttons(struct state *state, const struct input *input)
int red_min = 50;
int red_state = red_min;
unsigned long brewing_time = 3000UL; /* 3 seconds */
unsigned long brewing_max_time = 3000UL; /* 3 seconds */
unsigned long cooling_time = 3000UL; /* 3 seconds */
unsigned long overheat_time = 10000UL; /* 10 seconds */
unsigned long max_heating_time = 60000UL; /* 60 seconds */
@ -196,7 +197,7 @@ void proc_machine(struct state *st)
{
float temp = st->ntc_T;
int on = (st->btn[BTN_ON].state == RELEASED);
int hot = (st->btn[BTN_HOT].state == PRESSED);
int brew_hot = (st->btn[BTN_HOT].state == PRESSED);
Serial.print("t=");
Serial.print(millis());
@ -223,7 +224,12 @@ void proc_machine(struct state *st)
}
if (st->mstate == SLEEPING) {
if (on) {
/* Allow brewing cold at without turning the heater */
/* FIXME: Use the cold button instead */
if (brew_hot) {
st->mstate = BREWING_COLD;
Serial.println("brewing cold");
} else if (on) {
st->mstate = HEATING;
st->heating_t0 = millis();
Serial.println("heating");
@ -240,20 +246,28 @@ void proc_machine(struct state *st)
Serial.println("cannot heat, going to sleep");
}
} else if (st->mstate == HOT) {
if (hot) {
st->mstate = BREWING;
if (brew_hot) {
st->mstate = BREWING_HOT;
st->brewing_t0 = millis();
Serial.println("brewing");
} else if (millis() - st->hot_t0 > max_idle_time) {
st->mstate = SLEEPING;
Serial.println("idle timeout, going to sleep");
}
} else if (st->mstate == BREWING) {
if (millis() - st->brewing_t0 > brewing_time) {
} else if (st->mstate == BREWING_HOT) {
/* Stop brewing if no longer pressing the brew button or we
* exceed the brew max time */
if (!brew_hot || millis() - st->brewing_t0 > brewing_max_time) {
st->mstate = COOLING;
st->cooling_t0 = millis();
Serial.println("cooling");
}
} else if (st->mstate == BREWING_COLD) {
/* FIXME: Use cold button instead */
if (!brew_hot) {
st->mstate = SLEEPING;
Serial.println("going back to sleeping after cold brewing");
}
} else if (st->mstate == COOLING) {
/* TODO: Wait a bit and go back to heating */
if (millis() - st->cooling_t0 > cooling_time) {
@ -316,7 +330,7 @@ output_leds(const struct state *st)
} else if (st->mstate == PANIC_OVERHEAT) {
setled(PIN_LED_RED, 1);
setled(PIN_LED_GREEN, 0);
} else if (st->mstate == BREWING) {
} else if (st->mstate == BREWING_HOT || st->mstate == BREWING_COLD) {
setled(PIN_LED_RED, 0);
analogWrite(PIN_LED_GREEN, g);
if (g >= 255)
@ -333,7 +347,7 @@ output_leds(const struct state *st)
void
output_heater(const struct state *st)
{
if (st->mstate == HEATING || st->mstate == HOT || st->mstate == BREWING) {
if (st->mstate == HEATING || st->mstate == HOT || st->mstate == BREWING_HOT) {
if (st->ntc_T < TEMP_MIN)
relay(PIN_HEAT, ON);
else if (st->ntc_T > TEMP_MAX)
@ -346,7 +360,7 @@ output_heater(const struct state *st)
void
output_pump(const struct state *st)
{
if (st->mstate == BREWING)
if (st->mstate == BREWING_HOT || st->mstate == BREWING_COLD)
relay(PIN_PUMP, ON);
else
relay(PIN_PUMP, OFF);
@ -356,6 +370,7 @@ void do_output(const struct state *st)
{
output_leds(st);
output_heater(st);
output_pump(st);
}
void setup()