From 09f67190a934230853e1dddaf65a14c4e9a50999 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Mon, 1 Mar 2021 22:31:20 -0500 Subject: Implement API to set/get render interval --- api.cpp | 10 ++++++++++ api.hpp | 8 ++++++++ pico-watch.cpp | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api.cpp b/api.cpp index 1200f16..2d63506 100644 --- a/api.cpp +++ b/api.cpp @@ -134,6 +134,16 @@ bool Api::datetime_get(datetime_t *t) { return rtc_get_datetime(t); } +int Api::performance_render_interval_get() { + return m_app_render_interval; +} + +void Api::performance_render_interval_set(int interval) { + if (interval < 10) + interval = 10; + m_app_render_interval = interval; +} + uint Api::button_last_get() { return m_button_last_pressed; } diff --git a/api.hpp b/api.hpp index f5de57e..20f5c34 100644 --- a/api.hpp +++ b/api.hpp @@ -13,6 +13,7 @@ class Api { u_char m_init_done = 0; uint8_t m_ucBuffer[1024] = {0}; uint m_button_last_pressed = 0; + int m_app_render_interval = 500; void init_display(); public: bool m_send_button_press_to_app = true; @@ -55,7 +56,14 @@ class Api { // \param perf See Api::perf_modes enum for possible values bool performance_set(int perf); bool datetime_get(datetime_t *t); + // Get app's current render interval + // \return Value in millisec + int performance_render_interval_get(); + // Same spirit as performance_set, the app should use the smallest value possible that does not cause a lack of responsiveness in the app's UI. + // \param interval Time to wait in millisec between calls of the app's render function. + void performance_render_interval_set(int interval); // Get last button pressed, see buttons.hpp for values + // \return Last button pressed uint button_last_get(); // Set last button pressed, should only be called by button gpio interrupt. void button_last_set(uint gpio); diff --git a/pico-watch.cpp b/pico-watch.cpp index 7c59d98..adfe2fd 100644 --- a/pico-watch.cpp +++ b/pico-watch.cpp @@ -80,7 +80,7 @@ int main() { while (1) { app_render(current_app); - sleep_ms(500); + sleep_ms(app_api.performance_render_interval_get()); } return 0; } -- cgit v1.2.3-54-g00ecf