1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include <stdio.h>
#include "pico/stdlib.h"
#include "main.hpp"
// For time format:
#include "../../globals.hpp"
// TODO in this app
// -
// Time as string
// Adapted from pico-sdk/scr/common/pico_util/datetime.c
void app_main_clock::time_as_str(char *buf, uint buf_size, const datetime_t *t) {
int hour;
if (g_user.time_format) // 24 hour format
hour = t->hour;
else { // 12 hour format
hour = t->hour % 12;
if (hour == 0) hour = 12;
}
snprintf(buf,
buf_size,
"%02d:%02d ",
hour, t->min, t->sec);
};
void app_main_clock::date_as_str(char *buf, uint buf_size, const datetime_t *t) {
static const char *DATETIME_DOWS[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
snprintf(buf,
buf_size,
"%02d-%02d-%02d %s",
t->year,
t->month,
t->day,
DATETIME_DOWS[t->dotw]);
};
BaseApp::AppReturnValues app_main_clock::render(Api *app_api) {
char datetime_buf[256];
char *datetime_str = &datetime_buf[0];
datetime_t t;
app_api->datetime_get(&t);
// time
time_as_str(datetime_str, sizeof(datetime_buf), &t);
app_api->display_write_string(0,25,3, datetime_str, FONT_12x16, 0, 1);
snprintf(datetime_str, sizeof(datetime_buf), "%02d", t.sec);
app_api->display_write_string(0,87,4, datetime_str, FONT_8x8, 0, 1);
// for 12 hour time
if (!g_user.time_format) {
bool is_pm = !(t.hour < 12);
const char *indicator = is_pm? "PM" : "AM";
app_api->display_write_string(0,98,2, indicator, FONT_8x8, 0, 1);
}
// date
date_as_str(datetime_str, sizeof(datetime_buf), &t);
app_api->gui_footer_text(datetime_str);
return AppReturnValues::OK;
}
BaseApp::AppReturnValues app_main_clock::btn_pressed(Api *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);
}
BaseApp::AppReturnValues app_main_clock::bgrefresh(Api *app_api, bool in_foreground) {
return AppReturnValues::OK;
}
app_main_clock::~app_main_clock() {
}
|