Esempio n. 1
0
void bluetooth_connection_callback(bool connected) {
  toggle_bluetooth(connected);
}
Esempio n. 2
0
void init() {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));
	
  const int inbound_size = 160;
  const int outbound_size = 160;
  app_message_open(inbound_size, outbound_size);  

  window = window_create();
  if (window == NULL) {
      return;
  }
	
    window_stack_push(window, true);
  
	background_color  = GColorBlack;
    window_set_background_color(window, background_color);
		
	Layer *window_layer = window_get_root_layer(window);

    GRect bounds = layer_get_frame(window_layer);
    path_layer = layer_create(bounds);
    layer_set_update_proc(path_layer, path_layer_update_callback);
    layer_add_child(window_layer, path_layer);

    // Pass the corresponding GPathInfo to initialize a GPath
    batt10 = gpath_create(&BATT10);
    batt20 = gpath_create(&BATT20);
    batt30 = gpath_create(&BATT30);
    batt40 = gpath_create(&BATT40);
    batt50 = gpath_create(&BATT50);
    batt60 = gpath_create(&BATT60);
    batt70 = gpath_create(&BATT70);
    batt80 = gpath_create(&BATT80);
    batt90 = gpath_create(&BATT90);
    batt100 = gpath_create(&BATT100);
  
	// Create time and date layers
    GRect dummy_frame = { {0, 0}, {0, 0} };
	
  for (int i = 0; i < TOTAL_TIME_DIGITS; ++i) {
    time_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i]));
  }

  time1_text_layer = text_layer_create(GRect(0, 64, 147, 30));
  text_layer_set_background_color(time1_text_layer, GColorClear);
  text_layer_set_text_color(time1_text_layer, GColorWhite);
  text_layer_set_text_alignment(time1_text_layer, GTextAlignmentCenter);
  text_layer_set_font(time1_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_BOLD_24)));
  text_layer_set_text(time1_text_layer, time1_buffer);
  layer_add_child(window_get_root_layer(window), (Layer*) time1_text_layer);
  

  date_text_layer = text_layer_create(GRect(0, 128, 144, 20));
  text_layer_set_background_color(date_text_layer, GColorClear);
  text_layer_set_text_color(date_text_layer, GColorWhite);
  text_layer_set_text_alignment(date_text_layer, GTextAlignmentCenter);
  text_layer_set_font(date_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELVETICA_16)));
  text_layer_set_text(date_text_layer, date_buffer);
  layer_add_child(window_get_root_layer(window), (Layer*) date_text_layer);
  
  toggle_bluetooth(bluetooth_connection_service_peek());
  battery_state_service_subscribe(&update_battery_state);

  Tuplet initial_values[] = {
    TupletInteger(SWAP_KEY, persist_read_bool(SWAP_KEY)),
    TupletInteger(INVERT_KEY, persist_read_bool(INVERT_KEY)),
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
  };
  
  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
      sync_tuple_changed_callback, NULL, NULL);
   
  appStarted = true;
  
  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  tick_handler(localtime(&now), DAY_UNIT + HOUR_UNIT + MINUTE_UNIT);
  tick_timer_service_subscribe(MINUTE_UNIT, (TickHandler) tick_handler);
	
  // update the battery on launch
  update_battery_state(battery_state_service_peek());
  bluetooth_connection_service_subscribe(bluetooth_connection_callback);
		
}