Commit a4e8d9f1 authored by Philippe Kalaf's avatar Philippe Kalaf

Fixed a bunch of bugs with menu functionality

up/down during manual flow controls flowrate/pressure
Flow rate return function to go return 0 when no flow
parent 70af792b
......@@ -35,6 +35,7 @@ BrewControl::BrewControl( PinName brew_pin,
PinName pump_control_pin,
PinName pressure_sensor_pin,
PinName temp_sensor_pin,
//PinName temp2_sensor_pin,
PinName boiler_pwm_pin
) :
_brew_switch(brew_pin, 0),
......@@ -42,6 +43,7 @@ BrewControl::BrewControl( PinName brew_pin,
_pump_control(zcd_input_pin, pump_control_pin),
_pressure_sensor(pressure_sensor_pin),
_temp_sensor(temp_sensor_pin),
//_temp2_sensor(temp2_sensor_pin),
_boiler_pwm(boiler_pwm_pin)
{
_preinfuse_time = 0;
......@@ -58,11 +60,24 @@ BrewControl::BrewControl( PinName brew_pin,
enable_boiler();
}
float BrewControl::get_current_temperature()
float BrewControl::get_current_temperature_side()
{
return _temp_sensor.read();
}
float BrewControl::get_current_temperature_top()
{
// return _temp2_sensor.read();
return 0;
}
float BrewControl::get_current_temperature()
{
//return (_temp_sensor.read() + _temp2_sensor.read())/2;
return get_current_temperature_side();
}
void BrewControl::set_shot_temperature(float shot_temp)
{
if (shot_temp <= 20)
......@@ -94,7 +109,7 @@ int BrewControl::get_shot_volume()
void BrewControl::boiler_pid_worker()
{
// take temperature measurement
float latestTemp = _temp_sensor.read();
float latestTemp = get_current_temperature();
double power = 0.0;
......@@ -181,7 +196,7 @@ void BrewControl::set_shot_time(int time)
// This is to set the wanted shot volume
void BrewControl::set_shot_volume(int volume)
{
if (volume > 0)
if (volume >= 0)
_target_shot_volume = volume;
}
......@@ -248,6 +263,9 @@ void BrewControl::brew_worker()
else if(_mode == MODE_PRESSURE)
{
}
else if(_mode == MODE_MANUAL)
{
}
}
uint8_t BrewControl::start()
......@@ -300,15 +318,23 @@ uint8_t BrewControl::start()
return _mode;
}
void BrewControl::toggle_solenoid()
{
if(_brew_switch)
_brew_switch = 0;
else
_brew_switch = 1;
}
void BrewControl::stop()
{
_state = 0;
_brew_switch = 0;
_shot_clock = 0;
set_shot_volume(0);
set_shot_time(0);
_flow_sensor.reset_count();
_brew_ticker.detach();
_shot_clock = 0;
}
bool BrewControl::toggle()
......
......@@ -45,6 +45,7 @@ public:
PinName pump_control_pin,
PinName pressure_sensor_pin,
PinName temp_sensor_pin,
//PinName temp2_sensor_pin,
PinName boiler_pwm_pin);
/// Set the target shot temperature in C
......@@ -53,6 +54,8 @@ public:
float get_shot_temperature();
/// Get the live temperature of water in the boiler in C
float get_current_temperature();
float get_current_temperature_side();
float get_current_temperature_top();
/// Set the target shot time in s
void set_shot_time(int time);
......@@ -104,6 +107,7 @@ public:
bool toggle_boiler();
PhaseControl *get_pump_control_ptr();
void toggle_solenoid();
private:
// Signal to turn on/off pump
......@@ -120,6 +124,7 @@ private:
// Temperature control
LMT01 _temp_sensor;
//LMT01 _temp2_sensor;
PwmOut _boiler_pwm;
PIDControl _boiler_pid;
float _latest_temp;
......
......@@ -55,5 +55,13 @@ void FHKSC::reset_count()
// flow rate in ml per second
float FHKSC::get_flow_rate()
{
return float(0.52 / (float(_interval_between_increments_us)/1000000));
}
\ No newline at end of file
int time_us = _flow_rate_timer.read_us();
// if we got no incremenet in 2 seconds, flowrate is 0
if (time_us - _time_last_increment_us > 2000000)
return 0;
if (_interval_between_increments_us)
return float(0.52 / (float(_interval_between_increments_us)/1000000));
else
return 0;
}
......@@ -61,11 +61,11 @@ Thread menu_thread;
Mutex lcd_mutex;
// Joystick for menu control
InterruptIn Fire(p14); // JS_PUSH
InterruptIn Up(p15); // JS_UP
InterruptIn Down(p12); // JS_DOWN
InterruptIn Left(p13); // JS_LEFT
InterruptIn Right(p16); // JS_RIGHT
InterruptIn Fire(p9); // JS_PUSH
InterruptIn Up(p30); // JS_UP
InterruptIn Down(p29); // JS_DOWN
InterruptIn Left(p28); // JS_LEFT
InterruptIn Right(p27); // JS_RIGHT
// Main Brew Control class holding all brewing features and logic
// parameters are (in order):
......@@ -74,9 +74,10 @@ InterruptIn Right(p16); // JS_RIGHT
// ZDC detector input (ZCD_IN)
// pump phasecontrol signal (PUMP_CTRL)
// pressure sensor (PRESSURE_IN)
// temperature sensor (TEMP_IN)
// side temperature sensor (TEMP_IN)
// top temperature sensor (TEMP2_IN) - Not Implemented
// boiler control ssr (BOILER_CTRL)
BrewControl brew_control(p10, p15, p12, p13, p20, p14, p26);
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p26);
// Menu structures
#define PRE_INFUSE_TIME 0
......@@ -133,7 +134,7 @@ uint8_t brew_params[NUM_BREW_MENUS][3][3]= {
{ {55, 28, 0}, {55, 28, 0}, {55, 28, 0} }
};
uint8_t cycle_menu = 0;
uint8_t active_menu = 0;
uint8_t menu_level = L_STANDBY;
// 0 means not in edit mode - 1 to 9 are positions on a 3x3 square
......@@ -151,11 +152,12 @@ void set_params(uint8_t menu_id)
{
brew_control.set_shot_volume(0);
brew_control.set_shot_time(0);
brew_control.set_preinfuse_time(0);
return;
}
uint8_t i;
for(i = 0; i < MENU_ITEMS[1][menu_id]; i++) {
switch (MENU_ITEMS[i+2][menu_id])
for(i = 0; i < MENU_ITEMS[menu_id][1]; i++) {
switch (MENU_ITEMS[menu_id][i+2])
{
case PRE_INFUSE_TIME:
brew_control.set_preinfuse_time(
......@@ -194,7 +196,7 @@ void draw_menu()
// Invert screen while brewing
if (brew_control.get_state())
LCD.invert(1);
if (cycle_menu == M_BREW_MANUAL)
if (active_menu == M_BREW_MANUAL)
{
LCD.locate(5,16);
LCD.printf("MANUAL");
......@@ -219,7 +221,7 @@ void draw_menu()
brew_control.get_current_pressure(),
brew_control.get_current_flow_rate());
LCD.locate(55,17);
LCD.printf("%d ml %d s",
LCD.printf("%.0f ml %.0f s",
brew_control.get_current_volume(),
brew_control.get_current_time());
}
......@@ -227,38 +229,38 @@ void draw_menu()
else if (menu_level == L_MENU) {
LCD.locate(0,12);
LCD.set_font((unsigned char*) Arial12x12);
LCD.printf("%s ", MENU_TITLES[cycle_menu]);
LCD.printf("%s ", MENU_TITLES[active_menu]);
}
// Show second level menu items (brew parameters)
else if (menu_level == L_MENU_SUB) {
out_s.clear();
// Display all menu items
for(i = 2; i < sizeof(MENU_ITEMS[cycle_menu])/sizeof(*MENU_ITEMS[cycle_menu]); i++) {
for(i = 2; i < sizeof(MENU_ITEMS[active_menu])/sizeof(*MENU_ITEMS[active_menu]); i++) {
// Get the type of current menu item (T, P, Y or ST)
int idx = MENU_ITEMS[cycle_menu][i];
int idx = MENU_ITEMS[active_menu][i];
char default_n[8];
// break out if we have an empty element
if (idx == EMPTY)
break;
out_s += ITEM_STRINGS[idx];
// For each menu item, get all the parameters (either 1 or 3)
for (j = 0; j < MENU_ITEMS[cycle_menu][0]; j++) {
for (j = 0; j < MENU_ITEMS[active_menu][0]; j++) {
// Add brackets if edit selection is over current parameter
if (edit_mode == (i-2)*3+(j+1))
sprintf(default_n, "[%d]", brew_params[cycle_menu][j][i-2]);
sprintf(default_n, "[%d]", brew_params[active_menu][j][i-2]);
else
sprintf(default_n, "%d", brew_params[cycle_menu][j][i-2]);
sprintf(default_n, "%d", brew_params[active_menu][j][i-2]);
out_s += default_n;
out_s += " ";
}
out_s += '\n';
}
if (MENU_ITEMS[cycle_menu][1] == 1)
if (MENU_ITEMS[active_menu][1] == 1)
{
LCD.set_font((unsigned char*) Arial12x12);
LCD.locate(0,12);
}
else if (MENU_ITEMS[cycle_menu][1] == 2)
else if (MENU_ITEMS[active_menu][1] == 2)
{
LCD.set_font((unsigned char*) Arial12x12);
LCD.locate(0,6);
......@@ -278,7 +280,13 @@ void menu_handler()
{
while(true) {
// wait on joystick action
osEvent event = Thread::signal_wait(0);
osEvent event = Thread::signal_wait(0, 500);
if (event.status == osEventTimeout)
{
draw_menu();
continue;
}
// fire
if (event.value.signals == 0x05) {
switch (menu_level)
......@@ -294,7 +302,7 @@ void menu_handler()
break;
case L_BREW: // send params to brew control b4 brewing
if(!brew_control.get_state())
set_params(cycle_menu);
set_params(active_menu);
brew_control.toggle();
break;
}
......@@ -309,15 +317,20 @@ void menu_handler()
{
menu_level = L_MENU;
// if we exiting settings, let's set them
if(cycle_menu == M_BREW_SETTINGS)
set_params(cycle_menu);
if(active_menu == M_BREW_SETTINGS)
set_params(active_menu);
}
else
brew_params[cycle_menu]
brew_params[active_menu]
[conversion_table[edit_mode-1][0]]
[conversion_table[edit_mode-1][1]]--;
break;
case L_BREW: menu_level = L_MENU_SUB; break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
// skip sub-menu for manual mode
menu_level = L_MENU;
else
menu_level = L_MENU_SUB;
break;
}
}
// up
......@@ -325,13 +338,15 @@ void menu_handler()
switch (menu_level)
{
case L_STANDBY: menu_level = L_MENU; break;
case L_MENU: cycle_menu = (!cycle_menu)?cycle_menu:cycle_menu-1;
case L_MENU: active_menu = (!active_menu)?active_menu:active_menu-1;
break;
case L_MENU_SUB: if(edit_mode > 1)
// sub 1 or 3 based on number of phases
edit_mode -= (MENU_ITEMS[cycle_menu][0] == 1)?3:1;
edit_mode -= (MENU_ITEMS[active_menu][0] == 1)?3:1;
break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
brew_control.pressure_up();
break;
case L_BREW: break;
}
}
// right
......@@ -339,13 +354,18 @@ void menu_handler()
switch (menu_level)
{
case L_STANDBY: menu_level = L_MENU; break;
case L_MENU: menu_level = L_MENU_SUB; break;
case L_MENU_SUB: if(!edit_mode && cycle_menu != M_BREW_SETTINGS)
case L_MENU: if(active_menu == M_BREW_MANUAL)
// skip sub-menu for manual mode
menu_level = L_BREW;
else
menu_level = L_MENU_SUB;
break;
case L_MENU_SUB: if(!edit_mode && active_menu != M_BREW_SETTINGS)
{
menu_level = L_BREW;
}
else
brew_params[cycle_menu]
brew_params[active_menu]
[conversion_table[edit_mode-1][0]]
[conversion_table[edit_mode-1][1]]++;
break;
......@@ -357,14 +377,16 @@ void menu_handler()
switch (menu_level)
{
case L_STANDBY: menu_level = L_MENU; break;
case L_MENU: cycle_menu = (cycle_menu < NUM_BREW_MENUS)?cycle_menu+1:cycle_menu;
case L_MENU: active_menu = (active_menu < NUM_BREW_MENUS)?active_menu+1:active_menu;
break;
case L_MENU_SUB: if(edit_mode < (MENU_ITEMS[cycle_menu][1]-1)*3
case L_MENU_SUB: if(edit_mode < (MENU_ITEMS[active_menu][1]-1)*3
&& edit_mode > 0)
// move fwd by 1 or 3 based on number of phases
edit_mode += (MENU_ITEMS[cycle_menu][0] == 1)?3:1;
edit_mode += (MENU_ITEMS[active_menu][0] == 1)?3:1;
break;
case L_BREW: if(active_menu == M_BREW_MANUAL)
brew_control.pressure_down();
break;
case L_BREW: break;
}
}
......@@ -504,17 +526,19 @@ int main()
else
pc.printf("Disabling PID\n");
}
else if (c == '=')
brew_control.toggle_solenoid();
}
pc.printf("%d %.3f %.2f %.1f %.1f %.2f %d %d %d\n",
/*
pc.printf("%d %.3f ml %.2f bar %.1f C %.1f C %.1f s %.2f ml/s\n",
brew_control.get_pump_level(),
brew_control.get_current_volume(),
brew_control.get_current_pressure(),
brew_control.get_current_temperature(),
brew_control.get_current_temperature_side(),
brew_control.get_current_temperature_top(),
brew_control.get_current_time(),
brew_control.get_current_flow_rate(),
menu_level,
edit_mode,
MENU_ITEMS[cycle_menu][1]*3 );
brew_control.get_current_flow_rate());
*/
#endif
Thread::wait(100); // wait 0.1s
}
......
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