aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app_manager.cpp24
-rw-r--r--app_manager.hpp42
-rw-r--r--apps/home_menu/main.cpp2
-rw-r--r--buttons.cpp4
-rw-r--r--pico-watch.cpp8
5 files changed, 45 insertions, 35 deletions
diff --git a/app_manager.cpp b/app_manager.cpp
index d6f6e1d..f7ca969 100644
--- a/app_manager.cpp
+++ b/app_manager.cpp
@@ -13,11 +13,9 @@
// From pico-watch.c:
extern Api app_api;
-std::vector<BaseApp*> open_apps;
+std::vector<BaseApp*> app_mgr::open_apps;
-// Check if the specified app (via app_id) is already running.
-// \return If app is init, pointer to app, else nullptr (more or less 0).
-BaseApp* app_check_if_init(int app_id) {
+BaseApp* app_mgr::app_check_if_init(int app_id) {
for (auto app : open_apps) {
if (app_id == app->app_get_attributes().id)
return app;
@@ -25,8 +23,7 @@ BaseApp* app_check_if_init(int app_id) {
return nullptr;
}
-// Called by app_init to create the app object.
-BaseApp* app_create(int app_id) {
+BaseApp* app_mgr::app_create(int app_id) {
switch (app_id) {
case 0: open_apps.push_back(new app_home_menu(&app_api)); break;
case 1: open_apps.push_back(new app_main_clock(&app_api)); break;
@@ -38,7 +35,7 @@ BaseApp* app_create(int app_id) {
return open_apps.back();
}
-BaseApp* app_init(int app_id) {
+BaseApp* app_mgr::app_init(int app_id) {
BaseApp* new_app;
app_api.performance_render_interval_set(500); // Reset interval
@@ -56,16 +53,15 @@ BaseApp* app_init(int app_id) {
return new_app;
}
-int app_render(BaseApp* app) {
+int app_mgr::app_render(BaseApp* app) {
return app->render(&app_api);
}
-int app_btnpressed(BaseApp* app, uint gpio, unsigned long delta) {
+int app_mgr::app_btnpressed(BaseApp* app, uint gpio, unsigned long delta) {
return app->btnpressed(&app_api, gpio, delta);
}
-// Quit the app referenced by the app_id.
-int app_destroy(BaseApp* to_erase) {
+int app_mgr::app_destroy(BaseApp* to_erase) {
auto erase_it = std::find(open_apps.begin(), open_apps.end(), to_erase); // "it" meaning iterator
if (erase_it != open_apps.end()) {
//assert(to_erase == erase_it);
@@ -76,20 +72,20 @@ int app_destroy(BaseApp* to_erase) {
return 0;
}
-void app_all_bgrefresh() {
+void app_mgr::app_all_bgrefresh() {
for (auto app : open_apps) {
app->bgrefresh(&app_api, app->app_get_attributes().id == g_s.current_app->app_get_attributes().id);
}
}
-void app_switch_request(int to_appid) {
+void app_mgr::app_switch_request(int to_appid) {
if (!g_s.app_switch_requested)
g_s.app_switch_to_app = to_appid;
g_s.app_switch_requested = true;
app_api.performance_render_interval_set(0); // This will be reset on new app init
}
-void app_switch(BaseApp* app, int new_appid) {
+void app_mgr::app_switch(BaseApp* app, int new_appid) {
g_s.app_ready = false;
app_api.display_fill(0,1); // Clear OLED
diff --git a/app_manager.hpp b/app_manager.hpp
index 71aba2f..3657d93 100644
--- a/app_manager.hpp
+++ b/app_manager.hpp
@@ -2,23 +2,37 @@
#include <vector>
#include "base_app.hpp"
-// List of pointers to currently running apps.
-extern std::vector<BaseApp*> open_apps;
+// Interface to the app manager. These functions are accessible to other parts of the code, except open_apps, which is managed by the following functions.
+namespace app_mgr {
+ // List of pointers to currently running apps.
+ extern std::vector<BaseApp*> open_apps;
-// Init a new app, that is not running.
-BaseApp* app_init(int app_id);
+ // Init a new app, that is not running.
+ BaseApp* app_init(int app_id);
-// Allow the running app, referenced by app_id, to invoke its render routine.
-int app_render(BaseApp* app);
+ // Allow the running app, referenced by app_id, to invoke its render routine.
+ int app_render(BaseApp* app);
-// Delta is in ms, from time_since_button_press()
-int app_btnpressed(BaseApp* app, uint gpio, unsigned long delta);
+ // Delta is in ms, from time_since_button_press()
+ int app_btnpressed(BaseApp* app, uint gpio, unsigned long delta);
-// This should only be called by pico-watch.cpp before app rendering, to chage the current app.
-void app_switch(BaseApp* app, int new_appid);
+ // This should only be called by pico-watch.cpp before app rendering, to chage the current app.
+ void app_switch(BaseApp* app, int new_appid);
-// Requests the current app to be replaced by an other one. The replacement will be done at the right moment.
-void app_switch_request(int to_appid);
+ // Requests the current app to be replaced by an other one. The replacement will be done at the right moment.
+ void app_switch_request(int to_appid);
-// Refresh each app
-void app_all_bgrefresh();
+ // Refresh each app
+ void app_all_bgrefresh();
+
+ // Private functions following. I tried using anonymous namespaces but it was too complicated. I might come back to this later. Just don't use the following internal functions.
+ // Check if the specified app (via app_id) is already running.
+ // \return If app is init, pointer to app, else nullptr (more or less 0).
+ BaseApp* app_check_if_init(int app_id);
+
+ // Called by app_init to create the app object.
+ BaseApp* app_create(int app_id);
+
+ // Quit the app referenced by the app_id.
+ int app_destroy(BaseApp* to_erase);
+}
diff --git a/apps/home_menu/main.cpp b/apps/home_menu/main.cpp
index 02965c3..ff8ae4d 100644
--- a/apps/home_menu/main.cpp
+++ b/apps/home_menu/main.cpp
@@ -39,7 +39,7 @@ int app_home_menu::render(Api *app_api) {
int app_home_menu::btnpressed(Api *app_api, uint gpio, unsigned long delta) {
switch (gpio) {
case BUTTON_SELECT:
- app_switch_request( selected_app);
+ app_mgr::app_switch_request(selected_app);
return 0;
case BUTTON_DOWN:
selected_app--;
diff --git a/buttons.cpp b/buttons.cpp
index df947db..79202c8 100644
--- a/buttons.cpp
+++ b/buttons.cpp
@@ -17,9 +17,9 @@ void gpio_interrupt_cb(uint gpio, uint32_t events) {
if (app_api.m_interpret_button_press) {
if (gpio == BUTTON_HOME && (g_s.current_app->app_get_attributes().id != 0)) // Home app
- app_switch_request(0);
+ app_mgr::app_switch_request(0);
else
- app_btnpressed(g_s.current_app, gpio, delta_since_press);
+ app_mgr::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 1a8738a..efa7702 100644
--- a/pico-watch.cpp
+++ b/pico-watch.cpp
@@ -29,7 +29,7 @@ bool repeating_callback(struct repeating_timer *t) {
}
// should it be done when sleeping?
- app_all_bgrefresh();
+ app_mgr::app_all_bgrefresh();
return true;
}
@@ -42,16 +42,16 @@ int main() {
struct repeating_timer timer;
add_repeating_timer_ms(250, repeating_callback, NULL, &timer); // TODO: Execute on core1
- g_s.current_app = app_init(0);
+ g_s.current_app = app_mgr::app_init(0);
while (1) {
if (g_s.app_switch_requested) {
- app_switch(g_s.current_app, g_s.app_switch_to_app);
+ app_mgr::app_switch(g_s.current_app, g_s.app_switch_to_app);
g_s.app_switch_requested = false;
}
if (g_s.app_ready && !g_s.is_sleeping) {
- app_render(g_s.current_app);
+ app_mgr::app_render(g_s.current_app);
app_api.display_write_backbuffer();
}