Ejemplo n.º 1
0
/* Initializes the watchface */
void handle_init(void) {
  window = window_create();
  window_set_background_color(window, GColorBlack);
  
  app_message_register_inbox_received((AppMessageInboxReceived) in_recv_handler);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  /*
  bool user_zero = persist_read_bool(KEY_ZERO);
  bool user_battery = persist_read_bool(KEY_BATTERY);
  bool user_bluetooth = persist_read_bool(KEY_BLUETOOTH);
  */
  /* Sets the custom fonts as resources. */
  GFont abadi_62 = 
    fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ARIAL_NARROW_BOLD_69));
  GFont abadi_24 =
    fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ABADI_CONDENSED_20));
  
  /* Sets the transparent image as a resource. */
  bt_white_image = gbitmap_create_with_resource(RESOURCE_ID_WARNING_SIGN_WHITE);
//  bt_black_image = gbitmap_create_with_resource(RESOURCE_ID_WARNING_SIGN_BLACK);
  
  //HOUR LAYER
  hour_layer = text_layer_create(GRect(0,0, 82, 84));
  text_layer_set_font(hour_layer, abadi_62);
  text_layer_set_text_alignment(hour_layer, GTextAlignmentRight);
  text_layer_set_background_color(hour_layer, GColorBlack);
  text_layer_set_text_color(hour_layer, GColorWhite);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(hour_layer));
  
  //MINUTE LAYER
  min_layer = text_layer_create(GRect(64, 80, 80, 88));
  text_layer_set_font(min_layer, abadi_62);
  text_layer_set_text_alignment(min_layer, GTextAlignmentLeft);
  text_layer_set_background_color(min_layer, GColorBlack);
  text_layer_set_text_color(min_layer, GColorWhite);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(min_layer));
  
  //AM PM LAYER
  am_layer = text_layer_create(GRect(82, 32, 62, 36));
  text_layer_set_font(am_layer, abadi_24);
  text_layer_set_text_alignment(am_layer, GTextAlignmentCenter);
  text_layer_set_background_color(am_layer, GColorBlack);
  text_layer_set_text_color(am_layer, GColorWhite);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(am_layer));
  
  //DATE LAYER
  date_layer = text_layer_create(GRect(0, 102, 64, 84));  //Manually centered vertically
  text_layer_set_font(date_layer, abadi_24);
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  text_layer_set_background_color(date_layer, GColorBlack);
  text_layer_set_text_color(date_layer, GColorWhite);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));
  
  //BATTERY PERCENTAGE LAYER
  battery_layer = text_layer_create(GRect(0, 0, 0, 0)); //Creates the battery layer
  text_layer_set_background_color(battery_layer, GColorWhite);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(battery_layer));
  
  //IMAGE LAYERS
  /* Uses GCompOpOr to display white portions of image */
  bt_white_image_layer = bitmap_layer_create(GRect(82, 28, 62, 36)); //Matches am_layer, removes text buffer of 4 px
  bitmap_layer_set_bitmap(bt_white_image_layer, bt_white_image);
  bitmap_layer_set_alignment(bt_white_image_layer, GAlignCenter);
  bitmap_layer_set_background_color(bt_white_image_layer, GColorBlack);
  bitmap_layer_set_compositing_mode(bt_white_image_layer, GCompOpOr);
  
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bt_white_image_layer));
  
  /* Uses GCompOpOr to display black portions of image */
  /*
  bt_black_image_layer = bitmap_layer_create(GRect(82, 32, 62, 36)); //Matches am_layer
  bitmap_layer_set_bitmap(bt_black_image_layer, bt_white_image);
  bitmap_layer_set_alignment(bt_black_image_layer, GAlignCenter);
  bitmap_layer_set_compositing_mode(bt_black_image_layer, GCompOpOr);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bt_black_image_layer));
  */
  
  if(settings.bluetoothWarning == 1){
  update_bluetooth_state(bluetooth_connection_service_peek());
  bluetooth_connection_service_subscribe(update_bluetooth_state);
  }
  
  if(settings.batteryBar == 1){
  update_battery_state(battery_state_service_peek()); 
  battery_state_service_subscribe(update_battery_state);
  }
  
  //TIME CHANGES
  /* Call the function to update time upon starting the watchface */
  time_t now = time(NULL);
  
  handle_timechanges(localtime(&now), MINUTE_UNIT | HOUR_UNIT);
  //handle_hourchanges(localtime(&now), HOUR_UNIT);
  
  /* Every minute, calls the handle_timechanges function */
  tick_timer_service_subscribe(MINUTE_UNIT, handle_timechanges);  
  
  window_stack_push(window, true);
}
Ejemplo n.º 2
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  Layer *window_layer = window_get_root_layer(window);

  // Setup weather bar
  Layer *weather_holder = layer_create(GRect(0, 0, 144, 50));
  layer_add_child(window_layer, weather_holder);

  icon_layer = bitmap_layer_create(GRect(8, 7, 40, 40));
  layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer));

  temp_layer = text_layer_create(GRect(32, 10, 144 - 40, 28));
  text_layer_set_text_color(temp_layer, GColorWhite);
  text_layer_set_background_color(temp_layer, GColorClear);
  text_layer_set_font(temp_layer,
      fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(temp_layer, GTextAlignmentRight);
  layer_add_child(weather_holder, text_layer_get_layer(temp_layer));

  // Initialize date & time text
  Layer *date_holder = layer_create(GRect(0, 52, 144, 94));
  layer_add_child(window_layer, date_holder);

  ResHandle roboto_21 = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21);
  text_day_layer = text_layer_create(GRect(8, 0, 144-8, 25));
  text_layer_set_text_color(text_day_layer, GColorWhite);
  text_layer_set_background_color(text_day_layer, GColorClear);
  text_layer_set_font(text_day_layer, fonts_load_custom_font(roboto_21));
  layer_add_child(date_holder, text_layer_get_layer(text_day_layer));

  text_date_layer = text_layer_create(GRect(8, 21, 144-8, 25));
  text_layer_set_text_color(text_date_layer, GColorWhite);
  text_layer_set_background_color(text_date_layer, GColorClear);
  text_layer_set_font(text_date_layer, fonts_load_custom_font(roboto_21));
  layer_add_child(date_holder, text_layer_get_layer(text_date_layer));

  line_layer = layer_create(GRect(8, 47, 144-16, 2));
  layer_set_update_proc(line_layer, line_layer_update_callback);
  layer_add_child(date_holder, line_layer);
	
  line_layer = layer_create(GRect(8, 0, 144-16, 2));
  layer_set_update_proc(line_layer, line_layer_update_callback);
  layer_add_child(date_holder, line_layer);

  ResHandle roboto_49 = resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49);
  text_time_layer = text_layer_create(GRect(7, 45, 144-7, 49));
  text_layer_set_text_color(text_time_layer, GColorWhite);
  text_layer_set_background_color(text_time_layer, GColorClear);
  text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
  text_layer_set_font(text_time_layer, fonts_load_custom_font(roboto_49));
  layer_add_child(date_holder, text_layer_get_layer(text_time_layer));

  // Setup messaging
  const int inbound_size = 64;
  const int outbound_size = 64;
  app_message_open(inbound_size, outbound_size);

  Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 13),
    TupletCString(WEATHER_TEMPERATURE_KEY, ""),
    TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
  };

  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values,
                ARRAY_LENGTH(initial_values), sync_tuple_changed_callback,
                NULL, NULL);

  // FIXME testing code
  battery_text_layer = text_layer_create(GRect(0, 53, 144-8, 30));
  text_layer_set_text_color(battery_text_layer, GColorWhite);
  text_layer_set_background_color(battery_text_layer, GColorClear);
  text_layer_set_font(battery_text_layer, fonts_load_custom_font(roboto_21));
  text_layer_set_text_alignment(battery_text_layer, GTextAlignmentRight);
  layer_add_child(window_layer, text_layer_get_layer(battery_text_layer));

  // Subscribe to notifications
  bluetooth_connection_service_subscribe(bluetooth_connection_changed);
  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  battery_state_service_subscribe(update_battery_state);

  // Update the battery on launch
  update_battery_state(battery_state_service_peek());

  // TODO: Update display here to avoid blank display on launch?
}
Ejemplo n.º 3
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);
		
}