From bfd88af24823a4ceb3e22dc202ed195dd1b7ef8e Mon Sep 17 00:00:00 2001 From: Bas Grolleman Date: Fri, 2 Jan 2026 07:41:22 +0100 Subject: [PATCH] Last updates --- countdown_watchface/src/c/watchface.c | 44 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/countdown_watchface/src/c/watchface.c b/countdown_watchface/src/c/watchface.c index a562b4c..6e480c2 100644 --- a/countdown_watchface/src/c/watchface.c +++ b/countdown_watchface/src/c/watchface.c @@ -1,11 +1,26 @@ #include #include + static Window *s_main_window; static TextLayer *s_time_layer; static TextLayer *s_date_layer; -static TextLayer *s_cd_layer; static EffectLayer *s_effect_layer; +static Layer *s_battery_layer; +static Layer *s_countdown_layer; +static int s_battery_level; + +static void battery_update_proc(Layer *layer, GContext *ctx) { + GRect bounds = layer_get_bounds(layer); + + int width = (s_battery_level * 114)/ 100; + + graphics_context_set_fill_color(ctx, GColorWhite); + graphics_fill_rect(ctx,bounds,0,GCornerNone); + + graphics_context_set_fill_color(ctx,GColorWhite); + graphics_fill_rect(ctx, GRect(0,0,width,bounds.size.h), 0, GCornerNone); +} static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); @@ -43,26 +58,19 @@ static void main_window_load(Window *window) { // Add it as a child layer to the Window's root layer layer_add_child(window_layer, text_layer_get_layer(s_date_layer)); - s_cd_layer = text_layer_create( - GRect(0, PBL_IF_ROUND_ELSE(18,12), bounds.size.w, 50) - ); + // Battery + s_battery_layer = layer_create(GRect(14,54,115,2)); + layer_set_update_proc(s_battery_layer, battery_update_proc); - // Improve the layout to be more like a watchface - text_layer_set_background_color(s_cd_layer, GColorClear); - text_layer_set_text_color(s_cd_layer, GColorWhite); - text_layer_set_text(s_cd_layer, "-----=========="); - text_layer_set_font(s_cd_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); - text_layer_set_text_alignment(s_cd_layer, GTextAlignmentCenter); - - // Add it as a child layer to the Window's root layer - layer_add_child(window_layer, text_layer_get_layer(s_cd_layer)); + layer_add_child(window_layer, s_battery_layer); + layer_mark_dirty(s_battery_layer); } static void main_window_unload(Window *window) { text_layer_destroy(s_time_layer); text_layer_destroy(s_date_layer); - text_layer_destroy(s_cd_layer); effect_layer_destroy(s_effect_layer); + layer_destroy(s_battery_layer); } static void update_time() { @@ -85,6 +93,11 @@ static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); } +static void battery_callback(BatteryChargeState state) { + s_battery_level = state.charge_percent; +} + + static void init() { s_main_window = window_create(); @@ -96,14 +109,15 @@ static void init() { window_stack_push(s_main_window, true); tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); + battery_state_service_subscribe(battery_callback); update_time(); + battery_callback(battery_state_service_peek()); } static void deinit() { window_destroy(s_main_window); } - int main(void) { init(); app_event_loop();