Add clock to alarm top bar

This commit is contained in:
RandyTheSilly committed 2026-10-31 13:43:46 -04:00
1 parent 2c33964565
commit 94788deaab
2 files changed
+29 -13

No files matched your search

+28 -12
View File
@@ -15,9 +15,6 @@ static Window *s_status_window;
static Window *s_drop_window;
static Layer *s_top_bar_layer;
static Layer *s_bottom_bar_layer;
// static TextLayer *s_time_txt_layer;
static TextLayer *s_countdown_txt_layer;
static TextLayer *s_progress_txt_layer;
static TextLayer *s_status_txt_layer;
//// setter
static BitmapLayer *s_clock_bmp_layer;
@@ -40,6 +37,9 @@ static Layer *s_division_layer;
static Layer *s_alarm_highlight_layer;
static MenuLayer *s_drop_menu_layer;
static RightTriangleLayer *s_triangle_layer;
static TextLayer *s_clock_txt_layer;
static TextLayer *s_countdown_txt_layer;
static TextLayer *s_progress_txt_layer;
static TextLayer *s_side_a_txt_layer;
static TextLayer *s_side_b_txt_layer;
static TextLayer *s_side_c_txt_layer;
@@ -74,7 +74,7 @@ static uint8_t s_zap_cooldown;
static uint8_t s_countdown_int = 0;
static bool s_continuous_zap_on_first_triangle;
static char s_countdown_buf[4];
static char s_progress_buf[9];
static char s_progress_buf[6];
// constants
//// shared (setter+alarm)
@@ -444,7 +444,7 @@ static void update_for_new_triangle() {
text_layer_set_text(s_countdown_txt_layer, s_countdown_buf);
// set progress counter
snprintf(s_progress_buf, sizeof(s_progress_buf), "%d/%d ", s_current_triangle_num, settings.TriangleCount);
snprintf(s_progress_buf, sizeof(s_progress_buf), "%d/%d", s_current_triangle_num, settings.TriangleCount);
text_layer_set_text(s_progress_txt_layer, s_progress_buf);
}
@@ -460,7 +460,8 @@ static void decrement_cooldown(uint8_t *cooldown) {
}
}
static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
static void alarm_tick_handler(struct tm *tick_time, TimeUnits units_changed) {
// seconds
s_countdown_int--;
decrement_cooldown(&s_shake_cooldown);
if (s_current_triangle_num == 1) {
@@ -485,6 +486,13 @@ static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed)
right_triangle_layer_regen(s_triangle_layer);
update_for_new_triangle();
}
// minutes
if (units_changed == 0 || (units_changed & MINUTE_UNIT)) {
static char s_clock_buffer[8];
strftime(s_clock_buffer, sizeof(s_clock_buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", tick_time);
text_layer_set_text(s_clock_txt_layer, s_clock_buffer);
}
}
static void graph_layer_update_proc(Layer *layer, GContext *ctx) {
@@ -759,9 +767,17 @@ static void alarm_window_load() {
s_drop_window,
(WindowHandlers){.load = drop_menu_window_load, .unload = drop_menu_window_unload});
static const GRect s_top_bar_text_grect = GRect(0, (s_small_top_bar_height / 2) - PBL_IF_ROUND_ELSE(6, 10), PBL_DISPLAY_WIDTH, s_small_top_bar_height);
// clock
static const uint16_t s_top_bar_edge_margin = (PBL_DISPLAY_WIDTH - 44) / 2; // 44 is the width of the countdown ((3*16)-4)
s_clock_txt_layer = text_layer_create(GRect(0, 4, s_top_bar_edge_margin, s_small_top_bar_height));
text_layer_set_background_color(s_clock_txt_layer, GColorClear);
text_layer_set_text_color(s_clock_txt_layer, GColorWhite);
text_layer_set_text_alignment(s_clock_txt_layer, GTextAlignmentCenter);
text_layer_set_font(s_clock_txt_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
layer_add_child(window_layer, text_layer_get_layer(s_clock_txt_layer));
// countdown
s_countdown_txt_layer = text_layer_create(s_top_bar_text_grect);
s_countdown_txt_layer = text_layer_create(GRect(0, (s_small_top_bar_height / 2) - PBL_IF_ROUND_ELSE(6, 10), PBL_DISPLAY_WIDTH, s_small_top_bar_height));
text_layer_set_background_color(s_countdown_txt_layer, GColorClear);
text_layer_set_text_color(s_countdown_txt_layer, GColorWhite);
text_layer_set_text_alignment(s_countdown_txt_layer, GTextAlignmentCenter);
@@ -769,11 +785,11 @@ static void alarm_window_load() {
layer_add_child(window_layer, text_layer_get_layer(s_countdown_txt_layer));
// progress
s_progress_txt_layer = text_layer_create(s_top_bar_text_grect);
s_progress_txt_layer = text_layer_create(GRect(PBL_DISPLAY_WIDTH - s_top_bar_edge_margin, 4, s_top_bar_edge_margin, s_small_top_bar_height));
text_layer_set_background_color(s_progress_txt_layer, GColorClear);
text_layer_set_text_color(s_progress_txt_layer, GColorWhite);
text_layer_set_text_alignment(s_progress_txt_layer, GTextAlignmentRight);
text_layer_set_font(s_progress_txt_layer, s_font_lecoish_small);
text_layer_set_text_alignment(s_progress_txt_layer, GTextAlignmentCenter);
text_layer_set_font(s_progress_txt_layer, fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS));
layer_add_child(window_layer, text_layer_get_layer(s_progress_txt_layer));
// x (incorrect equation icon)
@@ -800,7 +816,7 @@ static void alarm_window_load() {
// schedule recovery alarm and begin countdown :)
schedule_alarm(WAKE_RECOVERY_ALARM);
accel_tap_service_subscribe(accel_tap_handler);
tick_timer_service_subscribe(SECOND_UNIT, alarm_seconds_handler);
tick_timer_service_subscribe(SECOND_UNIT | MINUTE_UNIT, alarm_tick_handler);
}
static void alarm_window_unload() {