diff options
Diffstat (limited to 'buttons.cpp')
-rw-r--r-- | buttons.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/buttons.cpp b/buttons.cpp index bc0ba74..589619c 100644 --- a/buttons.cpp +++ b/buttons.cpp @@ -1,5 +1,4 @@ #include <stdio.h> -#include "pico/stdlib.h" #include "buttons.hpp" #include "globals.hpp" @@ -12,6 +11,8 @@ extern Api app_api; // Rising edge and falling edge are "inverted" as every button is set to be pulled up. This means that the falling edge is done when the button is pressed and the rising edge when the button is released. +// SDL2 TODO: Implement button support +#ifndef SDL2_BUILD void gpio_interrupt_cb(uint gpio, uint32_t events) { auto delta_since_press = time_since_button_press(); @@ -72,3 +73,42 @@ void init_buttons() { */ g_s.button_last_pressed_time = to_ms_since_boot(get_absolute_time()); } + +#else // SDL2_BUILD +// this function will have to be called by SDL2 on keyboard/button press +// gpio: button pressed +// events: 0 is when button released and 1 is when button pressed +void gpio_interrupt_cb(uint gpio, uint32_t events) { + auto delta_since_press = time_since_button_press(); + + if (delta_since_press > g_s.button_delay_time) { + + if (app_api.m_interpret_button_press) { + switch (events) { + case 1: + if (gpio == BUTTON_HOME && (g_s.foreground_app->app_get_attributes().id != 0)) // Home app + app_mgr::app_switch_request(0); + else + app_mgr::app_btnpressed(g_s.foreground_app, gpio, delta_since_press); + break; + + case 0: + if (gpio != BUTTON_HOME) // For simplicity's sake + app_mgr::app_btnreleased(g_s.foreground_app, gpio, delta_since_press); + break; + } + + } + + if (events == 1) + app_api.button_last_set(gpio); + g_s.button_last_pressed_time = to_ms_since_boot(get_absolute_time()); + } +} +unsigned long time_since_button_press() { + // FIXME: This does not correct overflows + // std::cout << to_ms_since_boot(get_absolute_time()); + return to_ms_since_boot(get_absolute_time())-g_s.button_last_pressed_time; +} +void init_buttons() {} +#endif |