aboutsummaryrefslogtreecommitdiffstats
path: root/apps/home_menu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/home_menu.cpp')
-rw-r--r--apps/home_menu.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/apps/home_menu.cpp b/apps/home_menu.cpp
index 7f53447..910ebac 100644
--- a/apps/home_menu.cpp
+++ b/apps/home_menu.cpp
@@ -1,12 +1,8 @@
#include <stdio.h>
#include "pico/stdlib.h"
-extern "C" {
-#include "hardware/rtc.h"
-}
-#include "pico/util/datetime.h"
-#include "../oled/ss_oled.h"
#include "home_menu.hpp"
+#include "../api.hpp"
#include "../buttons.hpp"
extern void app_switch(int old_appid, int new_appid);
@@ -15,7 +11,7 @@ extern bool rtc_get_datetime(datetime_t *t);
#define NUMBER_OF_APPS 2
namespace app_home_menu {
- const char* APPS_NAME[NUMBER_OF_APPS][12] = {"Home", "Clock"};
+ char *APPS_NAME[NUMBER_OF_APPS] = {"Home", "Clock"};
char *pressed_button;
int *selected_app;
@@ -28,28 +24,28 @@ namespace app_home_menu {
t->sec);
};
- void show_title(SSOLED *oled) {
+ void show_title(Api *app_api) {
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
datetime_t t;
- rtc_get_datetime(&t);
+ app_api->datetime_get(&t);
// title with time
title_str(datetime_str, sizeof(datetime_buf), &t);
- oledWriteString(oled, 0,0,0, datetime_str, FONT_8x8, 0, 1);
+ app_api->gui_header_text((std::string)datetime_str);
}
// Rendering of app
- int render(SSOLED *oled) {
- show_title(oled);
- oledWriteString(oled, 0,0,2, pressed_button, FONT_6x8, 0, 1);
- oledWriteString(oled, 0,5,3, const_cast<char*>(APPS_NAME[0][*selected_app]), FONT_12x16, 0, 1);
+ int render(Api *app_api) {
+ 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);
return 0;
}
// Example of how button inputs could be interpreted.
// Drawing on screen should be done in the render function.
- int btnpressed(SSOLED *oled, uint gpio) {
+ int btnpressed(Api *app_api, uint gpio) {
switch (gpio) {
case BUTTON_HOME:
*pressed_button = 'H'; break;
@@ -79,19 +75,20 @@ namespace app_home_menu {
}
// Initlisation of the app.
- int init(SSOLED *oled) {
- pressed_button = new char; *pressed_button = '*';
- selected_app = new int;
+ int init(Api *app_api) {
+ app_api->performance_set(Api::perf_modes::LOW_POWER);
+ pressed_button = new char; *pressed_button = '*';
+ selected_app = new int; *selected_app = 0; // Make sure to init the values to something known!
return 0; // return 1 when function not implemented
}
// 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.
- int bgrefresh(SSOLED *oled, char in_foreground) {
+ int bgrefresh(Api *app_api, char in_foreground) {
return 1;
}
// Destruction of app, deinitlisation should be done here. This is only called if the app's APPS_DESTROY_ON_EXIT is set to 1. When it is not a "service" app.
- int destroy(SSOLED *oled) {
+ int destroy(Api *app_api) {
delete pressed_button; pressed_button = nullptr;
delete selected_app; selected_app = nullptr;
return 1;