// Handle the start-up of the app void init(void) { // Create our app's base window window = window_create(); window_stack_push(window, true); window_set_background_color(window, COLOR_BACKGROUND); // Init the layer that shows the board Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); boardLayer = layer_create(bounds); // Associate with layer object and set dimensions layer_set_update_proc(boardLayer, boardLayer_update_callback); // Set the drawing callback function for the layer. layer_add_child(window_layer, boardLayer); // Add the child to the app's base window // Init the layer that shows the player marks playersLayer = layer_create(bounds); layer_set_update_proc(playersLayer, playersLayer_update_callback); layer_add_child(window_layer, playersLayer); // Init the text layer used to show the time timeLayer = text_layer_create(GRect(0, 168-42, 144 /* width */, 42 /* height */)); text_layer_set_text_alignment(timeLayer, GTextAlignmentCenter); text_layer_set_text_color(timeLayer, COLOR_FOREGROUND); text_layer_set_background_color(timeLayer, GColorClear); text_layer_set_font(timeLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_layer, text_layer_get_layer(timeLayer)); tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick); update_time_text(); }
void show_watchface(void) { initialise_ui(); s_res_charging = gbitmap_create_with_resource(RESOURCE_ID_CHARGING); s_res_battery_20 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_20); s_res_battery_40 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_40); s_res_battery_60 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_60); s_res_battery_80 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_80); s_res_battery_100 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_100); layer_set_update_proc(sCalendarLayer, calendar_layer_update_callback); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); battery_state_service_subscribe(handle_battery); bluetooth_connection_service_subscribe(handle_bluetooth); sTimer = NULL; btStatus = bluetooth_connection_service_peek(); handle_battery(battery_state_service_peek()); currentTime = get_time(); update_time_text(); update_date_text(); layer_mark_dirty(sCalendarLayer); window_set_window_handlers(s_window, (WindowHandlers) { .unload = handle_window_unload, });
void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) { *currentTime = *tick_time; update_time_text(); if (units_changed & DAY_UNIT) { update_date_text(); layer_mark_dirty(sCalendarLayer); } }
/** * Tick function that is called every minute. * @param tick_time Time at which the tick even was triggered * @param units_changed Time interval at which the tick timer is triggered. */ static void tick_callback(struct tm *tick_time, TimeUnits units_changed) { if (tick_time->tm_min % 10 == 0){ send_all_eta_req(); } else { decrement_etas(); } refresh(); update_time_text(); }
/** * Function to process the data of a preset update. * @param data "DATA" response of the given message, formatted either * as "stop_id|stop_name|route_id|route_name", or as "END" to signify the end * of the preset messages. */ static void process_preset_data(char* data){ if (strcmp(data, "END") != 0){ data_processor_init(data, '|'); Preset *preset = malloc(sizeof(Preset)); strcpy(preset->stop_id, data_processor_get_string()); strcpy(preset->stop_name, data_processor_get_string()); strcpy(preset->route_id, data_processor_get_string()); strcpy(preset->route_name, data_processor_get_string()); preset->eta = -5; presets_add(preset); } else{ send_all_eta_req(); refresh(); reset_selected_index(); update_time_text(); } }
void handle_second_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; PblTm current_time; if(t) current_time = *t->tick_time; else get_time(¤t_time); update_seconds_text(¤t_time); if(current_time.tm_min != display_time.tm_min) update_time_text(¤t_time); if(current_time.tm_mday != display_time.tm_mday) update_date_text(¤t_time); }
/** * Function to process the data of an ETA update message. * @param data the "DATA" response of the given method, which is formatted as "stop_id|route_id|eta" */ static void process_eta_data(char* data){ data_processor_init(data, '|'); char* stop_id = data_processor_get_string(); char* route_id = data_processor_get_string(); char* eta_string = data_processor_get_string(); int eta = PRESET_NO_ETA; if (strcmp(eta_string, "NO ETA") != 0){ eta = atoi(eta_string); } for (int i = 0; i < presets_get_count(); i++){ Preset *preset = presets_get(i); if (strcmp(preset->stop_id, stop_id) == 0 && strcmp(preset->route_id, route_id) == 0){ preset->eta = eta; break; } } free(stop_id); free(route_id); refresh(); update_time_text(); }
// Called once per second static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) { update_time_text(); }