diff options
-rw-r--r-- | apps/home_menu.cpp | 2 | ||||
-rw-r--r-- | apps/home_menu.hpp | 2 | ||||
-rw-r--r-- | apps/main_clock.cpp | 2 | ||||
-rw-r--r-- | apps/main_clock.hpp | 2 | ||||
-rw-r--r-- | buttons.cpp | 8 | ||||
-rw-r--r-- | pico-watch.cpp | 7 |
6 files changed, 13 insertions, 10 deletions
diff --git a/apps/home_menu.cpp b/apps/home_menu.cpp index 342c3ef..531a53c 100644 --- a/apps/home_menu.cpp +++ b/apps/home_menu.cpp @@ -45,7 +45,7 @@ namespace app_home_menu { // Example of how button inputs could be interpreted. // Drawing on screen should be done in the render function. - int btnpressed(Api *app_api, uint gpio) { + int btnpressed(Api *app_api, uint gpio, unsigned long delta) { switch (gpio) { case BUTTON_SELECT: app_switch(0, selected_app); diff --git a/apps/home_menu.hpp b/apps/home_menu.hpp index 366a248..78aed40 100644 --- a/apps/home_menu.hpp +++ b/apps/home_menu.hpp @@ -9,7 +9,7 @@ namespace app_home_menu { int init(Api *app_api); int render(Api *app_api); - int btnpressed(Api *app_api, uint gpio); + int btnpressed(Api *app_api, uint gpio, unsigned long delta); int bgrefresh(Api *app_api, bool in_foreground); int destroy(Api *app_api); } diff --git a/apps/main_clock.cpp b/apps/main_clock.cpp index ee97c3c..24a4dfb 100644 --- a/apps/main_clock.cpp +++ b/apps/main_clock.cpp @@ -66,7 +66,7 @@ namespace app_main_clock { } // Interpretation of button inputs - int btnpressed(Api *app_api, uint gpio) { + int btnpressed(Api *app_api, uint gpio, unsigned long delta) { if (gpio == BUTTON_MODE) *ask_user_choice = true; return 0; diff --git a/apps/main_clock.hpp b/apps/main_clock.hpp index e1d9469..72e02a4 100644 --- a/apps/main_clock.hpp +++ b/apps/main_clock.hpp @@ -9,7 +9,7 @@ namespace app_main_clock { int init(Api *app_api); int render(Api *app_api); - int btnpressed(Api *app_api, uint gpio); + int btnpressed(Api *app_api, uint gpio, unsigned long delta); int bgrefresh(Api *app_api, bool in_foreground); int destroy(Api *app_api); } diff --git a/buttons.cpp b/buttons.cpp index ad1f1dd..7aa82e8 100644 --- a/buttons.cpp +++ b/buttons.cpp @@ -4,20 +4,22 @@ #include "buttons.hpp" #include "api.hpp" // From pico-watch.c: -extern int app_btnpressed(int app_id, uint gpio); +extern int app_btnpressed(int app_id, uint gpio, unsigned long delta); extern void app_switch_request(int); extern Api app_api; //const uint BUTTON_PINS[] = {BUTTON_HOME, BUTTON_SELECT, BUTTON_MODE, BUTTON_UP, BUTTON_DOWN}; void gpio_interrupt_cb(uint gpio, uint32_t events) { - if (button_time_since_press() > g_s.button_delay_time) { + auto delta_since_press = time_since_button_press(); + + if (delta_since_press > g_s.button_delay_time) { if (app_api.m_interpret_button_press) { if (gpio == BUTTON_HOME && (g_s.current_app != 0)) // Home app app_switch_request(0); else - app_btnpressed(g_s.current_app, gpio); + app_btnpressed(g_s.current_app, gpio, delta_since_press); } app_api.button_last_set(gpio); diff --git a/pico-watch.cpp b/pico-watch.cpp index 3473d0f..bbaa679 100644 --- a/pico-watch.cpp +++ b/pico-watch.cpp @@ -18,7 +18,7 @@ Api app_api; #define APP_DATA_BUFFER_LEN 256 int (*APPS_FUNC_INIT[NUMBER_OF_APPS])(Api *app_api) = {app_home_menu::init, app_main_clock::init}; int (*APPS_FUNC_RENDER[NUMBER_OF_APPS])(Api *app_api) = {app_home_menu::render, app_main_clock::render}; -int (*APPS_FUNC_BTNPRESS[NUMBER_OF_APPS])(Api *app_api, uint gpio) = {app_home_menu::btnpressed, app_main_clock::btnpressed}; +int (*APPS_FUNC_BTNPRESS[NUMBER_OF_APPS])(Api *app_api, uint gpio, unsigned long delta) = {app_home_menu::btnpressed, app_main_clock::btnpressed}; int (*APPS_FUNC_BGREFRESH[NUMBER_OF_APPS])(Api *app_api, bool in_foreground) = {app_home_menu::bgrefresh, app_main_clock::bgrefresh}; int (*APPS_FUNC_DESTROY[NUMBER_OF_APPS])(Api *app_api) = {app_home_menu::destroy, app_main_clock::destroy}; int APPS_DESTROY_ON_EXIT[NUMBER_OF_APPS] = {0, 1}; @@ -63,8 +63,9 @@ int app_render(int app_id) { return (*APPS_FUNC_RENDER[app_id])(&app_api); } -int app_btnpressed(int app_id, uint gpio) { - return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio); +// Delta is in ms, from time_since_button_press() +int app_btnpressed(int app_id, uint gpio, unsigned long delta) { + return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio, delta); } int app_destroy(int app_id) { |