Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightstand: Show battery percentage and show AM/PM in timer mode #42

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions nightstand_clock/clock_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ void elements_progress_bar_vertical(
uint8_t height,
float progress) {
furi_assert(canvas);
furi_assert((progress >= 0) && (progress <= 1.0));
furi_assert(((float)progress >= 0.0f) && ((float)progress <= 1.0f));

uint8_t width = 9;

uint8_t progress_length = roundf((1.f - progress) * (height - 2));
Expand Down Expand Up @@ -142,6 +143,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
char time_string[TIME_LEN];
char date_string[DATE_LEN];
char meridian_string[MERIDIAN_LEN];
char date_pct_string[DATE_PCT_LEN];
char timer_string[20];

if(state->time_format == LocaleTimeFormat24h) {
Expand Down Expand Up @@ -191,15 +193,31 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, time_string); // DRAW TIME
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, timer_string); // DRAW TIMER
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignTop, date_string); // DRAW DATE

snprintf(
date_pct_string, sizeof(date_pct_string), "%s %u%%", date_string, state->battery_pct);
canvas_draw_str_aligned(
canvas, 64, 20, AlignCenter, AlignTop, date_pct_string); // DRAW DATE + BATTERY
elements_button_left(canvas, "Reset");
} else {
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignCenter, time_string);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 65, 17, AlignCenter, AlignCenter, date_string);

if(state->time_format == LocaleTimeFormat12h)
canvas_draw_str_aligned(canvas, 64, 47, AlignCenter, AlignCenter, meridian_string);
if(state->time_format == LocaleTimeFormat12h) {
snprintf(
date_pct_string,
sizeof(date_pct_string),
"%s %u%%",
date_string,
state->battery_pct);
canvas_draw_str_aligned(canvas, 64, 17, AlignCenter, AlignCenter, date_pct_string);
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignCenter, meridian_string);
} else {
canvas_draw_str_aligned(canvas, 64, 17, AlignCenter, AlignCenter, date_string);
Willy-JL marked this conversation as resolved.
Show resolved Hide resolved
char pct_string[BATTERY_LEN + 1];
snprintf(pct_string, sizeof(pct_string), "%u%%", state->battery_pct);
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignCenter, pct_string);
}
}
if(timer_running) {
elements_button_center(canvas, "Stop");
Expand All @@ -210,8 +228,8 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {

static void clock_state_init(ClockState* const state) {
state->time_format = locale_get_time_format();

state->date_format = locale_get_date_format();
state->battery_pct = furi_hal_power_get_pct();

//FURI_LOG_D(TAG, "Time format: %s", state->settings.time_format == H12 ? "12h" : "24h");
//FURI_LOG_D(TAG, "Date format: %s", state->settings.date_format == Iso ? "ISO 8601" : "RFC 5322");
Expand Down Expand Up @@ -344,9 +362,9 @@ int32_t clock_app(void* p) {
break;
}
}
} /*else if(event.type == EventTypeTick) {
furi_hal_rtc_get_datetime(&plugin_state->datetime);
}*/
} else if(event.type == EventTypeTick) {
plugin_state->battery_pct = furi_hal_power_get_pct();
}

furi_mutex_release(plugin_state->mutex);
view_port_update(view_port);
Expand Down
3 changes: 3 additions & 0 deletions nightstand_clock/clock_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define TIME_LEN 12
#define DATE_LEN 14
#define MERIDIAN_LEN 3
#define BATTERY_LEN 4
#define DATE_PCT_LEN 21

typedef enum {
EventTypeTick,
Expand All @@ -36,4 +38,5 @@ typedef struct {
uint32_t timer_start_timestamp;
uint32_t timer_stopped_seconds;
bool timer_running;
uint8_t battery_pct;
} ClockState;