static void handle_init(void) { s_main_window = window_create(); Layer *window_layer = window_get_root_layer(s_main_window); GRect bounds = layer_get_frame(window_layer); s_battery_layer = text_layer_create(GRect(0, 0, 144, 20)); window_stack_push(s_main_window, true); s_graph_layer = layer_create(grect_crop(GRect(0, 0, bounds.size.w, bounds.size.h - 34), 10)); layer_set_update_proc(s_graph_layer, update_graph_layer); s_battery_layer = text_layer_create(GRect(0, bounds.size.h - 34, bounds.size.w, 34)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentCenter); text_layer_set_text(s_battery_layer, "12/31 23:59 100%"); layer_add_child(window_layer, s_graph_layer); layer_add_child(window_layer, text_layer_get_layer(s_battery_layer)); wakeup_service_subscribe(handle_wakeup); wakeup_cancel_all(); schedule_wakeup_measure_battery_state(); BatteryChargeState charge_state = battery_state_service_peek(); save_charge_state(&charge_state); update_last_charge_log(); }
void SetGameAlarm(struct tm *gameTime, time_t startTime, int32_t nGame) { // make sure there are no pending wakeups wakeup_cancel_all(); wakeup_service_subscribe(DoGameAlarm); time_t when = startTime; switch (gameTime->tm_wday) { case 0: // Sunday, just use start time break; case 6: // Saturday, search the train schedule when -= s_SaturdayTrains[0]; // backup based on station stop break; default: // Weekday schedule when -= s_WeekDayTrains[0]; break; } if(bSetAlarm){ bSetAlarm = false; when = time(NULL); when += 15; wakeme = wakeup_schedule(when, nGame, false); } int x = s_StationStops[0]; if (!x) { bToday = false; } }
// Initialize the program static void prv_initialize(void) { // cancel any existing wakeup events wakeup_cancel_all(); // load timer timer_persist_read(); // set initial states if (timer_is_paused()) { // get time parts uint16_t hr, min, sec; timer_get_time_parts(&hr, &min, &sec); if (hr) { main_data.control_mode = ControlModeEditHr; } else { main_data.control_mode = ControlModeEditMin; } } else { main_data.control_mode = ControlModeCounting; } // initialize window main_data.window = window_create(); ASSERT(main_data.window); window_set_click_config_provider(main_data.window, prv_click_config_provider); Layer *window_root = window_get_root_layer(main_data.window); GRect window_bounds = layer_get_bounds(window_root); #ifdef PBL_SDK_2 window_set_fullscreen(main_data.window, true); window_bounds.size.h = 168; #endif window_stack_push(main_data.window, true); // initialize main layer main_data.layer = layer_create(window_bounds); ASSERT(main_data.layer); layer_set_update_proc(main_data.layer, prv_layer_update_proc_handler); layer_add_child(window_root, main_data.layer); // initialize drawing singleton drawing_initialize(main_data.layer); // subscribe to tick timer service tick_timer_service_subscribe(MINUTE_UNIT, prv_tick_timer_service_callback); // start refreshing prv_app_timer_callback(NULL); }