Commit 4ce0cc7f authored by Philippe Kalaf's avatar Philippe Kalaf

Added automatic steam stop after 5 minutes

Refactored brew code a bit
Steam only enabled when joystick is fired
parent d81e6943
......@@ -30,6 +30,12 @@
// Soft stop time
#define SOFT_STOP_TIME_S 7.0
// Steam timeout in seconds
#define STEAM_TIMEOUT 300.0
// Steam temperature
#define STEAM_TEMPERATURE 140.0
// Manage different brew modes and timings
#include "brewcontrol.h"
......@@ -67,6 +73,9 @@ BrewControl::BrewControl( PinName brew_pin,
// 9 bars is default
_target_shot_pressure = 9;
// this is used for steam mode to return to prev target temp when done
_prev_temp = 0;
_boiler_pid.setPIDGains(0.075, 0.1, 0.9);
_boiler_pid.setIntegratorLimits(0, 1);
......@@ -262,7 +271,7 @@ void BrewControl::_brew_worker()
{
_shot_clock = _shot_clock + BREW_WORKER_PERIOD;
if (_mode == MODE_PRE_INFUSE)
if (_state == PRE_INFUSING)
{
// First let's fill up the portafilter
if (_flow_sensor.read() <= PORTAFILTER_VOLUME && !_stop_preinfuse)
......@@ -286,8 +295,10 @@ void BrewControl::_brew_worker()
_stop_preinfuse = 0;
_pressure_sensor.start_count();
}
return;
}
else if(_mode == MODE_TIME)
if(_mode == MODE_TIME)
{
// Auto-adjust pressure to target
float error = _target_shot_pressure - get_current_pressure();
......@@ -299,7 +310,7 @@ void BrewControl::_brew_worker()
if(_shot_clock >= _target_shot_time)
soft_stop();
}
else if(_mode == MODE_VOLUME)
else if(_mode == MODE_YIELD)
{
// Auto-adjust pressure to target
float error = _target_shot_pressure - get_current_pressure();
......@@ -311,7 +322,7 @@ void BrewControl::_brew_worker()
if(_flow_sensor.read() >= _target_shot_volume)
soft_stop();
}
else if(_mode == MODE_FLOW_RATE)
else if(_mode == MODE_TIME_YIELD)
{
// Re-calculate target flowrate
_target_flow_rate = (_target_shot_volume - _flow_sensor.read())
......@@ -329,57 +340,54 @@ void BrewControl::_brew_worker()
else if(_mode == MODE_MANUAL)
{
}
else if(_mode == MODE_STEAM)
{
// automatically stop steaming after STEAM_TIMEOUT
if (_shot_clock >= STEAM_TIMEOUT)
_stop();
}
}
uint8_t BrewControl::start()
uint8_t BrewControl::start(uint8_t mode)
{
// We are already brewing, return brewing mode
if(_state) return _mode;
_state = BREWING;
_mode = mode;
// reset shot clock and flow sensor
_flow_sensor.reset_count();
_shot_clock = 0;
_brew_ticker.detach();
// We have 4 operating modes based on which values are set or unset
// Time mode - constant pressure, constant time, variable volume
if (_target_shot_time && !_target_shot_volume)
_mode = MODE_TIME;
// Volume mode - constant pressure, constant volume, variable time
else if(!_target_shot_time && _target_shot_volume)
_mode = MODE_VOLUME;
// Flowrate mode - constant volume, constant time, variable flow-rate
else if(_target_shot_time && _target_shot_volume)
_mode = MODE_FLOW_RATE;
// Manual on/off via start(), stop(), toggle()
else
_mode = MODE_MANUAL;
_state = BREWING;
// Let's save settings before we set pre-infuse mode
if (_preinfuse_time && _mode != MODE_MANUAL)
// only pre-infuse if set to > 0s and not in manual or steam mode
if (_preinfuse_time && _mode != MODE_MANUAL && _mode != MODE_STEAM)
{
_prev_mode = _mode;
_prev_pressure = get_pump_level();
_prev_pressure = get_pump_level();
// set pre-infuse mode
_mode = MODE_PRE_INFUSE;
_state = PRE_INFUSING;
// we pre-infuse at low pressure
_pump_control.set_level(45);
_pump_control.set_level(60);
}
// Turn on brewing circuits
_brew_switch = 1;
if(_mode == MODE_STEAM)
{
// save currently set temperature to return to it after steaming
_prev_temp = get_shot_temperature();
set_shot_temperature(STEAM_TEMPERATURE);
}
else
// Turn on brewing circuits
_brew_switch = 1;
// Run worker at defined period
if(_mode != MODE_MANUAL)
_brew_ticker.attach(callback(this, &BrewControl::_brew_worker),
BREW_WORKER_PERIOD);
_brew_ticker.attach(callback(this, &BrewControl::_brew_worker),
BREW_WORKER_PERIOD);
return _mode;
}
......@@ -400,10 +408,20 @@ void BrewControl::_stop()
set_shot_volume(0);
set_shot_time(0);
_flow_sensor.reset_count();
if(_prev_temp)
{
set_shot_temperature(_prev_temp);
_prev_temp = 0;
}
}
void BrewControl::soft_stop()
{
if (_mode == MODE_STEAM)
{
_stop();
return;
}
_pump_control.set_level(0);
_brew_ticker.detach();
_soft_stop_timer.attach(callback(this, &BrewControl::_stop),
......@@ -417,13 +435,13 @@ float BrewControl::get_average_pressure()
return _average_pressure;
}
uint8_t BrewControl::toggle()
uint8_t BrewControl::toggle(uint8_t mode)
{
if(_state == BREWING || _state == PRE_INFUSING)
soft_stop();
soft_stop();
else if(_state == STOPPED)
start();
start(mode);
return _state;
}
......
......@@ -27,16 +27,17 @@
#include "pressuresensor.h"
#define MODE_TIME 1
#define MODE_VOLUME 2
#define MODE_FLOW_RATE 3
#define MODE_YIELD 2
#define MODE_TIME_YIELD 3
#define MODE_MANUAL 4
#define MODE_PRE_INFUSE 5
#define MODE_STEAM 5
// Brew states
#define STOPPED 0
#define BREWING 1
#define PRE_INFUSING 2
#define SOFT_STOPPING 3
#define STEAMING 4
#define PORTAFILTER_VOLUME 100
......@@ -110,9 +111,9 @@ public:
/// Return 1 if currently brewing, 0 if not
uint8_t get_state();
/// Toggle brewing
uint8_t toggle();
uint8_t toggle(uint8_t mode);
/// Start brewing, this resets all live variables and based on set targets initiates the right brew mode, returns set mode
uint8_t start();
uint8_t start(uint8_t mode);
/// Stop brewing with reduced backflush
void soft_stop();
......@@ -143,7 +144,7 @@ private:
// Soft stop reduces backflush
Timeout _soft_stop_timer;
// Pressure Sensor
PressureSensor _pressure_sensor;
......@@ -155,6 +156,9 @@ private:
PwmOut _boiler_pwm;
PIDControl _boiler_pid;
float _latest_temp;
// Previous temp used for steam mode
float _prev_temp;
// Boiler state
bool _enable_boiler;
......
......@@ -104,11 +104,11 @@ BrewControl brew_control(p10, p15, p12, p13, p20, p25, p26);
#define L_BREW 3
#define M_BREW_SETTINGS 0
#define M_BREW_TIME 1
#define M_BREW_YIELD 2
#define M_BREW_TIME_YIELD 3
#define M_BREW_MANUAL 4
#define M_BREW_STEAM 5
#define M_BREW_TIME MODE_TIME
#define M_BREW_YIELD MODE_YIELD
#define M_BREW_TIME_YIELD MODE_TIME_YIELD
#define M_BREW_MANUAL MODE_MANUAL
#define M_BREW_STEAM MODE_STEAM
#define NUM_BREW_MENUS 6
......@@ -214,7 +214,7 @@ void draw_menu()
LCD.set_font((unsigned char*) Small_6);
if (menu_level == L_BREW)
{
// Invert screen while brewing
// Invert screen while brewing or steaming
if (state)
LCD.invert(1);
if (active_menu == M_BREW_MANUAL)
......@@ -247,7 +247,10 @@ void draw_menu()
if (state == BREWING)
{
LCD.locate(5,23);
LCD.printf("BREW");
if (active_menu == M_BREW_STEAM)
LCD.printf("HOT");
else
LCD.printf("BREW");
}
else if (state == PRE_INFUSING)
{
......@@ -363,7 +366,7 @@ void menu_handler()
// set brew mode settings
set_params(active_menu);
}
brew_control.toggle();
brew_control.toggle(active_menu);
break;
}
}
......@@ -385,17 +388,11 @@ void menu_handler()
[conversion_table[edit_mode-1][0]]
[conversion_table[edit_mode-1][1]]--;
break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
// skip sub-menu for manual mode
case L_BREW: // skip sub-menu for manual or steam mode
if(active_menu == M_BREW_MANUAL || active_menu == M_BREW_STEAM)
menu_level = L_MENU;
else if(active_menu == M_BREW_STEAM)
{
// Put temperature back to previous setting when leaving steam mode
// TODO flow some water to cool things down faster?
brew_control.set_shot_temperature(brew_params[0][0][0]);
menu_level = L_MENU;
}
else
// only exit brew menu if not in brewing mode
else if(!brew_control.get_state())
menu_level = L_MENU_SUB;
break;
}
......@@ -426,8 +423,8 @@ void menu_handler()
menu_level = L_BREW;
else if(active_menu == M_BREW_STEAM)
{
// skip sub-menu for steam mode
menu_level = L_BREW;
brew_control.set_shot_temperature(140);
}
else
menu_level = L_MENU_SUB;
......@@ -554,7 +551,7 @@ int main()
{
brew_control.set_shot_volume(0);
brew_control.set_shot_time(0);
brew_control.toggle();
brew_control.toggle(MODE_MANUAL);
pc.printf("brew to %d\n", brew_control.get_state());
}
......@@ -572,7 +569,7 @@ int main()
else if(c == 'z')
{
brew_control.set_shot_volume(target_volume);
brew_control.start();
brew_control.start(MODE_YIELD);
}
// w and s to set target temperature
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment