Compare commits

..

No commits in common. "402e1f4e43a369f863c8c0f7c5d07365ce617b40" and "55d0548ea8f3435c0802b1aecf267d7612db12c1" have entirely different histories.

2 changed files with 11 additions and 1796 deletions

View File

@ -22,8 +22,7 @@ enum machine_state {
DEBOUNCE,
HEATING,
HOT,
BREWING_HOT,
BREWING_COLD,
BREWING,
COOLING,
PANIC_OVERHEAT,
};
@ -187,7 +186,7 @@ void proc_buttons(struct state *state, const struct input *input)
int red_min = 50;
int red_state = red_min;
unsigned long brewing_max_time = 3000UL; /* 3 seconds */
unsigned long brewing_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 */
@ -197,7 +196,7 @@ void proc_machine(struct state *st)
{
float temp = st->ntc_T;
int on = (st->btn[BTN_ON].state == RELEASED);
int brew_hot = (st->btn[BTN_HOT].state == PRESSED);
int hot = (st->btn[BTN_HOT].state == PRESSED);
Serial.print("t=");
Serial.print(millis());
@ -224,12 +223,7 @@ void proc_machine(struct state *st)
}
if (st->mstate == SLEEPING) {
/* 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) {
if (on) {
st->mstate = HEATING;
st->heating_t0 = millis();
Serial.println("heating");
@ -246,28 +240,20 @@ void proc_machine(struct state *st)
Serial.println("cannot heat, going to sleep");
}
} else if (st->mstate == HOT) {
if (brew_hot) {
st->mstate = BREWING_HOT;
if (hot) {
st->mstate = BREWING;
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_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) {
} else if (st->mstate == BREWING) {
if (millis() - st->brewing_t0 > brewing_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) {
@ -330,7 +316,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_HOT || st->mstate == BREWING_COLD) {
} else if (st->mstate == BREWING) {
setled(PIN_LED_RED, 0);
analogWrite(PIN_LED_GREEN, g);
if (g >= 255)
@ -347,7 +333,7 @@ output_leds(const struct state *st)
void
output_heater(const struct state *st)
{
if (st->mstate == HEATING || st->mstate == HOT || st->mstate == BREWING_HOT) {
if (st->mstate == HEATING || st->mstate == HOT || st->mstate == BREWING) {
if (st->ntc_T < TEMP_MIN)
relay(PIN_HEAT, ON);
else if (st->ntc_T > TEMP_MAX)
@ -360,7 +346,7 @@ output_heater(const struct state *st)
void
output_pump(const struct state *st)
{
if (st->mstate == BREWING_HOT || st->mstate == BREWING_COLD)
if (st->mstate == BREWING)
relay(PIN_PUMP, ON);
else
relay(PIN_PUMP, OFF);
@ -370,7 +356,6 @@ void do_output(const struct state *st)
{
output_leds(st);
output_heater(st);
output_pump(st);
}
void setup()

File diff suppressed because it is too large Load Diff