Commit ad95fb2d authored by Philippe Kalaf's avatar Philippe Kalaf

Added double click detector to joystick

parent a4e8d9f1
......@@ -67,6 +67,8 @@ InterruptIn Down(p29); // JS_DOWN
InterruptIn Left(p28); // JS_LEFT
InterruptIn Right(p27); // JS_RIGHT
Timer js_timer;
// Main Brew Control class holding all brewing features and logic
// parameters are (in order):
// valve/zcd/pump power control (VALVE_CTRL)
......@@ -80,6 +82,9 @@ InterruptIn Right(p27); // JS_RIGHT
BrewControl brew_control(p10, p15, p12, p13, p20, p25, p26);
// Menu structures
//
// TODO portafilter size
// TODO powersaving
#define PRE_INFUSE_TIME 0
#define PRESSURE 1
#define YIELD 2
......@@ -395,26 +400,46 @@ void menu_handler()
}
}
// timer to ignore double clicks
bool check_js_timer()
{
if(js_timer.read_ms() < 250)
{
js_timer.reset();
return 0;
}
else
{
js_timer.reset();
return 1;
}
}
// Joystick ISRs just send signals to unblock menu thread
void cycle_up()
{
menu_thread.signal_set(0x02);
if(check_js_timer())
menu_thread.signal_set(0x02);
}
void cycle_down()
{
menu_thread.signal_set(0x04);
if(check_js_timer())
menu_thread.signal_set(0x04);
}
void cycle_left()
{
menu_thread.signal_set(0x01);
if(check_js_timer())
menu_thread.signal_set(0x01);
}
void cycle_right()
{
menu_thread.signal_set(0x03);
if(check_js_timer())
menu_thread.signal_set(0x03);
}
void fire_away()
{
menu_thread.signal_set(0x05);
if(check_js_timer())
menu_thread.signal_set(0x05);
}
// print the actual contrast
......@@ -423,6 +448,7 @@ int main()
// Initialize default mode - 60ml shots
int target_volume = 60;
brew_control.set_shot_volume(target_volume);
js_timer.start();
// We want to call the menu_handler in another thread
menu_thread.start(callback(menu_handler));
......@@ -539,7 +565,7 @@ int main()
brew_control.get_current_time(),
brew_control.get_current_flow_rate());
*/
#endif
Thread::wait(100); // wait 0.1s
#endif
}
}
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