示例#1
0
文件: clock.c 项目: Herschee/Watchdog
static void init() {
  // Subscribe to Wakeup API
  wakeup_service_subscribe(wakeup_handler);
  
  // Register callbacks
  app_message_register_inbox_received(inbox_received_callback);
  app_message_register_inbox_dropped(inbox_dropped_callback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);
  app_message_open(400,400);
  
  // Was this a wakeup launch?
  if (launch_reason() == APP_LAUNCH_WAKEUP) {
    // The app was started by a wakeup
    WakeupId id = 0;
    int32_t reason = 0;

    // Get details and handle the wakeup
    wakeup_get_launch_event(&id, &reason);
    wakeup_handler(id, reason);
  } else {
    // Launch main page
    init_main_window();
    
    // Launch the splash page
    init_splash_window();
  }
}
示例#2
0
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();
}
示例#3
0
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;
  }
}
示例#4
0
int main(void) {
  if (launch_reason() == APP_LAUNCH_WAKEUP) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "launch wakeup");
    wakeup_service_subscribe(NULL);
    BatteryChargeState charge_state = battery_state_service_peek();
    save_charge_state(&charge_state);
    schedule_wakeup_measure_battery_state();
    app_event_loop();
  } else {
    handle_init();
    app_event_loop();
    handle_deinit();
  }
}