From 5bb9681e84eae15dc5fe05b8a7f653ef99905e7f Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Thu, 22 Apr 2021 10:29:48 -0400 Subject: Ignore home button press when in Api popup This avoids quitting the app when an Api popup is displayed, causing problems. The variable resposable for this has been renamed to better reflect its use. --- api.cpp | 16 ++++++++-------- api.hpp | 3 ++- buttons.cpp | 12 ++++++++---- pico-watch.cpp | 4 +--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/api.cpp b/api.cpp index acf0fba..6d1b054 100644 --- a/api.cpp +++ b/api.cpp @@ -97,7 +97,7 @@ void Api::gui_popup_generic(std::string &title, std::string &body, int max_title bool Api::gui_popup_text(std::string title, std::string body){ m_button_last_pressed = BUTTON_NONE; - m_send_button_press_to_app = false; + m_interpret_button_press = false; gui_popup_generic(title, body); @@ -105,13 +105,13 @@ bool Api::gui_popup_text(std::string title, std::string body){ sleep_ms(50); // TODO: use _wfi() // Give back control to running app oledFill(&m_oled, 0, 1); - m_send_button_press_to_app = true; + m_interpret_button_press = true; return true; } bool Api::gui_popup_booleanchoice(std::string title, std::string body){ m_button_last_pressed = BUTTON_NONE; - m_send_button_press_to_app = false; + m_interpret_button_press = false; title.insert(0, "Choice|"); // TODO: Could be made nicer with a custom char that uses the whole height, this would give a visible separation, with two "text blocks" composing the title gui_popup_generic(title, body); @@ -132,7 +132,7 @@ bool Api::gui_popup_booleanchoice(std::string title, std::string body){ } // Give back control to running app oledFill(&m_oled, 0, 1); - m_send_button_press_to_app = true; + m_interpret_button_press = true; return choice; } @@ -150,7 +150,7 @@ void Api::gui_popup_intchoice_footer(int current_num, int min_num, int max_num) int Api::gui_popup_intchoice(std::string title, std::string body, int min_num, int max_num, int default_num, int step){ m_button_last_pressed = BUTTON_NONE; - m_send_button_press_to_app = false; + m_interpret_button_press = false; int current_num = default_num; @@ -182,7 +182,7 @@ int Api::gui_popup_intchoice(std::string title, std::string body, int min_num, i // Give back control to running app oledFill(&m_oled, 0, 1); - m_send_button_press_to_app = true; + m_interpret_button_press = true; return current_num; } @@ -223,7 +223,7 @@ void Api::gui_popup_strchoice_footer(const char selection[]) { int Api::gui_popup_strchoice(std::string title, std::string body, const char *choices[27], int choices_size, int min_index, int max_index, int default_index){ m_button_last_pressed = BUTTON_NONE; - m_send_button_press_to_app = false; + m_interpret_button_press = false; if (max_index == -1) max_index = choices_size-1; @@ -257,7 +257,7 @@ int Api::gui_popup_strchoice(std::string title, std::string body, const char *ch // Give back control to running app oledFill(&m_oled, 0, 1); - m_send_button_press_to_app = true; + m_interpret_button_press = true; return current_index; } diff --git a/api.hpp b/api.hpp index 0327f4f..2f88d9f 100644 --- a/api.hpp +++ b/api.hpp @@ -23,7 +23,8 @@ class Api { void gui_popup_intchoice_footer(int current_num, int min_num, int max_num); void gui_popup_strchoice_footer(const char selection[]); public: - bool m_send_button_press_to_app = true; + // Allow button press to be registed by app and for app_switch (when HOME). Set to false for in Api internal gui. + bool m_interpret_button_press = true; enum app_init_return_status { OK = 0, MALLOC_FAILED = 1 diff --git a/buttons.cpp b/buttons.cpp index 7ecc8a4..b86ac5d 100644 --- a/buttons.cpp +++ b/buttons.cpp @@ -18,10 +18,14 @@ const int button_delay_time = 50; // 50ms worked fine for me .... change it to y void gpio_interrupt_cb(uint gpio, uint32_t events) { if ((to_ms_since_boot(get_absolute_time())-button_last_pressed_time)>button_delay_time) { - if (gpio == BUTTON_HOME && (current_app != 0)) // Home app - app_switch(current_app, 0); - else - app_btnpressed(current_app, gpio); + + if (app_api.m_interpret_button_press) { + if (gpio == BUTTON_HOME && (current_app != 0)) // Home app + app_switch(current_app, 0); + else + app_btnpressed(current_app, gpio); + } + app_api.button_last_set(gpio); button_last_pressed_time = to_ms_since_boot(get_absolute_time()); } diff --git a/pico-watch.cpp b/pico-watch.cpp index 60537a8..ce76016 100644 --- a/pico-watch.cpp +++ b/pico-watch.cpp @@ -67,9 +67,7 @@ int app_render(int app_id) { } int app_btnpressed(int app_id, uint gpio) { - if (app_api.m_send_button_press_to_app) - return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio); - return 2; + return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio); } int app_destroy(int app_id) { -- cgit v1.2.3-54-g00ecf