Skip to content

Commit 4497ec7

Browse files
authored
Merge pull request #254 from non-bin/Clock
Clock: add 12h option
2 parents 89835b7 + 37c0db0 commit 4497ec7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

applications/clock_app/clock_app.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct {
2121

2222
typedef struct {
2323
FuriHalRtcDateTime datetime;
24+
bool militaryTime; // 24 hour
2425
} ClockState;
2526

2627
static void clock_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
@@ -47,11 +48,18 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
4748
state->datetime.year,
4849
state->datetime.month,
4950
state->datetime.day);
51+
52+
uint8_t hour = state->datetime.hour;
53+
// bool pm = false;
54+
if (!state->militaryTime && hour > 12) {
55+
hour -= 12;
56+
// pm = true;
57+
}
5058
snprintf(
5159
strings[1],
5260
20,
5361
"%.2d:%.2d:%.2d",
54-
state->datetime.hour,
62+
hour,
5563
state->datetime.minute,
5664
state->datetime.second);
5765
snprintf(strings[2], 20, "%.2d:%.2d", curMin, curSec);
@@ -66,6 +74,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
6674
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignCenter, strings[1]); // DRAW TIME
6775
canvas_set_font(canvas, FontSecondary);
6876
canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignTop, strings[0]); // DRAW DATE
77+
elements_button_left(canvas, state->militaryTime ? "12h" : "24h");
6978
}
7079
if(timerStarted) {
7180
elements_button_center(canvas, "Stop");
@@ -77,6 +86,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
7786

7887
static void clock_state_init(ClockState* const state) {
7988
furi_hal_rtc_get_datetime(&state->datetime);
89+
state->militaryTime = true;
8090
}
8191

8292
// Runs every 1000ms by default
@@ -131,8 +141,11 @@ int32_t clock_app(void* p) {
131141
timerStarted = true;
132142
}
133143
} else if (event.input.key == InputKeyLeft) {
134-
// RESET TIMER
135-
timerSecs = 0;
144+
if (timerStarted || timerSecs!=0) {
145+
timerSecs = 0;
146+
} else {
147+
plugin_state->militaryTime = !plugin_state->militaryTime;
148+
}
136149
} else if (event.input.key == InputKeyBack) {
137150
// Exit the plugin
138151
processing = false;

0 commit comments

Comments
 (0)