107 lines
3.2 KiB
C
107 lines
3.2 KiB
C
#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);
|
|
text_layer_set_text_alignment(s_time_mg_layer, GTextAlignmentCenter);
|
|
text_layer_set_text(s_time_mg_layer, "88\n88");
|
|
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\n%M" : "%I\n%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);
|
|
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
|
|
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();
|
|
}
|