diff options
Diffstat (limited to 'project/Core/Src/Project/local_control.c')
| -rw-r--r-- | project/Core/Src/Project/local_control.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/project/Core/Src/Project/local_control.c b/project/Core/Src/Project/local_control.c index 5957e1a..c151226 100644 --- a/project/Core/Src/Project/local_control.c +++ b/project/Core/Src/Project/local_control.c @@ -12,11 +12,11 @@ #include "GPIO.h" #include "project.h" #include "systick.h" +#include "player_actions.h" -int click_count = 0; -uint32_t last_press = 0; -uint32_t time_down = 0; -int hold_pending = 0; +static int click_count = 0; +static uint32_t last_press = 0; +static int hold_pending = 0; void handle_press(int pressed); @@ -33,17 +33,23 @@ void local_control_init() { */ void local_control_loop() { uint32_t now = systick_get_count(); + if (hold_pending) { hold_pending = 0; - printf("Hold click action\r\n"); + player_stop(); } - if (now - last_press > 10000) { + if (last_press && now - last_press > 1000) { last_press = 0; switch(click_count) { case 1: - printf("Single click action\r\n"); break; + if (player_get_state() == PLAYING_STATE) { + player_pause(); + } else { + player_play(); + } + break; case 2: - printf("Double click action\r\n"); break; + player_next(); break; } click_count = 0; } @@ -71,23 +77,21 @@ void EXTI9_5_IRQHandler() { /** * Logs button information + * @param pressed 1 if the button was just pressed, 0 if the button was just released */ void handle_press(int pressed) { + static uint32_t time_down = 0; uint32_t now = systick_get_count(); + if (pressed) { time_down = now; } else { -// printf("now: %i, time_down: %i diff: %i\r\n", now, time_down, now - time_down); - if (/*(now - time_down) < 10 ||*/ !time_down) { - printf("ignored\r\n"); -// printf("now: %i, time_down: %i diff: %i\r\n", now, time_down, now - time_down); - } else if ((now - time_down) < 10000) { -// printf("SHORT PRESS\r\n"); + putchar(0); // I don't know why but without this it bounces + if ((now - time_down) < 1000) { time_down = 0; last_press = now; click_count++; } else { -// printf("LONG PRESS\r\n"); hold_pending = 1; time_down = 0; } |
