aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConfuSomu2021-03-16 13:52:22 -0400
committerConfuSomu2021-03-16 13:52:22 -0400
commit54467fed75930ea005d7fb1e7099d5397e11a308 (patch)
tree9bd0d8f33145f893377974df4105a97246b91f74
parent5aa8fc267204835296914360647473e3e93001e6 (diff)
downloadpico-watch-54467fed75930ea005d7fb1e7099d5397e11a308.tar
pico-watch-54467fed75930ea005d7fb1e7099d5397e11a308.tar.gz
pico-watch-54467fed75930ea005d7fb1e7099d5397e11a308.zip
Implement API method to ask user for yes/no choice
-rw-r--r--api.cpp30
-rw-r--r--api.hpp6
-rw-r--r--buttons.hpp1
3 files changed, 36 insertions, 1 deletions
diff --git a/api.cpp b/api.cpp
index 1c08eb9..a0d8ae0 100644
--- a/api.cpp
+++ b/api.cpp
@@ -95,7 +95,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 = 0;
+ m_button_last_pressed = BUTTON_NONE;
m_send_button_press_to_app = false;
gui_popup_generic(title, body);
@@ -105,6 +105,34 @@ bool Api::gui_popup_text(std::string title, std::string body){
// Give back control to running app
oledFill(&m_oled, 0, 1);
m_send_button_press_to_app = 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;
+
+ 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);
+
+ while (m_button_last_pressed != BUTTON_SELECT and m_button_last_pressed != BUTTON_MODE)
+ sleep_ms(50); // TODO: use _wfi()
+
+ bool choice;
+ switch (m_button_last_pressed) {
+ case BUTTON_SELECT:
+ choice = true;
+ break;
+ case BUTTON_MODE:
+ choice = false;
+ break;
+ default:
+ __breakpoint(); // Impossible to attain (but you never know…)
+ }
+ // Give back control to running app
+ oledFill(&m_oled, 0, 1);
+ m_send_button_press_to_app = true;
+ return choice;
}
bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) {
diff --git a/api.hpp b/api.hpp
index 7f5015c..2930759 100644
--- a/api.hpp
+++ b/api.hpp
@@ -47,6 +47,12 @@ class Api {
// \param body String containing the popup's body. The zone has a size of 13×6 characters, so body should not be longer than 78 characters. Newline allows going to the next line and the text is automatically wrapped.
// \note Strings longer than 13 and 78 respectively will be truncated.
bool gui_popup_text(std::string title, std::string body);
+ // Display a popup over the current view and wait for select or mode (cancel) button to be pressed. The choice done (yes/no) by the user is returned as a bool.
+ // This is a blocking function and should be used only in the app's render method.
+ // \param title Popup's title. The title is prefixed with "Choice|", so the `title` argument cannot exceed 6 characters.
+ // \param body String containing the popup's body. The zone has a size of 13×6 characters, so body should not be longer than 78 characters. Newline allows going to the next line and the text is automatically wrapped.
+ // \note Strings longer than 13 and 78 respectively will be truncated.
+ bool gui_popup_booleanchoice(std::string title, std::string body);
// Display text at the bottom of the screen.
// The font size is automatically choosen based on the text lenght.
// \param text Text to display. Text longer than 21 will be truncated.
diff --git a/buttons.hpp b/buttons.hpp
index 3136a26..3899127 100644
--- a/buttons.hpp
+++ b/buttons.hpp
@@ -5,6 +5,7 @@
// Init buttons used in conjuction with interrupts
// All buttons are connected to ground.
#define NUMBER_OF_BUTTONS 5
+#define BUTTON_NONE 0
#define BUTTON_HOME 22
#define BUTTON_SELECT 18
#define BUTTON_MODE 19