aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConfuSomu2021-03-01 23:01:44 -0500
committerConfuSomu2021-03-01 23:01:44 -0500
commitb9971cb3b7779d31889379c56afeddc24ff50d04 (patch)
tree6bd342169c4cd84365981ae071369f931f4f62f1
parent09f67190a934230853e1dddaf65a14c4e9a50999 (diff)
downloadpico-watch-b9971cb3b7779d31889379c56afeddc24ff50d04.tar
pico-watch-b9971cb3b7779d31889379c56afeddc24ff50d04.tar.gz
pico-watch-b9971cb3b7779d31889379c56afeddc24ff50d04.zip
Fix race condition when refresh interval is small
Possible fix
-rw-r--r--pico-watch.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/pico-watch.cpp b/pico-watch.cpp
index adfe2fd..9df6799 100644
--- a/pico-watch.cpp
+++ b/pico-watch.cpp
@@ -11,6 +11,7 @@
#include "apps/home_menu.hpp"
int current_app = 0;
+bool app_ready = true;
Api app_api;
#define NUMBER_OF_APPS 2
@@ -25,6 +26,7 @@ int APPS_IS_INIT[NUMBER_OF_APPS] = {0, 0}; // Only run in background if init
int app_init(int app_id) {
app_api.display_fill(0,1); // Clear OLED
+ app_api.performance_render_interval_set(500); // Reset interval
if (!APPS_IS_INIT[app_id]) {
APPS_IS_INIT[app_id] = 1;
return (*APPS_FUNC_INIT[app_id])(&app_api);
@@ -42,7 +44,6 @@ int app_btnpressed(int app_id, uint gpio) {
}
int app_destroy(int app_id) {
- // TODO: reset APPS_DATA for the app
if (APPS_IS_INIT[app_id]) {
APPS_IS_INIT[app_id] = 0;
return (*APPS_FUNC_DESTROY[app_id])(&app_api);
@@ -62,11 +63,13 @@ bool apps_bgrefresh(struct repeating_timer *t) { // TODO: Refresh done on core1
}
void app_switch(int old_appid, int new_appid) {
+ app_ready = false;
if (APPS_DESTROY_ON_EXIT[old_appid]) {
app_destroy(old_appid);
}
app_init(new_appid);
current_app = new_appid;
+ app_ready = true;
}
int main() {
@@ -79,7 +82,8 @@ int main() {
app_init(current_app);
while (1) {
- app_render(current_app);
+ if (app_ready)
+ app_render(current_app); // FIXME: This may cause race conditions when switching app
sleep_ms(app_api.performance_render_interval_get());
}
return 0;