Initial code commit

This commit is contained in:
2026-05-15 19:10:34 -04:00
parent 2997b933e8
commit 6e8d254d17
5 changed files with 218 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
#include <pebble.h>
// window statics
static Window *s_main_window;
static TextLayer *s_time_mg_layer;
static TextLayer *s_time_layer;
// static GFont s_civic_font;
static const GRect s_time_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT);
// persist statics&defines
static GColor8 s_led_color;
static GColor8 s_bg_color;
static GColor8 s_mg_color;
static GColor8 s_fg_color;
#define storage_key_led_color 0
#define storage_key_bg_color 1
#define storage_key_mg_color 2
#define storage_key_fg_color 3
static void main_window_load() {
Layer *window_layer = window_get_root_layer(s_main_window);
if (persist_exists(storage_key_led_color)) {
light_set_color_rgb888(persist_read_int(storage_key_led_color));
} else {
light_set_color(GColorWhite);
}
if (persist_exists(storage_key_bg_color)) {
window_set_background_color(s_main_window, (GColor8){.argb = persist_read_int(storage_key_bg_color)});
} else {
window_set_background_color(s_main_window, GColorBlue);
}
if (persist_exists(storage_key_mg_color)) {
s_time_mg_layer = text_layer_create(s_time_grect);
text_layer_set_background_color(s_time_mg_layer, GColorClear);
text_layer_set_text_color(s_time_mg_layer, (GColor8){.argb = persist_read_int(storage_key_mg_color)});
// text_layer_set_font(s_time_mg_layer, s_civic_font);
layer_add_child(window_layer, text_layer_get_layer(s_time_mg_layer));
}
if (persist_exists(storage_key_fg_color)) {
text_layer_set_text_color(s_time_layer, (GColor8){.argb = persist_read_int(storage_key_fg_color)});
} else {
text_layer_set_text_color(s_time_layer, GColorWhite);
}
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
}
static void main_window_unload() {
if (s_time_mg_layer) {
text_layer_destroy(s_time_mg_layer);
}
}
static void update_minute_1() {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
static char s_time_buffer[8];
strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", tick_time);
text_layer_set_text(s_time_layer, s_time_buffer);
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
update_minute_1();
}
static void soft_reload(bool first_load) {
if (!first_load) {
window_stack_remove(s_main_window, false);
window_destroy(s_main_window);
}
s_main_window = window_create();
window_set_window_handlers(
s_main_window,
(WindowHandlers){.load = main_window_load, .unload = main_window_unload});
window_stack_push(s_main_window, false);
}
static void init() {
// s_civic_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_CIVIC_FONT_100));
s_time_layer = text_layer_create(s_time_grect);
text_layer_set_background_color(s_time_layer, GColorClear);
// text_layer_set_font(s_time_layer, s_civic_font);
update_minute_1();
soft_reload(true);
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
}
static void deinit() {
tick_timer_service_unsubscribe();
// fonts_unload_custom_font(s_civic_font);
text_layer_destroy(s_time_layer);
window_destroy(s_main_window);
}
int main(void) {
init();
app_event_loop();
deinit();
}