aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api.cpp19
-rw-r--r--api.hpp10
-rw-r--r--apps/home_menu.cpp1
-rw-r--r--buttons.cpp4
-rw-r--r--pico-watch.cpp4
5 files changed, 33 insertions, 5 deletions
diff --git a/api.cpp b/api.cpp
index e333272..16d79ad 100644
--- a/api.cpp
+++ b/api.cpp
@@ -54,6 +54,9 @@ int Api::display_write_pixel(int x, int y, unsigned char ucColor, int bRender) {
bool Api::gui_popup_text(std::string title, std::string body){
#define CHARS_PER_LINE 13
+ m_button_last_pressed = 0;
+ m_send_button_press_to_app = false;
+
oledRectangle(&m_oled, 9,7, 119,63, 0, 1); // Background
oledRectangle(&m_oled, 9,7, 119,63, 1, 0); // Popup border
oledRectangle(&m_oled, 9,7, 119,16, 1, 1); // Title background
@@ -67,7 +70,7 @@ bool Api::gui_popup_text(std::string title, std::string body){
// Make body fit by adding '\n' at a regular interval
int since_nl = 0; // Characters since newline
- for(std::string::size_type i = 0; i < body.size(); ++i) {
+ for (std::string::size_type i = 0; i < body.size(); ++i) {
if (body[i] == '\n')
since_nl = 0;
else if (since_nl++ == CHARS_PER_LINE) {
@@ -78,9 +81,21 @@ bool Api::gui_popup_text(std::string title, std::string body){
// See https://stackoverflow.com/questions/1986966/does-s0-point-to-contiguous-characters-in-a-stdstring
oledWriteString(&m_oled, 0, 15,1, &title[0], FONT_8x8, 1, 1); // Draw title
oledWriteString(&m_oled, 0, 13,2, &body[0], FONT_8x8, 0, 1); // Draw body
- while(1) {;} // TODO: change, this is temporary, only for this commit!
+ while (m_button_last_pressed != BUTTON_SELECT)
+ sleep_ms(50);
+ // Give back control to running app
+ oledFill(&m_oled, 0, 1);
+ m_send_button_press_to_app = true;
}
bool Api::datetime_get(datetime_t *t) {
return rtc_get_datetime(t);
}
+
+uint Api::button_last_get() {
+ return m_button_last_pressed;
+}
+
+void Api::button_last_set(uint gpio) {
+ m_button_last_pressed = gpio;
+}
diff --git a/api.hpp b/api.hpp
index 2738688..2fc3bba 100644
--- a/api.hpp
+++ b/api.hpp
@@ -5,13 +5,17 @@
#include "pico/util/datetime.h"
#include "oled/ss_oled.h"
+#include "buttons.hpp"
+
class Api {
private:
SSOLED m_oled;
u_char m_init_done = 0;
uint8_t m_ucBuffer[1024] = {0};
+ uint m_button_last_pressed = 0;
void init_display();
public:
+ bool m_send_button_press_to_app = true;
void init();
int display_write_string(int iScrollX, int x, int y, char *szMsg, int iSize, int bInvert, int bRender);
void display_fill(unsigned char ucData, int bRender);
@@ -20,13 +24,17 @@ class Api {
void display_draw_ellipse(int iCenterX, int iCenterY, int32_t iRadiusX, int32_t iRadiusY, uint8_t ucColor, uint8_t bFilled);
void display_write_buffer(uint8_t *pBuffer);
int display_write_pixel(int x, int y, unsigned char ucColor, int bRender);
- // Display a popup over the current view.
+ // Display a popup over the current view and wait for select button to be pressed.
// This is a blocking function and should be used only in the app's render method.
// \param title Popup's title, length should not exceed 13 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_text(std::string title, std::string body);
bool datetime_get(datetime_t *t);
+ // Get last button pressed, see buttons.hpp for values
+ uint button_last_get();
+ // Set last button pressed, should only be called by button gpio interrupt.
+ void button_last_set(uint gpio);
};
#endif \ No newline at end of file
diff --git a/apps/home_menu.cpp b/apps/home_menu.cpp
index 996b713..b2dddb7 100644
--- a/apps/home_menu.cpp
+++ b/apps/home_menu.cpp
@@ -40,6 +40,7 @@ namespace app_home_menu {
show_title(app_api);
app_api->display_write_string(0,0,2, pressed_button, FONT_6x8, 0, 1);
app_api->display_write_string(0,5,3, APPS_NAME[*selected_app], FONT_12x16, 0, 1);
+ sleep_ms(500);
app_api->gui_popup_text("Title is a string", "Body text, and new line. And this is a pretty long string.\nIterating is very fun!");
return 0;
}
diff --git a/buttons.cpp b/buttons.cpp
index 8ba7b81..cd94504 100644
--- a/buttons.cpp
+++ b/buttons.cpp
@@ -2,10 +2,12 @@
#include "pico/stdlib.h"
#include "buttons.hpp"
+#include "api.hpp"
// From pico-watch.c:
extern int app_btnpressed(int app_id, uint gpio);
extern void app_switch(int old_appid, int new_appid);
extern int current_app;
+extern Api app_api;
// Debounce control
// See https://www.raspberrypi.org/forums/viewtopic.php?f=145&t=301522#p1812063
@@ -21,7 +23,7 @@ void gpio_interrupt_cb(uint gpio, uint32_t events) {
app_switch(current_app, 0);
else
app_btnpressed(current_app, gpio);
-
+ app_api.button_last_set(gpio);
button_time = to_ms_since_boot(get_absolute_time());
}
}
diff --git a/pico-watch.cpp b/pico-watch.cpp
index ebc3f12..7c59d98 100644
--- a/pico-watch.cpp
+++ b/pico-watch.cpp
@@ -36,7 +36,9 @@ int app_render(int app_id) {
}
int app_btnpressed(int app_id, uint gpio) {
- return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio);
+ if (app_api.m_send_button_press_to_app)
+ return (*APPS_FUNC_BTNPRESS[app_id])(&app_api, gpio);
+ return 2;
}
int app_destroy(int app_id) {