diff options
author | ConfuSomu | 2024-02-14 15:26:36 -0500 |
---|---|---|
committer | ConfuSomu | 2024-02-14 15:26:36 -0500 |
commit | 9873cd86c33a669c95ff5421fd6b91c59f80354f (patch) | |
tree | 5df2a653acfd4c94e4074cf58c1da7d96167c79b | |
parent | ad6b89bf02c43b208638fd8a1140ebc7f5636602 (diff) | |
download | pico-watch-9873cd86c33a669c95ff5421fd6b91c59f80354f.tar pico-watch-9873cd86c33a669c95ff5421fd6b91c59f80354f.tar.gz pico-watch-9873cd86c33a669c95ff5421fd6b91c59f80354f.zip |
Rename Api class to AppAPI
-rw-r--r-- | app/app_manager.cpp | 2 | ||||
-rw-r--r-- | app/base_app.hpp | 8 | ||||
-rw-r--r-- | apps/home_menu/main.cpp | 12 | ||||
-rw-r--r-- | apps/home_menu/main.hpp | 10 | ||||
-rw-r--r-- | apps/main_clock/main.cpp | 10 | ||||
-rw-r--r-- | apps/main_clock/main.hpp | 8 | ||||
-rw-r--r-- | apps/settings/main.cpp | 16 | ||||
-rw-r--r-- | apps/settings/main.hpp | 14 | ||||
-rw-r--r-- | buttons.cpp | 2 | ||||
-rw-r--r-- | hal/api.cpp | 52 | ||||
-rw-r--r-- | hal/api.hpp | 2 | ||||
-rw-r--r-- | pico-watch.cpp | 6 |
12 files changed, 71 insertions, 71 deletions
diff --git a/app/app_manager.cpp b/app/app_manager.cpp index 07e68fa..a927d74 100644 --- a/app/app_manager.cpp +++ b/app/app_manager.cpp @@ -11,7 +11,7 @@ #define NUMBER_OF_APPS 3 // From pico-watch.c: -extern Api app_api; +extern AppAPI app_api; std::vector<BaseApp*> app_mgr::open_apps; diff --git a/app/base_app.hpp b/app/base_app.hpp index 94b12cc..325bb26 100644 --- a/app/base_app.hpp +++ b/app/base_app.hpp @@ -21,12 +21,12 @@ class BaseApp { // {return app_attributes;} // where app_attribues is an instance of AppAttributes - virtual AppReturnValues render(Api *app_api) = 0; // Has to be implemented + virtual AppReturnValues render(AppAPI *app_api) = 0; // Has to be implemented // Called when a button is pressed. // \param delta The time since the button been last released. Delta is in ms, from time_since_button_press(). - virtual AppReturnValues btn_pressed(Api *app_api, uint gpio, unsigned long delta) {return AppReturnValues::OK;}; + virtual AppReturnValues btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta) {return AppReturnValues::OK;}; // Called when a button is released. // \param delta The time since the button has been pressed. Delta is in ms, from time_since_button_press(). - virtual AppReturnValues btn_released(Api *app_api, uint gpio, unsigned long delta) {return AppReturnValues::OK;}; - virtual AppReturnValues bgrefresh(Api *app_api, bool in_foreground) {return AppReturnValues::OK;}; + virtual AppReturnValues btn_released(AppAPI *app_api, uint gpio, unsigned long delta) {return AppReturnValues::OK;}; + virtual AppReturnValues bgrefresh(AppAPI *app_api, bool in_foreground) {return AppReturnValues::OK;}; }; diff --git a/apps/home_menu/main.cpp b/apps/home_menu/main.cpp index 200a71f..a884491 100644 --- a/apps/home_menu/main.cpp +++ b/apps/home_menu/main.cpp @@ -14,7 +14,7 @@ void app_home_menu::title_str(char *buf, uint buf_size, const datetime_t *t) { t->sec); }; -void app_home_menu::show_title(Api *app_api) { +void app_home_menu::show_title(AppAPI *app_api) { char datetime_buf[256]; char *datetime_str = &datetime_buf[0]; datetime_t t; @@ -26,7 +26,7 @@ void app_home_menu::show_title(Api *app_api) { } // Rendering of app -BaseApp::AppReturnValues app_home_menu::render(Api *app_api) { +BaseApp::AppReturnValues app_home_menu::render(AppAPI *app_api) { show_title(app_api); app_api->display_write_string(0,5,3, display_app_name, FONT_12x16, 0, 1); return AppReturnValues::OK; @@ -34,7 +34,7 @@ BaseApp::AppReturnValues app_home_menu::render(Api *app_api) { // Example of how button inputs could be interpreted. // Drawing on screen should be done in the render function. -BaseApp::AppReturnValues app_home_menu::btn_pressed(Api *app_api, uint gpio, unsigned long delta) { +BaseApp::AppReturnValues app_home_menu::btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta) { switch (gpio) { case BUTTON_SELECT: app_mgr::app_switch_request(selected_app); @@ -57,13 +57,13 @@ BaseApp::AppReturnValues app_home_menu::btn_pressed(Api *app_api, uint gpio, uns } // Initlisation of the app. -app_home_menu::app_home_menu(Api *app_api) { - app_api->performance_set(Api::perf_modes::LOW_POWER); +app_home_menu::app_home_menu(AppAPI *app_api) { + app_api->performance_set(AppAPI::perf_modes::LOW_POWER); selected_app = 0; snprintf(display_app_name, SIZE_APP_NAME, "%s", APPS_NAME[0]); } // Processor intensive operations and functions related to drawing to the screen should only be done when the app is in_foreground(=1). This function is only called when the app is init. -BaseApp::AppReturnValues app_home_menu::bgrefresh(Api *app_api, bool in_foreground) { +BaseApp::AppReturnValues app_home_menu::bgrefresh(AppAPI *app_api, bool in_foreground) { return AppReturnValues::OK; } diff --git a/apps/home_menu/main.hpp b/apps/home_menu/main.hpp index 242d2a3..7673aca 100644 --- a/apps/home_menu/main.hpp +++ b/apps/home_menu/main.hpp @@ -15,7 +15,7 @@ class app_home_menu : public BaseApp { char display_app_name[SIZE_APP_NAME]; void title_str(char *buf, uint buf_size, const datetime_t *t); - void show_title(Api *app_api); + void show_title(AppAPI *app_api); AppAttributes app_attributes = {0, false}; public: @@ -23,9 +23,9 @@ class app_home_menu : public BaseApp { return app_attributes; } - app_home_menu(Api *app_api); - AppReturnValues render(Api *app_api); - AppReturnValues btn_pressed(Api *app_api, uint gpio, unsigned long delta); - AppReturnValues bgrefresh(Api *app_api, bool in_foreground); + app_home_menu(AppAPI *app_api); + AppReturnValues render(AppAPI *app_api); + AppReturnValues btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta); + AppReturnValues bgrefresh(AppAPI *app_api, bool in_foreground); ~app_home_menu(); }; diff --git a/apps/main_clock/main.cpp b/apps/main_clock/main.cpp index ab9be14..9e86cba 100644 --- a/apps/main_clock/main.cpp +++ b/apps/main_clock/main.cpp @@ -35,7 +35,7 @@ void app_main_clock::date_as_str(char *buf, uint buf_size, const datetime_t *t) DATETIME_DOWS[t->dotw]); }; -BaseApp::AppReturnValues app_main_clock::render(Api *app_api) { +BaseApp::AppReturnValues app_main_clock::render(AppAPI *app_api) { char datetime_buf[256]; char *datetime_str = &datetime_buf[0]; datetime_t t; @@ -62,15 +62,15 @@ BaseApp::AppReturnValues app_main_clock::render(Api *app_api) { return AppReturnValues::OK; } -BaseApp::AppReturnValues app_main_clock::btn_pressed(Api *app_api, uint gpio, unsigned long delta) { +BaseApp::AppReturnValues app_main_clock::btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta) { return AppReturnValues::OK; } -app_main_clock::app_main_clock(Api *app_api) { - app_api->performance_set(Api::perf_modes::LOW_POWER); +app_main_clock::app_main_clock(AppAPI *app_api) { + app_api->performance_set(AppAPI::perf_modes::LOW_POWER); } -BaseApp::AppReturnValues app_main_clock::bgrefresh(Api *app_api, bool in_foreground) { +BaseApp::AppReturnValues app_main_clock::bgrefresh(AppAPI *app_api, bool in_foreground) { return AppReturnValues::OK; } diff --git a/apps/main_clock/main.hpp b/apps/main_clock/main.hpp index 8163c22..2cdc9ec 100644 --- a/apps/main_clock/main.hpp +++ b/apps/main_clock/main.hpp @@ -16,9 +16,9 @@ class app_main_clock : public BaseApp { return app_attributes; } - app_main_clock(Api *app_api); - AppReturnValues render(Api *app_api); - AppReturnValues btn_pressed(Api *app_api, uint gpio, unsigned long delta); - AppReturnValues bgrefresh(Api *app_api, bool in_foreground); + app_main_clock(AppAPI *app_api); + AppReturnValues render(AppAPI *app_api); + AppReturnValues btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta); + AppReturnValues bgrefresh(AppAPI *app_api, bool in_foreground); ~app_main_clock(); }; diff --git a/apps/settings/main.cpp b/apps/settings/main.cpp index ae0734b..a886b91 100644 --- a/apps/settings/main.cpp +++ b/apps/settings/main.cpp @@ -7,14 +7,14 @@ extern bool rtc_get_datetime(datetime_t *t); -void app_settings::show_title(Api *app_api) { +void app_settings::show_title(AppAPI *app_api) { std::string title_str {"Settings (/" MAIN_SET_NUM_STR ")"}; title_str.insert(10, std::to_string(selected_setting+1)); app_api->gui_header_text(title_str); } // Time and date settings -void app_settings::set0_menu(Api *app_api) { +void app_settings::set0_menu(AppAPI *app_api) { #define NUM_CHOICES 9 static const char *choices[NUM_CHOICES] = {"Hour", "Minute", "Second", "Year", "Month", "Day", "Day of week", STR_SET_APPLY, STR_SET_CANCEL}; uint max_value; @@ -88,7 +88,7 @@ void app_settings::set0_menu(Api *app_api) { } // Display settings -void app_settings::set1_menu(Api *app_api) { +void app_settings::set1_menu(AppAPI *app_api) { #define NUM_CHOICES 4 static const char *choices[NUM_CHOICES] = {"Display brightness", "Sleep timeout", "Time format", STR_SET_APPLY}; @@ -119,7 +119,7 @@ void app_settings::set1_menu(Api *app_api) { } // Rendering of app -BaseApp::AppReturnValues app_settings::render(Api *app_api) { +BaseApp::AppReturnValues app_settings::render(AppAPI *app_api) { show_title(app_api); app_api->display_write_string(0,0,3, display_setting_name, FONT_12x16, 0, 1); @@ -138,7 +138,7 @@ BaseApp::AppReturnValues app_settings::render(Api *app_api) { return AppReturnValues::OK; } -BaseApp::AppReturnValues app_settings::btn_pressed(Api *app_api, uint gpio, unsigned long delta) { +BaseApp::AppReturnValues app_settings::btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta) { switch (gpio) { case BUTTON_SELECT: selected = true; @@ -160,14 +160,14 @@ BaseApp::AppReturnValues app_settings::btn_pressed(Api *app_api, uint gpio, unsi return AppReturnValues::OK; } -app_settings::app_settings(Api *app_api) { - app_api->performance_set(Api::perf_modes::LOW_POWER); +app_settings::app_settings(AppAPI *app_api) { + app_api->performance_set(AppAPI::perf_modes::LOW_POWER); selected_setting = 0; selected = false; snprintf(display_setting_name, SIZE_SETTING_NAME, "%s", MAIN_SET_NAMES[0]); } -BaseApp::AppReturnValues app_settings::bgrefresh(Api *app_api, bool in_foreground) { +BaseApp::AppReturnValues app_settings::bgrefresh(AppAPI *app_api, bool in_foreground) { return AppReturnValues::OK; } diff --git a/apps/settings/main.hpp b/apps/settings/main.hpp index d9eabda..f9ea564 100644 --- a/apps/settings/main.hpp +++ b/apps/settings/main.hpp @@ -9,9 +9,9 @@ class app_settings : public BaseApp { char display_setting_name[SIZE_SETTING_NAME]; bool selected = false; - void show_title(Api *app_api); - void set0_menu(Api *app_api); - void set1_menu(Api *app_api); + void show_title(AppAPI *app_api); + void set0_menu(AppAPI *app_api); + void set1_menu(AppAPI *app_api); AppAttributes app_attributes = {2, true}; public: @@ -19,10 +19,10 @@ class app_settings : public BaseApp { return app_attributes; } - app_settings(Api *app_api); - AppReturnValues render(Api *app_api); - AppReturnValues btn_pressed(Api *app_api, uint gpio, unsigned long delta); - AppReturnValues bgrefresh(Api *app_api, bool in_foreground); + app_settings(AppAPI *app_api); + AppReturnValues render(AppAPI *app_api); + AppReturnValues btn_pressed(AppAPI *app_api, uint gpio, unsigned long delta); + AppReturnValues bgrefresh(AppAPI *app_api, bool in_foreground); ~app_settings(); }; #include "strings-undef.hpp" diff --git a/buttons.cpp b/buttons.cpp index 589619c..c5db168 100644 --- a/buttons.cpp +++ b/buttons.cpp @@ -5,7 +5,7 @@ #include "hal/api.hpp" #include "app/app_manager.hpp" // From pico-watch.c: -extern Api app_api; +extern AppAPI app_api; //const uint BUTTON_PINS[] = {BUTTON_HOME, BUTTON_SELECT, BUTTON_MODE, BUTTON_UP, BUTTON_DOWN}; diff --git a/hal/api.cpp b/hal/api.cpp index 961cdd5..5666763 100644 --- a/hal/api.cpp +++ b/hal/api.cpp @@ -13,14 +13,14 @@ extern "C" { #include "../init.hpp" #include "../globals.hpp" -void Api::init() { +void AppAPI::init() { if (!m_init_done) { init_display(); m_init_done = 1; } } -void Api::init_display() { +void AppAPI::init_display() { sleep_ms(500); // Wait for the OLED to settle oledInit(&m_oled, OLED_128x64, 0x3d, 0, 0, 1, SDA_PIN, SCL_PIN, RESET_PIN, 1000000L); oledFill(&m_oled, 0,1); @@ -29,44 +29,44 @@ void Api::init_display() { //oledSetTextWrap(&oled, true); } -void Api::display_power(bool mode) { +void AppAPI::display_power(bool mode) { oledPower(&m_oled, mode); } -void Api::display_set_contrast(unsigned char contrast) { +void AppAPI::display_set_contrast(unsigned char contrast) { oledSetContrast(&m_oled, contrast); } -int Api::display_write_string(int iScrollX, int x, int y, const char *szMsg, int iSize, int bInvert, int bRender) { +int AppAPI::display_write_string(int iScrollX, int x, int y, const char *szMsg, int iSize, int bInvert, int bRender) { oledWriteString(&m_oled, iScrollX, x, y, szMsg, iSize, bInvert, 0); m_writebb_needed = true; return 0; } -void Api::display_fill(unsigned char ucData, int bRender) { +void AppAPI::display_fill(unsigned char ucData, int bRender) { oledFill(&m_oled, ucData, bRender); } -void Api::display_draw_line(int x1, int y1, int x2, int y2, int bRender) { +void AppAPI::display_draw_line(int x1, int y1, int x2, int y2, int bRender) { oledDrawLine(&m_oled, x1, y1, x2, y2, 0); m_writebb_needed = true; } -void Api::display_draw_rectange(int x1, int y1, int x2, int y2, uint8_t ucColor, uint8_t bFilled) { // FIXME: Fix typo +void AppAPI::display_draw_rectange(int x1, int y1, int x2, int y2, uint8_t ucColor, uint8_t bFilled) { // FIXME: Fix typo oledRectangle(&m_oled, x1, y1, x2, y2, ucColor, bFilled); m_writebb_needed = true; // Write the back buffer, after experimentation, seems to be required when drawing this shape } -void Api::display_draw_ellipse(int iCenterX, int iCenterY, int32_t iRadiusX, int32_t iRadiusY, uint8_t ucColor, uint8_t bFilled) { +void AppAPI::display_draw_ellipse(int iCenterX, int iCenterY, int32_t iRadiusX, int32_t iRadiusY, uint8_t ucColor, uint8_t bFilled) { oledEllipse(&m_oled, iCenterX, iCenterY, iRadiusX, iRadiusY, ucColor, bFilled); m_writebb_needed = true; } -void Api::display_write_buffer(uint8_t *pBuffer) { +void AppAPI::display_write_buffer(uint8_t *pBuffer) { oledDumpBuffer(&m_oled, pBuffer); } -bool Api::display_write_backbuffer() { +bool AppAPI::display_write_backbuffer() { #ifndef SDL2_BUILD if (m_writebb_needed) oledDumpBuffer(&m_oled, m_ucBuffer); @@ -78,11 +78,11 @@ bool Api::display_write_backbuffer() { #endif } -int Api::display_write_pixel(int x, int y, unsigned char ucColor, int bRender) { +int AppAPI::display_write_pixel(int x, int y, unsigned char ucColor, int bRender) { return oledSetPixel(&m_oled, x, y, ucColor, bRender); } -void Api::gui_popup_generic(std::string &title, std::string &body, int max_title_length, int max_body_length) { +void AppAPI::gui_popup_generic(std::string &title, std::string &body, int max_title_length, int max_body_length) { 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, FIXME pixel bleeding @@ -112,7 +112,7 @@ void Api::gui_popup_generic(std::string &title, std::string &body, int max_title oledWriteString(&m_oled, 0, 13,2, body.c_str(), FONT_8x8, 0, 1); // Draw body } -bool Api::gui_popup_text(std::string title, std::string body){ +bool AppAPI::gui_popup_text(std::string title, std::string body){ m_button_last_pressed = BUTTON_NONE; m_interpret_button_press = false; @@ -126,7 +126,7 @@ bool Api::gui_popup_text(std::string title, std::string body){ return true; } -bool Api::gui_popup_booleanchoice(std::string title, std::string body){ +bool AppAPI::gui_popup_booleanchoice(std::string title, std::string body){ m_button_last_pressed = BUTTON_NONE; m_interpret_button_press = false; @@ -153,7 +153,7 @@ bool Api::gui_popup_booleanchoice(std::string title, std::string body){ return choice; } -void Api::gui_popup_intchoice_footer(int current_num, int min_num, int max_num) { +void AppAPI::gui_popup_intchoice_footer(int current_num, int min_num, int max_num) { char buf[30]; snprintf(&buf[0], sizeof(buf), "Select: %d (%d/%d)", @@ -165,7 +165,7 @@ void Api::gui_popup_intchoice_footer(int current_num, int min_num, int max_num) m_writebb_needed = true; display_write_backbuffer(); } -int Api::gui_popup_intchoice(std::string title, std::string body, int min_num, int max_num, int default_num, int step){ +int AppAPI::gui_popup_intchoice(std::string title, std::string body, int min_num, int max_num, int default_num, int step){ m_button_last_pressed = BUTTON_NONE; m_interpret_button_press = false; @@ -203,7 +203,7 @@ int Api::gui_popup_intchoice(std::string title, std::string body, int min_num, i return current_num; } -void Api::gui_popup_strchoice_footer(const char selection[]) { +void AppAPI::gui_popup_strchoice_footer(const char selection[]) { std::string buf{selection}; buf.insert(0, "Select: "); @@ -238,7 +238,7 @@ void Api::gui_popup_strchoice_footer(const char selection[]) { m_writebb_needed = true; display_write_backbuffer(); } -int Api::gui_popup_strchoice(std::string title, std::string body, const char *choices[27], int choices_size, int min_index, int max_index, int default_index){ +int AppAPI::gui_popup_strchoice(std::string title, std::string body, const char *choices[27], int choices_size, int min_index, int max_index, int default_index){ m_button_last_pressed = BUTTON_NONE; m_interpret_button_press = false; if (max_index == -1) @@ -278,7 +278,7 @@ int Api::gui_popup_strchoice(std::string title, std::string body, const char *ch return current_index; } -bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { +bool AppAPI::gui_footer_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { // Max chars per line for FONT_8x8 is 16 chars // Max chars per line for FONT_6x8 is 21 chars // Truncate longer text @@ -299,7 +299,7 @@ bool Api::gui_footer_text(std::string text, int offset_x, int offset_row, bool i return oledWriteString(&m_oled, 0,offset_x,7-offset_row, text.c_str(), font, invert, 0); } -bool Api::gui_header_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { +bool AppAPI::gui_header_text(std::string text, int offset_x, int offset_row, bool invert, bool no_bg) { // Max chars per line for FONT_8x8 is 16 chars // Max chars per line for FONT_6x8 is 21 chars // Truncate longer text @@ -320,11 +320,11 @@ bool Api::gui_header_text(std::string text, int offset_x, int offset_row, bool i return oledWriteString(&m_oled, 0,offset_x,0+offset_row, text.c_str(), font, invert, 0); } -bool Api::performance_set(int perf) { +bool AppAPI::performance_set(int perf) { return false; } -bool Api::datetime_get(datetime_t *t) { +bool AppAPI::datetime_get(datetime_t *t) { #ifndef SDL2_BUILD return rtc_get_datetime(t); #else @@ -332,7 +332,7 @@ bool Api::datetime_get(datetime_t *t) { #endif } -bool Api::datetime_set(datetime_t *t) { +bool AppAPI::datetime_set(datetime_t *t) { #ifndef SDL2_BUILD return rtc_set_datetime(t); #else @@ -340,10 +340,10 @@ bool Api::datetime_set(datetime_t *t) { #endif } -uint Api::button_last_get() { +uint AppAPI::button_last_get() { return m_button_last_pressed; } -void Api::button_last_set(uint gpio) { +void AppAPI::button_last_set(uint gpio) { m_button_last_pressed = gpio; } diff --git a/hal/api.hpp b/hal/api.hpp index eaba324..dabd6fe 100644 --- a/hal/api.hpp +++ b/hal/api.hpp @@ -6,7 +6,7 @@ #include "sdl2/display.hpp" #include "../buttons.hpp" -class Api { +class AppAPI { private: SSOLED m_oled; u_char m_init_done = 0; diff --git a/pico-watch.cpp b/pico-watch.cpp index a9e156a..282ae4e 100644 --- a/pico-watch.cpp +++ b/pico-watch.cpp @@ -20,18 +20,18 @@ global_status g_s; user_settings g_user; -Api app_api; +AppAPI app_api; bool cb_status_check(struct repeating_timer *t) { // Enter shallow sleep mode when needed auto time_since_last_press = time_since_button_press(); if (!g_s.is_sleeping && time_since_last_press > g_user.sleep_delay) { g_s.is_sleeping = true; - app_api.performance_set(Api::perf_modes::ENTER_SHALLOW_SLEEP); + app_api.performance_set(AppAPI::perf_modes::ENTER_SHALLOW_SLEEP); app_api.display_power(false); } else if (g_s.is_sleeping && time_since_last_press < g_user.sleep_delay) { g_s.is_sleeping = false; - app_api.performance_set(Api::perf_modes::EXIT_SHALLOW_SLEEP); + app_api.performance_set(AppAPI::perf_modes::EXIT_SHALLOW_SLEEP); app_api.display_power(true); } |