Commit 5c58e3b3 authored by Philippe Kalaf's avatar Philippe Kalaf

Added powersave mode

parent d8eb44ba
Pipeline #33788664 passed with stages
in 1 minute and 15 seconds
......@@ -80,6 +80,32 @@ void C12832_LCD::invert(unsigned int o)
else wr_cmd(0xA7);
}
void C12832_LCD::power_save(unsigned int o)
{
// turn off power save
if(o == 0)
{
// set all points OFF
wr_cmd(0xA4);
// sleep mode off
wr_cmd(0xAD);
wr_cmd(0x00);
}
else
{
// sleep mode on
wr_cmd(0xAC);
wr_cmd(0x00);
// display OFF
wr_cmd(0xAE);
// set all points ON
wr_cmd(0xA5);
}
}
void C12832_LCD::set_contrast(unsigned int o)
{
......
......@@ -161,6 +161,8 @@ public:
*/
void invert(unsigned int o);
void power_save(unsigned int o);
/** clear the screen
*
*/
......
......@@ -67,8 +67,14 @@ InterruptIn Down(p29); // JS_DOWN
InterruptIn Left(p28); // JS_LEFT
InterruptIn Right(p27); // JS_RIGHT
// This is used to ignore double clicks
Timer js_timer;
// Timer for power saving mode
Timer power_save_timer;
bool power_save_state;
#define POWER_SAVE_TIMEOUT_S 600
// Main Brew Control class holding all brewing features and logic
// parameters are (in order):
// valve/zcd/pump power control (VALVE_CTRL)
......@@ -265,6 +271,11 @@ void draw_menu()
}
else
{
if (power_save_state)
{
LCD.locate(5,16);
LCD.printf("COLD");
}
LCD.locate(5,20);
LCD.printf("STANDBY");
}
......@@ -481,31 +492,66 @@ bool check_js_timer()
}
}
void enter_power_save()
{
// let's set ambient temp to keep things cool
brew_control.set_shot_temperature(23);
// turn on power saving
//LCD.power_save(1);
power_save_state = 1;
menu_level = L_STANDBY;
}
void exit_power_save()
{
power_save_state = 0;
power_save_timer.reset();
// go back to previously set temperature
set_params(M_BREW_SETTINGS);
// turn off power saving
//LCD.power_save(0);
}
// should get called everytime a power saving reset event happens
void check_power_save()
{
if(power_save_state)
exit_power_save();
else
power_save_timer.reset();
}
// Joystick ISRs just send signals to unblock menu thread
void cycle_up()
{
check_power_save();
if(check_js_timer())
menu_thread.signal_set(0x02);
menu_thread.signal_set(0x02);
}
void cycle_down()
{
check_power_save();
if(check_js_timer())
menu_thread.signal_set(0x04);
menu_thread.signal_set(0x04);
}
void cycle_left()
{
check_power_save();
if(check_js_timer())
menu_thread.signal_set(0x01);
menu_thread.signal_set(0x01);
}
void cycle_right()
{
check_power_save();
if(check_js_timer())
menu_thread.signal_set(0x03);
menu_thread.signal_set(0x03);
}
void fire_away()
{
check_power_save();
if(check_js_timer())
menu_thread.signal_set(0x05);
menu_thread.signal_set(0x05);
}
// print the actual contrast
......@@ -516,6 +562,9 @@ int main()
brew_control.set_shot_volume(target_volume);
js_timer.start();
power_save_timer.start();
power_save_state = 0;
// We want to call the menu_handler in another thread
menu_thread.start(callback(menu_handler));
draw_menu();
......@@ -636,7 +685,10 @@ int main()
brew_control.get_last_pulse_count_side(),
brew_control.get_last_pulse_count_top()
);
Thread::wait(100); // wait 0.1s
#endif
Thread::wait(100); // wait 0.1s
// If there has been no keypress for POWER_SAVE_TIMEOUT_S, go to powersaving mode
if (power_save_timer.read() > POWER_SAVE_TIMEOUT_S)
enter_power_save();
}
}
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