Beispiel #1
0
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  s_text_layer = text_layer_create(GRect(0, 1, bounds.size.w, bounds.size.h - 20));
  text_layer_set_background_color(s_text_layer, GColorBlack);
  text_layer_set_text_color(s_text_layer, GColorWhite);
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
  
  s_connection_layer = text_layer_create(GRect(0, 135, bounds.size.w, 34));
  text_layer_set_text_color(s_connection_layer, GColorWhite);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentRight);
  handle_bluetooth(bluetooth_connection_service_peek());

  s_battery_layer = text_layer_create(GRect(0, 150, bounds.size.w, 34));
  text_layer_set_text_color(s_battery_layer, GColorWhite);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight);
  text_layer_set_text(s_battery_layer, "100% charged");
  
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  update_time(t);

  tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick);
  battery_state_service_subscribe(handle_battery);
  bluetooth_connection_service_subscribe(handle_bluetooth);

  layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
}
Beispiel #2
0
void handle_appmessage_receive(DictionaryIterator *received, void *context) {
  Tuple *tuple = dict_read_first(received);
  while (tuple) {
    switch (tuple->key) {
      case SECONDS_MODE:
        seconds_mode = tuple->value->int32;
        break;
      case BATTERY_MODE:
        battery_mode = tuple->value->int32;
        break;
      case DATE_MODE:
        date_mode = tuple->value->int32;
        break;
      case BLUETOOTH_MODE:
        bluetooth_mode = tuple->value->int32;
        break;
      case GRAPHICS_MODE:
        graphics_mode = tuple->value->int32;
        break;
      case CONNLOST_MODE:
        connlost_mode = tuple->value->int32;
        break;
    }
    tuple = dict_read_next(received);
  }
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config");
  has_config = true;
  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_inverter();
}
void handle_init() {

  // Configure window
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, BKGD_COLOR);
  window_set_fullscreen(window, true);
  Layer *window_layer = window_get_root_layer(window);

  // Dynamic allocation of assets
  minuteFrame = GRect(53, 16, 40, 40);
  minuteLayer = text_layer_create(minuteFrame);
  hourLayer = bitmap_layer_create(GRect(0, 0, 144, 148));
  batteryLogoLayer = bitmap_layer_create(GRect(65, 151, 10, 15));
  batteryPercentLayer = text_layer_create(GRect(78, 150, 30, 167-150));
  dateLayer = text_layer_create(GRect(3, 150, 38, 167-150));
  dayLayer = text_layer_create(GRect(141-30, 150, 30, 167-150));
  text_layer_set_text_alignment(dayLayer, GTextAlignmentRight);
  bottomBarLayer = layer_create(GRect(1, 149, 142, 18));

  // Setup minute layer
  text_layer_set_text_color(minuteLayer, TEXT_COLOR);
  text_layer_set_background_color(minuteLayer, GColorClear);
  text_layer_set_font(minuteLayer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MINUTE_38)));

  // Setup date & day layer
  text_layer_set_text_color(dateLayer, TEXT_COLOR);
  text_layer_set_background_color(dateLayer, GColorClear);
  text_layer_set_text_color(dayLayer, TEXT_COLOR);
  text_layer_set_background_color(dayLayer, GColorClear);

  // Setup battery layers
  text_layer_set_text_color(batteryPercentLayer, TEXT_COLOR);
  text_layer_set_background_color(batteryPercentLayer, GColorClear);

  // Setup line layer
  layer_set_update_proc(bottomBarLayer, bottom_bar_layer_update_callback);

  // Add layers into hierachy
  layer_add_child(bitmap_layer_get_layer(hourLayer), text_layer_get_layer(minuteLayer));
  layer_add_child(window_layer, bitmap_layer_get_layer(hourLayer));
  layer_add_child(window_layer, bottomBarLayer);
  layer_add_child(window_layer, bitmap_layer_get_layer(batteryLogoLayer));
  layer_add_child(window_layer, text_layer_get_layer(batteryPercentLayer));
  layer_add_child(window_layer, text_layer_get_layer(dateLayer));
  layer_add_child(window_layer, text_layer_get_layer(dayLayer));

  // Avoids a blank screen on watch start.
  time_t tick_time = time(NULL);
  display_time(localtime(&tick_time));
  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());

  tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);

  initialized = true;
}
Beispiel #4
0
static void do_init(void) {
  window = window_create();

  window_stack_push(window, true);
  window_layer = window_get_root_layer(window);
  
  date_layer = text_layer_create(GRect(layers[0][0][0],layers[0][0][1],layers[0][1][0],layers[0][1][1]));
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  text_layer_set_text(date_layer, "");
  
  ampm_layer = text_layer_create(GRect(layers[3][0][0],layers[3][0][1],layers[3][1][0],layers[3][1][1]));
  text_layer_set_text_alignment(ampm_layer, GTextAlignmentCenter);
  text_layer_set_text(ampm_layer, "");
  text_layer_set_text_color(date_layer, GColorBlack);
  text_layer_set_background_color(date_layer, GColorWhite);
  text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16)));
  
  conn_layer = bitmap_layer_create(
    GRect(layers[1][0][0],layers[1][0][1],layers[1][1][0],layers[1][1][1]));
  load_icon_into_layer(0, bitmap_layer_get_layer(conn_layer));
  
  battery_layer = bitmap_layer_create(
    GRect(layers[2][0][0],layers[2][0][1],layers[2][1][0],layers[2][1][1]));
  load_icon_into_layer(0, bitmap_layer_get_layer(battery_layer));
  
  int adj = 0;
  for (int slot_number = 0; slot_number < TOTAL_IMAGE_SLOTS; slot_number++) {
    digit_slot[slot_number] = bitmap_layer_create(
        GRect(position[slot_number][0][0], position[slot_number][0][1], position[slot_number][1][0], position[slot_number][1][1]));
    
    load_digit_image_into_slot(slot_number, slot_number);
    layer_add_child(window_layer, bitmap_layer_get_layer(digit_slot[slot_number]));
  }
  
    time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  
  handle_second_tick(current_time, SECOND_UNIT);
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_battery(battery_state_service_peek());
  
  tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  
  layer_add_child(window_layer, text_layer_get_layer(date_layer));
  
  window_set_background_color(window, GColorWhite);
  text_layer_set_text_color(date_layer, GColorBlack);
  text_layer_set_background_color(date_layer, GColorWhite);
  text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16)));

  layer_add_child(window_layer, bitmap_layer_get_layer(conn_layer));
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer));
  
  layer_add_child(window_layer, text_layer_get_layer(ampm_layer));
}
Beispiel #5
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);
  
  fontRobotoCondensed19  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19));
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  triangle_overlay_layer = layer_create(bounds);
	layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback);
	layer_add_child(window_layer, triangle_overlay_layer);
	triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS);
	gpath_move_to(triangle_overlay_path, grect_center_point(&bounds));
  
  // init hand paths
  minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS);
  gpath_move_to(minute_arrow_path, grect_center_point(&bounds));
  
  hour_arrow_path = gpath_create(&HOUR_HAND_POINTS);
  gpath_move_to(hour_arrow_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  

  s_hands_layer = layer_create(bounds);

  layer_set_update_proc(s_hands_layer, hands_update_proc);
  layer_add_child(window_layer, s_hands_layer);
  
  // Battery Line Basalt
   #ifdef PBL_PLATFORM_BASALT
      GRect line_frame = GRect(22, 160, 104, 6);
      LineLayer = layer_create(line_frame);
      layer_set_update_proc(LineLayer, line_layer_update_callback);
      layer_add_child(window_layer, LineLayer);
   #else //Chalk
      GRect line_round_frame = GRect(1, 1, 180, 180);
      RoundBatteryLayer = layer_create(line_round_frame);
      layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback);
      layer_add_child(window_layer,RoundBatteryLayer);
   #endif
     
  //Service subscribes:
  battery_state_service_subscribe(&handle_battery);
  
  handle_battery(battery_state_service_peek());
  
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
     
  app_focus_service_subscribe(&handle_appfocus);

}
Beispiel #6
0
static void main_window_load(Window *window) {

  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);


  s_battery_layer = text_layer_create(PBL_IF_ROUND_ELSE(
    GRect(38, 12, bounds.size.w-76, 32),
    GRect(8, 6, bounds.size.w-16, 32)));
  text_layer_set_text_color(s_battery_layer, GColorBlack);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight);
  text_layer_set_text(s_battery_layer, "100%");

  s_date_layer = text_layer_create(PBL_IF_ROUND_ELSE(
    GRect(38, 12, bounds.size.w-76, 32),
    GRect(8, 6, bounds.size.w-16, 32)));
  text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentLeft);
  text_layer_set_text(s_date_layer, "Jan 1");

  s_time_layer = text_layer_create(GRect(0, 48, bounds.size.w, 56));
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_background_color(s_time_layer, GColorMidnightGreen);
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

  s_steps_layer = text_layer_create(GRect(0, 100, bounds.size.w, 32));
  text_layer_set_text_color(s_steps_layer, GColorBlack);
  text_layer_set_background_color(s_steps_layer, GColorCadetBlue);
  text_layer_set_font(s_steps_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_steps_layer, GTextAlignmentCenter);
  text_layer_set_text(s_steps_layer, "0 steps");

  s_connection_layer = text_layer_create(GRect(0, 136, bounds.size.w, 20));
  text_layer_set_text_color(s_connection_layer, GColorBlack);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
  handle_bluetooth(connection_service_peek_pebble_app_connection());

  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_minute_tick(current_time, MINUTE_UNIT);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  battery_state_service_subscribe(handle_battery);

  connection_service_subscribe((ConnectionHandlers) {
    .pebble_app_connection_handler = handle_bluetooth
  });
Beispiel #7
0
static void do_init(void) {
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
	window_layer = window_get_root_layer(window);
	
	GRect line_frame = GRect(8, 120, 139, 2);
	line_layer = layer_create(line_frame);
	layer_set_update_proc(line_layer, draw_line);
	layer_add_child(window_layer, line_layer);
	
	time_layer = text_layer_create(GRect(5, 66, 118, 70));
	text_layer_set_text_color(time_layer, GColorWhite);
	text_layer_set_background_color(time_layer, GColorClear);
	text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_44)));
	text_layer_set_text_alignment(time_layer,GTextAlignmentRight);
	layer_add_child(window_layer, text_layer_get_layer(time_layer));
	
	date_layer = text_layer_create(GRect(65, 125, 79, 25));
	text_layer_set_text_color(date_layer, GColorWhite);
	text_layer_set_background_color(date_layer, GColorClear);
	text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18)));
	layer_add_child(window_layer, text_layer_get_layer(date_layer));
	
	wday_layer = text_layer_create(GRect(60, 143, 50, 25));
	text_layer_set_text_color(wday_layer, GColorWhite);
	text_layer_set_background_color(wday_layer, GColorClear);
	text_layer_set_font(wday_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18)));
	layer_add_child(window_layer, text_layer_get_layer(wday_layer));
	
	//+時間のNULL回避?(わかってない→調べる
	
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_time_tick(current_time, SECOND_UNIT);
	
	tick_timer_service_subscribe(SECOND_UNIT, &handle_time_tick);

	batt_layer = bitmap_layer_create(GRect(123, 151, 14, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer)); //親レイヤに載せる 
	
	watchicon_layer = bitmap_layer_create(GRect(131, 151, 6, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(watchicon_layer));
	bitmap_layer_set_background_color(watchicon_layer, GColorClear);
	
	bt_layer = bitmap_layer_create(GRect(110, 151, 11, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer));
	
	handle_battery(battery_state_service_peek());
	battery_state_service_subscribe(&handle_battery);

	handle_bluetooth(bluetooth_connection_service_peek());
	bluetooth_connection_service_subscribe(&handle_bluetooth);
}
Beispiel #8
0
static void do_init(void) {

	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);

	Layer *root_layer = window_get_root_layer(window);
	GRect frame = layer_get_frame(root_layer);

	/* Background */
	Anonymous = gbitmap_create_with_resource(RESOURCE_ID_BG_ANONYMOUS);
	Anonymous_Layer = bitmap_layer_create(GRect(0, 0, WIDTH, HEIGHT));
	bitmap_layer_set_background_color(Anonymous_Layer, GColorBlack);
	bitmap_layer_set_bitmap(Anonymous_Layer, Anonymous);
	layer_add_child(root_layer, bitmap_layer_get_layer(Anonymous_Layer));

	/* Time block */
	time_layer = text_layer_create(GRect(0, 52, frame.size.w, 34));
	text_layer_set_text_color(time_layer, GColorBlack);
	text_layer_set_background_color(time_layer, GColorClear);
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD ));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);

	/* Bluetooth block */
	bt_connected = gbitmap_create_with_resource(RESOURCE_ID_BT_DISCONNECTED);
	bt_connected_layer = bitmap_layer_create(GRect(WIDTH - ICON_WIDTH, 1, ICON_WIDTH, ICON_HEIGHT));
	bitmap_layer_set_background_color(bt_connected_layer, GColorBlack);
	layer_add_child(root_layer, bitmap_layer_get_layer(bt_connected_layer));

	/* Battery block */
	battery_layer = text_layer_create(GRect(2, -2, frame.size.w, 16 ));
	text_layer_set_text_color(battery_layer, GColorWhite);
	text_layer_set_background_color(battery_layer, GColorClear);
	text_layer_set_font(battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(battery_layer, GTextAlignmentLeft);
	text_layer_set_text(battery_layer, "100% charged");

	/* Init blocks */
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_second_tick(current_time, SECOND_UNIT);

	tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
	battery_state_service_subscribe(&handle_battery);

	bool connected = bluetooth_connection_service_peek();
	handle_bluetooth(connected);
	bluetooth_connection_service_subscribe(&handle_bluetooth);

	layer_add_child(root_layer, text_layer_get_layer(time_layer));
	layer_add_child(root_layer, text_layer_get_layer(battery_layer));
}
Beispiel #9
0
void lost_connection_warning(void *data) {
  int count = (int) data;
  bool on_off = count & 1;
  // blink icon
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_images[on_off ? 1 : 0]);
  layer_set_hidden(bitmap_layer_get_layer(bluetooth_layer), false);
  // buzz 3 times
  if (count < 6 && !on_off)
    vibes_short_pulse();
  if (count < 50) // blink for 15 seconds
    app_timer_register(300, lost_connection_warning, (void*) (count+1));
  else // restore bluetooth icon
    handle_bluetooth(bluetooth_connection_service_peek());
}
static void main_window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_frame(window_layer);

    // Format all layers
    s_time_layer = text_layer_create(GRect(0, 50, bounds.size.w, 50));
    text_layer_set_text_color(s_time_layer, GColorWhite);
    text_layer_set_background_color(s_time_layer, GColorClear);
    text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
    text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

    s_connection_layer = text_layer_create(GRect(0, 145, bounds.size.w, 34));
    text_layer_set_text_color(s_connection_layer, GColorWhite);
    text_layer_set_background_color(s_connection_layer, GColorClear);
    text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
    text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);

    s_weekday_layer = text_layer_create(GRect(0, 105, bounds.size.w, 34));
    text_layer_set_text_color(s_weekday_layer, GColorWhite);
    text_layer_set_background_color(s_weekday_layer, GColorClear);
    text_layer_set_font(s_weekday_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
    text_layer_set_text_alignment(s_weekday_layer, GTextAlignmentCenter);

    s_date_layer = text_layer_create(GRect(0, 125, bounds.size.w, 34));    
    text_layer_set_text_color(s_date_layer, GColorWhite);
    text_layer_set_background_color(s_date_layer, GColorClear);
    text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
    text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);

    s_temperature_layer = text_layer_create(GRect(0, 20, bounds.size.w, 32));
    text_layer_set_text_color(s_temperature_layer, GColorWhite);
    text_layer_set_background_color(s_temperature_layer, GColorClear);
    text_layer_set_font(s_temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
    text_layer_set_text_alignment(s_temperature_layer, GTextAlignmentCenter);

    s_city_layer = text_layer_create(GRect(0, 0, bounds.size.w, 32));
    text_layer_set_text_color(s_city_layer, GColorWhite);
    text_layer_set_background_color(s_city_layer, GColorClear);
    text_layer_set_font(s_city_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
    text_layer_set_text_alignment(s_city_layer, GTextAlignmentCenter);
    
    handle_bluetooth(connection_service_peek_pebble_app_connection());
    connection_service_subscribe((ConnectionHandlers) {
        .pebble_app_connection_handler = handle_bluetooth
    });
Beispiel #11
0
void a_main (void) {

    struct remote_state rstate;
    memset(&rstate, 0, sizeof(rstate));

    //init mutexes and set period for bluethooth monitoring
    if (mutex_create(&rstate.mutex) != 0) error();
    // I think we will need a mutex for the roomba too.
   // if (mutex_create(&rstate.roomba_lock)!=0) error();

    rstate.period.tv_nsec = 10000000ULL;
    rstate.bluetooth_uart = 1;
    rstate.light_sensor_threshold = calculate_light_threshold();

    // Setup UART
    struct uart_opt uopt;
    memset(&uopt, 0, sizeof(uopt));
    uopt.baud = 9600;
    if (uart_init(rstate.bluetooth_uart, uopt) != 0) error();

    // Roomba
    uart_t roomba_uart = 2;

    if (roomba_create(&rstate.roomba, roomba_uart) != 0) error();
    if (roomba_safe_mode(&rstate.roomba) != 0) error();

    if (thread_set_priority(thread_self(), 0)!=0) error();

    if (roomba_song_load_death(&rstate.roomba, SONG_NUMBER_DEATH) != 0) error();

    //start the roomba test func
    if (thread_create(0, roomba_job, 0, &rstate)!=0) error();

    if (thread_create(0, sensor_job, 0, &rstate) !=0) error();

    //turn main thread into uart (bluethooth) thread
    handle_bluetooth(&rstate);

}
/***Handle Window***/
static void main_window_load(Window *window) {
	//Get information about the window
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);
	
	//Use platform specific background image
	s_bitmap = gbitmap_create_with_resource(
		PBL_IF_BW_ELSE(RESOURCE_ID_IMAGE_BACKGROUND_BW, RESOURCE_ID_IMAGE_BACKGROUND_COLOR));
	s_bitmap_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); //size of image
	bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet);
	bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap);
	window_set_background_color(s_main_window, GColorBlack);
	layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer));
	
	//Add custom font
	s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MONACO_14));	
		
	//Time layer
	s_time_layer = text_layer_create(GRect(5, 30, bounds.size.w, 40));
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_text_color(s_time_layer, GColorWhite);
	text_layer_set_font(s_time_layer, s_font);
	layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
	
	//Battery layer
	s_battery_layer = text_layer_create(GRect(5, 70, bounds.size.w, 50));
	text_layer_set_background_color(s_battery_layer, GColorClear);
	text_layer_set_text_color(s_battery_layer, GColorWhite);
	text_layer_set_font(s_battery_layer, s_font);
	layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
	
	//Connection layer
	s_connection_layer = text_layer_create(GRect(5, 100, bounds.size.w, 20));
	text_layer_set_background_color(s_connection_layer, GColorClear);
	text_layer_set_text_color(s_connection_layer, GColorWhite);
	text_layer_set_font(s_connection_layer, s_font);
	handle_bluetooth(connection_service_peek_pebble_app_connection());
	layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
	
	//Other text layer
	s_text_layer = text_layer_create(GRect(5, 125, bounds.size.w, 20));
	text_layer_set_background_color(s_text_layer, GColorClear);
	text_layer_set_text_color(s_text_layer, GColorWhite);
	text_layer_set_font(s_text_layer, s_font);
	text_layer_set_text(s_text_layer, "root@PC:/$");
	layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
	
	//Platform-specific cursor animation
	//Stationary cursor for Aplite
	#if defined (PBL_BW)
	s_bitmap_cursor = gbitmap_create_with_resource(RESOURCE_ID_STATIC_CURSOR);
	//Blinking cursor for Basalt
	#elif defined (PBL_COLOR)
	s_sequence = gbitmap_sequence_create_with_resource(RESOURCE_ID_BLINKING_CURSOR);
	GSize frame_size = gbitmap_sequence_get_bitmap_size(s_sequence);
	s_bitmap_cursor = gbitmap_create_blank(frame_size, GBitmapFormat8Bit);
	//Start the animation
	uint32_t first_delay_ms = 1000;
	app_timer_register(first_delay_ms, timer_handler, NULL);
	#endif
	
	s_bitmap_cursor_layer = bitmap_layer_create(GRect(90, 125, 10, 15));
	bitmap_layer_set_compositing_mode(s_bitmap_cursor_layer, GCompOpSet);
	bitmap_layer_set_bitmap(s_bitmap_cursor_layer, s_bitmap_cursor);
	layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_cursor_layer));
}
Beispiel #13
0
static void handle_init() {
  time_t clock = time(NULL);
  now = localtime(&clock);
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);
  Layer *window_layer = window_get_root_layer(window);

  background_layer = layer_create(GRect(0, 0, 144, 144));
  layer_set_update_proc(background_layer, background_layer_update_callback);
  layer_add_child(window_layer, background_layer);

  hands_layer = layer_create(layer_get_frame(background_layer));
  layer_set_update_proc(hands_layer, hands_layer_update_callback);
  layer_add_child(background_layer, hands_layer);

  for (int i = 0; i < 22; i++) {
    battery_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_0 + i);  
  }
  battery_layer = bitmap_layer_create(GRect(144-16-3, 3, 16, 10));
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer));

  for (int i = 0; i < 2; i++)
    bluetooth_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF + i);  
  bluetooth_layer = bitmap_layer_create(GRect(66, 0, 13, 13));
  layer_add_child(background_layer, bitmap_layer_get_layer(bluetooth_layer));

  battp_layer = text_layer_create(GRect(0, 0, 32, 16));
  text_layer_set_text_color(battp_layer, GColorWhite);
  text_layer_set_background_color(battp_layer, GColorBlack);
  layer_add_child(window_layer, text_layer_get_layer(battp_layer));
  
  hour_path = gpath_create(&HOUR_POINTS);
  hour_in_path = gpath_create(&HOUR_IN_POINTS);
  gpath_move_to(hour_path, GPoint(CENTER_X, CENTER_Y));
  gpath_move_to(hour_in_path, GPoint(CENTER_X, CENTER_Y));
  min_path = gpath_create(&MIN_POINTS);
  gpath_move_to(min_path, GPoint(CENTER_X, CENTER_Y));

  font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20));
  font2 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_28));

  time_layer = text_layer_create(GRect(25,146,94,24));
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  text_layer_set_text_color(time_layer, GColorWhite);
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_font(time_layer, font);
  layer_add_child(window_layer, text_layer_get_layer(time_layer));
  
  date_layer = text_layer_create(GRect(94, 136, 50, 50));
  text_layer_set_text_alignment(date_layer, GTextAlignmentRight);
  text_layer_set_text_color(date_layer, GColorWhite);
  text_layer_set_background_color(date_layer, GColorClear);
  text_layer_set_font(date_layer, font2);
  layer_add_child(window_layer, text_layer_get_layer(date_layer));

  day_layer = text_layer_create(GRect(0, 146, 50, 24));
  text_layer_set_text_alignment(day_layer, GTextAlignmentLeft);
  text_layer_set_text_color(day_layer, GColorWhite);
  text_layer_set_background_color(day_layer, GColorClear);
  text_layer_set_font(day_layer, font);
  layer_add_child(window_layer, text_layer_get_layer(day_layer));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  battery_state_service_subscribe(&handle_battery);
  handle_battery(battery_state_service_peek());
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_tick(now,1);
}
Beispiel #14
0
static void initialise_ui(void) {
  s_window = window_create();
  window_set_background_color(s_window, GColorBlack);
  window_set_fullscreen(s_window, true);
  
  s_res_background_image = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND_IMAGE);
  // s_bitmaplayer_1
  s_bitmaplayer_1 = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_bitmaplayer_1, s_res_background_image);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_1);
  
  //background_layer
  background_layer = layer_create(GRect(0,0,144,168));
  layer_set_update_proc(background_layer, background_update);
  layer_add_child(window_get_root_layer(s_window), (Layer*)background_layer);
  
  // s_layer_1
  s_layer_1 = layer_create(GRect(0, 0, 144, 168));
  layer_set_update_proc(s_layer_1, levels_update);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_layer_1);
  
  time_layer = text_layer_create(GRect(40,90,100,40));
  text_layer_set_text(time_layer, "141.12");
  #ifdef PBL_COLOR
    text_layer_set_text_color(time_layer, GColorElectricBlue);
  #else
    text_layer_set_text_color(time_layer, GColorWhite);
  #endif
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_text_alignment(time_layer, GTextAlignmentRight);
  text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_METAL_GEAR_17)));
  layer_add_child(window_get_root_layer(s_window), (Layer*)time_layer);
  
  charge_layer = text_layer_create(GRect(52,115,88,21));
  text_layer_set_text(charge_layer, "CHRG");
  #ifdef PBL_COLOR
    text_layer_set_background_color(charge_layer, GColorRed);
    text_layer_set_text_color(charge_layer, GColorBlack);
  #else
    text_layer_set_background_color(charge_layer, GColorWhite);
    text_layer_set_text_color(charge_layer, GColorBlack);
  #endif
  text_layer_set_text_alignment(charge_layer, GTextAlignmentCenter);
  text_layer_set_font(charge_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_METAL_GEAR_16)));
  layer_add_child(window_get_root_layer(s_window), (Layer*)charge_layer);
  layer_set_hidden((Layer*)charge_layer, true);
  
  bluetooth_layer = text_layer_create(GRect(16,10,100,40));
  text_layer_set_text(bluetooth_layer, "PTT");
  #ifdef PBL_COLOR
    text_layer_set_text_color(bluetooth_layer, GColorElectricBlue);
  #else
    text_layer_set_text_color(bluetooth_layer, GColorWhite);
  #endif
  text_layer_set_background_color(bluetooth_layer, GColorClear);
  text_layer_set_font(bluetooth_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_METAL_GEAR_13)));
  layer_add_child(window_get_root_layer(s_window), (Layer*)bluetooth_layer);
  
  level1 = gpath_create(&LEVEL_1_POINTS);
  level2 = gpath_create(&LEVEL_2_POINTS);
  level3 = gpath_create(&LEVEL_3_POINTS);
  level4 = gpath_create(&LEVEL_4_POINTS);
  level5 = gpath_create(&LEVEL_5_POINTS);
  level6 = gpath_create(&LEVEL_6_POINTS);
  
  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());
}
Beispiel #15
0
static void window_load(Window *window) {
  
  set_color_data();
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  APP_LOG(APP_LOG_LEVEL_DEBUG, "---- window_load ----");

  // Config
 //if (persist_read_bool(KEY_CONNECTION_LOST_VIBE)) {
    s_connection_lost_vibe = persist_read_bool(KEY_CONNECTION_LOST_VIBE);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_connection_lost_vibe %d", s_connection_lost_vibe);
 /// }
 //if (persist_read_bool(KEY_SHOW_SECONDS_HAND)) {
    s_show_seconds_hand = persist_read_bool(KEY_SHOW_SECONDS_HAND);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_show_seconds_hand %d", s_show_seconds_hand);
 // }
 //if (persist_read_bool(KEY_COLOR_REVERSE)) {
    s_color_reverse = persist_read_bool(KEY_COLOR_REVERSE);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "s_color_reverse %d", s_color_reverse);
    set_color_data();
  //}
  
  

  
  s_simple_bg_layer = layer_create(bounds);
  layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
  layer_add_child(window_layer, s_simple_bg_layer);

  s_date_layer = layer_create(bounds);
  layer_set_update_proc(s_date_layer, date_update_proc);
  layer_add_child(window_layer, s_date_layer);

  //s_day_label = text_layer_create(PBL_IF_ROUND_ELSE(
  //  GRect(63, 114, 27, 20),
  //  GRect(46, 114, 27, 20)));
  s_day_label = text_layer_create(
    GRect((int)(bounds.size.w / 2) + 20, bounds.size.h -98, 27,20));
  text_layer_set_text(s_day_label, s_day_buffer);
  text_layer_set_background_color(s_day_label, s_backColor);
  text_layer_set_text_color(s_day_label, s_textColor);
  text_layer_set_font(s_day_label, fonts_get_system_font(FONT_KEY_GOTHIC_18));

  layer_add_child(s_date_layer, text_layer_get_layer(s_day_label));

  //s_num_label = text_layer_create(PBL_IF_ROUND_ELSE(
  //  GRect(90, 114, 18, 20),
  //  GRect(73, 114, 18, 20)));
  s_num_label = text_layer_create(GRect((int)(bounds.size.w / 2) + 47, bounds.size.h -98, 18,20));
  text_layer_set_text(s_num_label, s_num_buffer);
  text_layer_set_background_color(s_num_label, s_backColor);
  text_layer_set_text_color(s_num_label, s_textColor);
  text_layer_set_font(s_num_label, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  // BT OK/NG
  s_connection_layer = text_layer_create(GRect((int)(bounds.size.w / 2) - 27,114, 20, 20));
  text_layer_set_text_color(s_connection_layer, s_textColor);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentLeft);
  handle_bluetooth(connection_service_peek_pebble_app_connection());

  // Battery
  s_battery_layer = text_layer_create(GRect((int)(bounds.size.w / 2) , 114,40,20));
  text_layer_set_text_color(s_battery_layer, s_textColor);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft);
  text_layer_set_text(s_battery_layer, "100%");

  battery_state_service_subscribe(handle_battery);

  connection_service_subscribe((ConnectionHandlers) {
    .pebble_app_connection_handler = handle_bluetooth
  });
Beispiel #16
0
//********************************** Handle Init **************************
void handle_init(void) {

  if (quiet_time_is_active()) {
     QuietTimeColor = GColorYellow;
     }
     else
     {  
     QuietTimeColor = GColorRed;
     }
  
  GColor BGCOLOR   = COLOR_FALLBACK(GColorDukeBlue, GColorBlack);
  BGColorHold = BGCOLOR;

  GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite);
  TextColorHold = TEXTCOLOR;

  window = window_create();
  window_set_background_color(window, BGCOLOR);
  window_stack_push(window, true /* Animated */);

  fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20));
  fontRobotoCondensed20  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_20));
  fontRobotoCondensed21  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21));
  fontRobotoBoldSubset37 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_37));
  fontRobotoBoldSubset49 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49));

  Layer *window_layer = window_get_root_layer(window);

  // 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);

  // Open AppMessage
  app_message_open(128, 128);

  //degrees
  text_degrees_layer = text_layer_create(GRect(30, 1, 60, 200));
  text_layer_set_text_alignment(text_degrees_layer, GTextAlignmentCenter);
  text_layer_set_text(text_degrees_layer, degreesstr);
  text_layer_set_font(text_degrees_layer, fontRobotoCondensed20);
  text_layer_set_background_color(text_degrees_layer, BGCOLOR);
  text_layer_set_text_color(text_degrees_layer, TEXTCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_degrees_layer));

  //degrees inside
  text_degrees_inside_layer = text_layer_create(GRect(85, 2, 55, 26));
  text_layer_set_text_alignment(text_degrees_inside_layer, GTextAlignmentRight);
  text_layer_set_text(text_degrees_inside_layer, degreesstr);
  text_layer_set_font(text_degrees_inside_layer, fontRobotoCondensed20);
  text_layer_set_background_color(text_degrees_inside_layer, BGCOLOR);
  text_layer_set_text_color(text_degrees_inside_layer, TEXTCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_degrees_inside_layer));


  // WA1OUI
  text_wa1oui_layer = text_layer_create(GRect(1,25, 144, 148));
  text_layer_set_text_alignment(text_wa1oui_layer, GTextAlignmentCenter);
  text_layer_set_text(text_wa1oui_layer, "WA1OUI");
  text_layer_set_font(text_wa1oui_layer, fontRobotoBoldSubset37);
  text_layer_set_text_color(text_wa1oui_layer, TEXTCOLOR);
  text_layer_set_background_color(text_wa1oui_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_wa1oui_layer));


  // Dayname
  text_dayname_layer = text_layer_create(GRect(1, 65, 35, 168-65));
  text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentLeft);
  text_layer_set_font(text_dayname_layer, fontRobotoCondensed20);
  text_layer_set_text_color(text_dayname_layer, TEXTCOLOR);
  text_layer_set_background_color(text_dayname_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer));
  
  
  // wind
  text_wind_layer = text_layer_create(GRect(37, 65, 60, 168-65));
  text_layer_set_text_alignment(text_wind_layer, GTextAlignmentCenter);
  text_layer_set_font(text_wind_layer, fontRobotoCondensed20);
  text_layer_set_text_color(text_wind_layer, TEXTCOLOR);
  text_layer_set_background_color(text_wind_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_wind_layer));
  
  // Rain
  text_rain_layer = text_layer_create(GRect(95, 65, 49, 168-65));
  text_layer_set_text_alignment(text_rain_layer, GTextAlignmentRight);
  text_layer_set_font(text_rain_layer, fontRobotoCondensed21);
  text_layer_set_text_color(text_rain_layer, TEXTCOLOR);
  text_layer_set_background_color(text_rain_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_rain_layer));
  

  // Date
  text_date_layer = text_layer_create(GRect(8, 88, 144-8, 168-88));
  text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);
  text_layer_set_font(text_date_layer, fontRobotoCondensed21);
  text_layer_set_text_color(text_date_layer, TEXTCOLOR);
  text_layer_set_background_color(text_date_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_date_layer));


  // Time of Day
  text_time_layer = text_layer_create(GRect(7, 116, 144-7, 168-116));
  text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
  text_layer_set_font(text_time_layer, fontRobotoBoldSubset49);
  text_layer_set_text_color(text_time_layer, TEXTCOLOR);
  text_layer_set_background_color(text_time_layer, BGCOLOR);
  layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

  // Red Line
  GRect red_line_frame = GRect(10, 28, 124, 2);
  RedLineLayer = layer_create(red_line_frame);
  layer_set_update_proc(RedLineLayer, red_line_layer_update_callback);
  layer_add_child(window_layer, RedLineLayer);

  // Battery Line
  GRect line_frame = GRect(22, 118, 104, 6);
  LineLayer = layer_create(line_frame);
  layer_set_update_proc(LineLayer, line_layer_update_callback);
  layer_add_child(window_layer, LineLayer);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);

  //Bluetooth Logo Setup area
  GRect BTArea = GRect(1, 5, 20, 20);
  BTLayer1 = layer_create(BTArea);

  layer_add_child(window_layer, BTLayer1);

  layer_set_update_proc(BTLayer1, BTLine_update_callback);

  bluetooth_connection_service_subscribe(&handle_bluetooth);

 
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_battery(battery_state_service_peek());

  //app focus service subscribe
  app_focus_service_subscribe(&handle_appfocus);
  
  // Ensures time is displayed immediately (will break if NULL tick event accessed).
  // (This is why it's a good idea to have a separate routine to do the update itself.)
  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_tick(current_time, SECOND_UNIT);
}
Beispiel #17
0
static void main_window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_frame(window_layer);

	// 時刻領域(数値時計)
	s_time_layer = text_layer_create(GRect(0, 0, bounds.size.w, 34));
	text_layer_set_text_color      (s_time_layer, GColorWhite);
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_font            (s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
	text_layer_set_text_alignment  (s_time_layer, GTextAlignmentCenter);

	// 時刻領域(元素記号時計)
	s_time_element_layer = text_layer_create(GRect(0, 22, bounds.size.w, 34));
	text_layer_set_text_color      (s_time_element_layer, GColorWhite);
	text_layer_set_background_color(s_time_element_layer, GColorClear);
	text_layer_set_font            (s_time_element_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
	text_layer_set_text_alignment  (s_time_element_layer, GTextAlignmentCenter);

	// 日付領域(元素記号)
	s_date_element_layer = text_layer_create(GRect(0, 55, bounds.size.w, 34));
	text_layer_set_text_color      (s_date_element_layer, GColorWhite);
	text_layer_set_background_color(s_date_element_layer, GColorClear);
	text_layer_set_font            (s_date_element_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
	text_layer_set_text_alignment  (s_date_element_layer, GTextAlignmentCenter);

	// 日付領域(数値)
	s_date_layer = text_layer_create(GRect(0, 80, bounds.size.w, 34));
	text_layer_set_text_color      (s_date_layer, GColorWhite);
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_font            (s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
	text_layer_set_text_alignment  (s_date_layer, GTextAlignmentCenter);

  // 初期値の表示	
	text_layer_set_text(s_time_layer, "01:23:45");
	text_layer_set_text(s_time_element_layer, "H:V:Rh");
	text_layer_set_text(s_date_layer, "2015/03/21");
	text_layer_set_text(s_date_element_layer, "CaP/Li/Sc");
	
	// 母艦との接続状態の表示
	s_connection_layer = text_layer_create(GRect(0, 110, bounds.size.w, 34));
	text_layer_set_text_color(s_connection_layer, GColorWhite);
	text_layer_set_background_color(s_connection_layer, GColorClear);
	text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
	text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
	handle_bluetooth(bluetooth_connection_service_peek());

	// 充電状態の表示
	s_battery_layer = text_layer_create(GRect(0, 130, bounds.size.w, 34));
	text_layer_set_text_color(s_battery_layer, GColorWhite);
	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, "100% charged");

	// Ensures time is displayed immediately (will break if NULL tick event accessed).
	// (This is why it's a good idea to have a separate routine to do the update itself.)
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_second_tick(current_time, SECOND_UNIT);

	tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
	battery_state_service_subscribe(handle_battery);
	bluetooth_connection_service_subscribe(handle_bluetooth);

	layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_time_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_date_element_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
	layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
}
static void init(void) {

  // Create window
  window = window_create();
  window_stack_push(window, true);

  // Set background as black
  window_set_background_color(window, GColorBlack);

  window_layer = window_get_root_layer(window);
 
  // Get the frame of the window and its bounds
  GRect frame = layer_get_frame(window_layer);
  GRect bounds = layer_get_bounds(window_layer);

  // Set the image as bluetooth.png from resources folder and defined in appinfo 
  bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
  // Create the layer to host the image
  bluetooth_layer = bitmap_layer_create(GRect(0,0,40,31));
  // Set the image into the layer
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);

  battery_text_layer = text_layer_create(GRect(70,3,30,25));
  text_layer_set_text_color(battery_text_layer, GColorWhite);
  text_layer_set_background_color(battery_text_layer, GColorClear);
  text_layer_set_text_alignment(battery_text_layer, GTextAlignmentCenter);
  text_layer_set_font(battery_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));

  battery_image = gbitmap_create_with_resource(IMAGE_BATTERY_RESOURCE_IDS[0]);
  battery_layer = bitmap_layer_create(GRect(100,0,40,31));
  bitmap_layer_set_bitmap(battery_layer, battery_image);


  background_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  background_layer = bitmap_layer_create(GRect(0,30,frame.size.w,51));
  bitmap_layer_set_alignment(background_layer, GAlignCenter); 
  bitmap_layer_set_bitmap(background_layer, background_image);


  number_day = text_layer_create(GRect(00,80,frame.size.w,114));
  text_layer_set_text_color(number_day, GColorWhite);
  text_layer_set_background_color(number_day, GColorClear);
  text_layer_set_text_alignment(number_day,GTextAlignmentCenter);
  text_layer_set_font(number_day,
      fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HALO_SUBSET_28)));


  month_layer = text_layer_create(GRect(00, 105, frame.size.w ,114));
  text_layer_set_text_color(month_layer, GColorWhite);
  text_layer_set_background_color(month_layer, GColorClear);
  text_layer_set_text_alignment(month_layer,GTextAlignmentCenter);
  // Font size = 22
  text_layer_set_font(month_layer,
      fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HALO_SUBSET_22)));


  // Create layer in position (x,y)=(00,130) with size (width, height)= width of the window, 114px height
  time_layer = text_layer_create(GRect(00 /* posicion  x */,
                                       130 /* posicion y*/,
                                       frame.size.w /* ancho */,
                                       114 /* alto */));
  // Set the color of the text as white
  text_layer_set_text_color(time_layer, GColorWhite);
  // Set the background as transparent
  text_layer_set_background_color(time_layer, GColorClear);
  // Align the text in center
  text_layer_set_text_alignment(time_layer,GTextAlignmentCenter);

  // Set the font of the text as a custom one found in the resources folder and defined in appinfo.json
  // with size = 28
  text_layer_set_font(time_layer,
      fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HALO_SUBSET_28)));


  // Layer that inverts the color of everything above
  inverter_layer = inverter_layer_create(bounds);

  // Get current time
  time_t now = time(NULL);  
  struct tm *current_time = localtime(&now);

  //Subscribe to services. Refresh time every minute
  handle_second_tick(current_time, MINUTE_UNIT);
  tick_timer_service_subscribe(MINUTE_UNIT, &handle_second_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_battery(battery_state_service_peek());

  layer_add_child(window_layer, bitmap_layer_get_layer(background_layer));
  layer_add_child(window_layer, text_layer_get_layer(time_layer));
  layer_add_child(window_layer, text_layer_get_layer(month_layer));
  layer_add_child(window_layer, text_layer_get_layer(number_day));
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));
  layer_add_child(window_layer, text_layer_get_layer(battery_text_layer));
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer));
  layer_add_child(window_layer, inverter_layer_get_layer(inverter_layer));
}
Beispiel #19
0
void handle_appfocus(bool in_focus){
    if (in_focus) {
        handle_bluetooth(bluetooth_connection_service_peek());
        handle_battery(battery_state_service_peek());
    }
}
Beispiel #20
0
void handle_init(void) {
  APP_LOG(APP_LOG_LEVEL_ERROR, "In Init * * * * * ");
  
  GColor BGCOLOR   = COLOR_FALLBACK(GColorDukeBlue, GColorBlack);
  BGColorHold = BGCOLOR;

  GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite);
  TextColorHold = TEXTCOLOR;

  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, BGCOLOR);

  fontHelvNewLight20     = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20));
  fontRobotoBoldSubset40 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_40));
  fontRobotoBoldSubset45 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_45));
  Layer *window_layer = window_get_root_layer(window);

  // 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);

  // Open AppMessage
  app_message_open(64, 64);

// Date
  #ifdef PBL_PLATFORM_CHALK
     text_date_layer = text_layer_create(GRect(1, 94, 180, 28));
  #else
     text_date_layer = text_layer_create(GRect(1, 94, 144, 28));
  #endif
  
  text_layer_set_text_color(text_date_layer, TEXTCOLOR);
  text_layer_set_background_color(text_date_layer, BGCOLOR);
  text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);;
  text_layer_set_font(text_date_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
  layer_add_child(window_layer, text_layer_get_layer(text_date_layer));

 //Persistent Value Date Format:
  if (persist_exists(MESSAGE_KEY_DATE_FORMAT_KEY)) {
     persist_read_string(MESSAGE_KEY_DATE_FORMAT_KEY  , PersistDateFormat, sizeof(PersistDateFormat));
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set Date Format to                    %s - Persistent - 0 = US, 1 = Int'l", PersistDateFormat);
  }  else {
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set Date Format to                    0 - Default - US");
     strcpy(PersistDateFormat, "0"); //Default
  }

  if (strcmp(PersistDateFormat, "0") == 0) {     // US
     strcpy(date_format, "%b %e %Y");
  } else {
     strcpy(date_format, "%e %b %Y");
  }

  //Persistent Value Vib On BTLoss
  if(persist_exists(MESSAGE_KEY_BT_VIBRATE_KEY)) {
     PersistBTLoss = persist_read_int(MESSAGE_KEY_BT_VIBRATE_KEY);
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set BT Vibrate To                     %d - Persistent - 0 = NO Vib, 1 = Vib", PersistBTLoss);
  }  else {
     PersistBTLoss = 0; // Default
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set BT Vibrate To                     0 - Default - No Vibrate");

  }

  //Persistent Value Vib on Low Batt
  if(persist_exists(MESSAGE_KEY_LOW_BATTERY_KEY)) {
     PersistLow_Batt = persist_read_int(MESSAGE_KEY_LOW_BATTERY_KEY);
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set Low Batt Vibrate To               %d - Persistent - 0 = NO Vib, 1 = Vib", PersistLow_Batt);
  }  else {
     PersistLow_Batt = 0; // Default
     APP_LOG(APP_LOG_LEVEL_INFO, "    Set Low Batt Vibrate To               0 - Default - No Vibrate");

  }
 
  // Time of Day
  #ifdef PBL_PLATFORM_CHALK
      text_time_layer = text_layer_create(GRect(1, 120, 180, 45));
      text_layer_set_font(text_time_layer,fontRobotoBoldSubset40);
  #else
      text_time_layer = text_layer_create(GRect(1, 120, 144, 45));
      text_layer_set_font(text_time_layer,fontRobotoBoldSubset45);
  #endif 
    
  text_layer_set_text_color(text_time_layer, TEXTCOLOR);
  text_layer_set_background_color(text_time_layer, BGCOLOR);
  text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

   // Dayname
  #ifdef PBL_PLATFORM_CHALK
      text_dayname_layer = text_layer_create(GRect(1, 74, 180, 26));
  #else
      text_dayname_layer = text_layer_create(GRect(1, 74, 144, 26));
  #endif
    
  text_layer_set_text_color(text_dayname_layer, TEXTCOLOR);
  text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentCenter);
  text_layer_set_background_color(text_dayname_layer, BGCOLOR);
  text_layer_set_font(text_dayname_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
  layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer));

  // Planetary Logo

  image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLANETARY_LOGO);
 
  #ifdef PBL_PLATFORM_CHALK
      image_layer = bitmap_layer_create(GRect(1, 29, 180, 49)); 
  #else
      image_layer = bitmap_layer_create(GRect(1, 29, 144, 49)); 
  #endif  
    
  bitmap_layer_set_bitmap(image_layer, image);
  bitmap_layer_set_alignment(image_layer, GAlignCenter);
  layer_add_child(window_layer, bitmap_layer_get_layer(image_layer));

   // Line
  #ifdef PBL_PLATFORM_CHALK
      GRect line_frame = GRect(38, 122, 104, 6);
  #else
      GRect line_frame = GRect(22, 122, 104, 6);
  #endif 
    
  BatteryLineLayer = layer_create(line_frame);
  layer_set_update_proc(BatteryLineLayer, battery_line_layer_update_callback);
  layer_add_child(window_layer, BatteryLineLayer);

  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);

  //Bluetooth Logo Setup area
  #ifdef PBL_PLATFORM_CHALK
      GRect BTArea = GRect(55, 5, 20, 20);
  #else
      GRect BTArea = GRect(1, 5, 20, 20);
  #endif 
    
  BTLayer = layer_create(BTArea);

  layer_add_child(window_layer, BTLayer);

  layer_set_update_proc(BTLayer, BTLine_update_callback);

  bluetooth_connection_service_subscribe(&handle_bluetooth);


  //Battery Text
  #ifdef PBL_PLATFORM_CHALK
      text_battery_layer = text_layer_create(GRect(80,2,55,28));
  #else
      text_battery_layer = text_layer_create(GRect(85,2,55,28));
  #endif
    
  text_layer_set_text_color(text_battery_layer, TEXTCOLOR);
  text_layer_set_background_color(text_battery_layer, BGCOLOR);
  text_layer_set_font(text_battery_layer,  fontHelvNewLight20 );
  text_layer_set_text_alignment(text_battery_layer, GTextAlignmentRight);

  layer_add_child(window_layer, text_layer_get_layer(text_battery_layer));

  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  app_focus_service_subscribe(&handle_appfocus);

  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());
  
  // Ensures time is displayed immediately (will break if NULL tick event accessed).
  // (This is why it's a good idea to have a separate routine to do the update itself.)
  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_tick(current_time, SECOND_UNIT);


}
Beispiel #21
0
/*
  Update status indicators for the battery and bluetooth connection
*/
void update_status( void ) {
  handle_battery( battery_state_service_peek() );
  handle_bluetooth( bluetooth_connection_service_peek() );
}
Beispiel #22
0
// Watchface initialization
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);

	// Set Background color to Black (For testing only)
	window_set_background_color(window, GColorBlack);

	// Initialize Globals
	mincount = 0;
	use_uq_weather = true;
	batt_img = gbitmap_create_with_resource(RESOURCE_ID_BATT_100);
	cond_img = gbitmap_create_with_resource(RESOURCE_ID_COND_LOADING);

	GRect bounds = layer_get_bounds(window_layer);

	// For debugging
	static char boundtext[20];
	snprintf(boundtext, 20, "w=%d, h=%d\ntest", bounds.size.w, bounds.size.h);

	// Build the time layer
	time_layer = text_layer_create(GRect(0, -10, 122, 50));
	text_layer_set_text(time_layer, "TIME");
	//text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
	text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_44)));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(time_layer));

	// Build the ampm layer
	ampm_layer = text_layer_create(GRect(122, -4, 22, 44));
	text_layer_set_font(ampm_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_20)));
	text_layer_set_text(ampm_layer, "A\nM");
	text_layer_set_text_alignment(ampm_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(ampm_layer));

	// Build the date layer
	date_layer = text_layer_create(GRect(0, 42, 144, 27));
	text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_20)));
	text_layer_set_text(date_layer, "Date");
	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(date_layer));  

	// Build the weather icon layer
	icon_layer = bitmap_layer_create(GRect(0, 73, 40, 40));
	bitmap_layer_set_background_color(icon_layer, GColorBlack);
	layer_add_child(window_layer, bitmap_layer_get_layer(icon_layer));

	// Build the temp layer
	temp_layer = text_layer_create(GRect(42, 71, 76, 43));
	text_layer_set_background_color(temp_layer, GColorClear);
	text_layer_set_text_color(temp_layer, GColorWhite);
	text_layer_set_font(temp_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIADB_32)));
	text_layer_set_text(temp_layer, "...");
	text_layer_set_text_alignment(temp_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(temp_layer));

	// Build the battery layer
	batt_layer = bitmap_layer_create(GRect(120, 73, 24, 40));
	bitmap_layer_set_background_color(batt_layer, GColorBlack);
	layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer));

	// Build the bitcoin price layer
	btc_layer = text_layer_create(GRect(0, 118, 144, 24));
	text_layer_set_font(btc_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_18)));
	text_layer_set_text(btc_layer, "Loading...");
	text_layer_set_text_alignment(btc_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(btc_layer));

	// Build the fitbit layer
	fitbit_layer = text_layer_create(GRect(0, 144, 144, 24));
	text_layer_set_font(fitbit_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MYRIAD_16)));
	text_layer_set_text(fitbit_layer, "Loading...");
	text_layer_set_text_alignment(fitbit_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(fitbit_layer));


	// Verify persistent storage for BTC daily value is setup
	check_bitcoin_persist();

	// Setup AppMessage
	app_message_init();

	// Subscribe to the minute tick
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

	// Force initial tick to inialize values
	time_t then = time(NULL);
	struct tm *now = localtime(&then);
	handle_minute_tick(now, SECOND_UNIT | MINUTE_UNIT | HOUR_UNIT | DAY_UNIT | MONTH_UNIT | YEAR_UNIT);

	// Subscribed to battery change events
	battery_state_service_subscribe(handle_battery);

	// Force initial battery check
	handle_battery(battery_state_service_peek());

	// Subscribe to bluetooth change events
	bluetooth_connection_service_subscribe(handle_bluetooth);

	// Force initial bluetooth state check
	handle_bluetooth(bluetooth_connection_service_peek());

	/*
	// Build the debugging text layer
	text_layer = text_layer_create(GRect(2, 54, 140, 80));
	text_layer_set_background_color(text_layer, GColorBlack);
	text_layer_set_text_color(text_layer, GColorWhite);
	text_layer_set_text(text_layer, boundtext);
	text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_layer));
	*/
}
Beispiel #23
0
void handle_appfocus(bool in_focus){
    if (in_focus) {
        handle_bluetooth(bluetooth_connection_service_peek());
        layer_mark_dirty(s_hands_layer);
    }
}
Beispiel #24
0
//battery
void handle_battery(BatteryChargeState charge) {
	
	// 充電中(時計アイコンを給電中の表示に切り替え、電池残量に応じた電池アイコンを表示)
	if (charge.is_charging){
		
		bitmap_layer_destroy(batt_layer);
		bitmap_layer_destroy(bt_layer);
		bt_layer = bitmap_layer_create(GRect(101, 151, 11, 10));
		batt_layer = bitmap_layer_create(GRect(114, 151, 14, 10));
		
		//pebble time用に追記("#ifdef PBL_COLOR" - "#endif" で分岐する)
		#ifdef PBL_COLOR
		if (charge.charge_percent >90){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_09));}
			else if (charge.charge_percent > 80){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_08));}
			else if (charge.charge_percent > 70){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_07));}
			else if (charge.charge_percent > 60){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_06));}
			else if (charge.charge_percent > 50){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_05));}
			else if (charge.charge_percent > 40){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_04));}
			else if (charge.charge_percent > 30){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_03));}
			else if (charge.charge_percent > 20){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_12));}
			else if (charge.charge_percent > 10){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_11));}
			else if (charge.charge_percent > 0){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_10));}
			else {
	        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_10));}
		
		#endif //pebble classic
		if (charge.charge_percent >90){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_09));}
			else if (charge.charge_percent > 80){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_08));}
			else if (charge.charge_percent > 70){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_07));}
			else if (charge.charge_percent > 60){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_06));}
			else if (charge.charge_percent > 50){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_05));}
			else if (charge.charge_percent > 40){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_04));}
			else if (charge.charge_percent > 30){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_03));}
			else if (charge.charge_percent > 20){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_12));}
			else if (charge.charge_percent > 10){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_11));}
			else if (charge.charge_percent > 0){
		        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_10));}
			else {
	        bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_10));}
		
		layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer));
		layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer));
		
		handle_bluetooth(bluetooth_connection_service_peek());
		bluetooth_connection_service_subscribe(&handle_bluetooth);

		bitmap_layer_set_bitmap(watchicon_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_thunder));
		}

	// 満充電時は給電中の表示からプラグアイコンに切り替える
	else if (charge.is_plugged){
		
		bitmap_layer_destroy(batt_layer);
		bitmap_layer_destroy(bt_layer);
		
		bt_layer = bitmap_layer_create(GRect(101, 151, 11, 10));
		batt_layer = bitmap_layer_create(GRect(114, 151, 14, 10));
		
		bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_09));
		bitmap_layer_set_bitmap(watchicon_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_FULL));
		bitmap_layer_set_compositing_mode(watchicon_layer, GCompOpAssign);
		
		layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer));
		layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer));
		
		handle_bluetooth(bluetooth_connection_service_peek());
		bluetooth_connection_service_subscribe(&handle_bluetooth);
	}

	// 給電していない場合は時計アイコンを表示し、電池残量に応じた電池アイコンを表示する
	else if (! charge.is_charging){
		bitmap_layer_set_bitmap(watchicon_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLANK));
		
		bitmap_layer_destroy(batt_layer);
		bitmap_layer_destroy(bt_layer);
		
		bt_layer = bitmap_layer_create(GRect(110, 151, 11, 10));
		batt_layer = bitmap_layer_create(GRect(123, 151, 14, 10));
		
		#ifdef PBL_COLOR
		if (charge.charge_percent > 90){
    	    bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_29));}
		else if (charge.charge_percent > 80){
			bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_28));}
		else if (charge.charge_percent > 70){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_27));}
		else if (charge.charge_percent > 60){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_26));}
		else if (charge.charge_percent > 50){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_25));}
		else if (charge.charge_percent > 40){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_24));}
		else if (charge.charge_percent > 30){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_23));}
		else if (charge.charge_percent > 20){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_02));}
		else if (charge.charge_percent > 10){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_01));}
		else if (charge.charge_percent > 0){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_00));}
    	else{
	        // 無いとは思うけどコレ以外の状況が発生した場合に対応するため以下を記載(電池アイコンの表示なし)
			layer_set_hidden(bitmap_layer_get_layer(batt_layer), true);
		}
		
		#endif
		if (charge.charge_percent > 90){
    	    bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_29));}
		else if (charge.charge_percent > 80){
			bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_28));}
		else if (charge.charge_percent > 70){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_27));}
		else if (charge.charge_percent > 60){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_26));}
		else if (charge.charge_percent > 50){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_25));}
		else if (charge.charge_percent > 40){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_24));}
		else if (charge.charge_percent > 30){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_23));}
		else if (charge.charge_percent > 20){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_02));}
		else if (charge.charge_percent > 10){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_01));}
		else if (charge.charge_percent > 0){
        	bitmap_layer_set_bitmap(batt_layer, gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_00));}
    	else{
	        // 無いとは思うけどコレ以外の状況が発生した場合に対応するため以下を記載(電池アイコンの表示なし)
			layer_set_hidden(bitmap_layer_get_layer(batt_layer), true);
		}
		
		handle_bluetooth(bluetooth_connection_service_peek());
		bluetooth_connection_service_subscribe(&handle_bluetooth);
		
		layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer));
		layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer));
		
	}
}
Beispiel #25
0
static void handle_bluetooth(bool connected)
{
	const VibePattern pattern = {
  			.durations = (uint32_t []) {100, 300, 300, 300, 100, 300},
  			.num_segments = 6
	};
	
	if(connected == false)
	{
		//layer_set_hidden((Layer *)ILDesconec, false);
		vibes_enqueue_custom_pattern(pattern);
	} else {
		//layer_set_hidden((Layer *)ILDesconec, true);
		//vibes_enqueue_custom_pattern(pattern);
	}
}

static void handle_battery(BatteryChargeState estado) {
	//GRect frame = layer_get_frame((Layer *) BLBat);
	//GPoint pos = {frame.origin.x, frame.origin.y};
	
	if (estado.is_charging) {
		//sustituye_imagen(&bateria_png, BLBat, RESOURCE_ID_CARGANDO_BLACK, pos);
	} else if (estado.is_plugged) {
		//sustituye_imagen(&bateria_png, BLBat, RESOURCE_ID_CARGANDO_BLACK, pos);
	} else {
		//sustituye_imagen(&bateria_png, BLBat, RESOURCE_ID_BATERIA_BLACK, pos);
	}
	static char buffer_b[] = "100 ";
	snprintf(buffer_b, sizeof(buffer_b), "%d", estado.charge_percent/10);
	text_layer_set_text(TLBateria, buffer_b);	
}

void handle_time(struct tm *tick_time, TimeUnits units_changed)
{
	if (units_changed & MINUTE_UNIT ) {
		// Cambios producidos cada minuto
		static char buffer_min[] = "  ";
		
		strftime(buffer_min,sizeof("00"),"%M",tick_time);
		text_layer_set_text(TLMinuto,buffer_min);
		
		handle_battery(battery_state_service_peek());
	}
	
	if (units_changed & HOUR_UNIT  || iniciaHora) {
    	iniciaHora = false;
		static char buffer_dia[] = "  ";
		static char buffer_hora[] = "  ";
		static char buffer_mes[] = "  ";
		
		static char txt_dia[] = "dom ";
		//static char txt_mes[] = "ene ";  
		int dia = tick_time->tm_wday;
		//int mes = tick_time->tm_mon;
    	strftime(buffer_hora,sizeof("00"),"%k",tick_time);
		text_layer_set_text(TLHora,buffer_hora);
		strncpy(txt_dia, dias[7*idioma+dia], sizeof(dias[7*idioma+dia]));
		text_layer_set_text(TLDiaSem, txt_dia);
		
		strftime(buffer_mes,sizeof("00"),"%m",tick_time);
		text_layer_set_text(TLMes,buffer_mes);

		strftime(buffer_dia,sizeof("00"),"%e",tick_time);
		text_layer_set_text(TLDia,buffer_dia);
     }
}

void window_load(Window *window)
{
	initialise_ui();
	//Para la primera vez, lanzo manualmente la actualización del reloj y bluetooth
	time_t temp = time(NULL);
	handle_time(localtime(&temp), MINUTE_UNIT);
	handle_battery(battery_state_service_peek());
	handle_bluetooth(bluetooth_connection_service_peek());
}
Beispiel #26
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  // init layers
  simple_bg_layer = layer_create(bounds);
  layer_set_update_proc(simple_bg_layer, bg_update_proc);
  layer_add_child(window_layer, simple_bg_layer);
  
  // init bitmaps
  background_bitmap = transbitmap_create_with_resource_prefix(RESOURCE_ID_IMAGE_BACKGROUND);
  bluetooth_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
  battery_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY);
  bluetooth_layer = bitmap_layer_create(GRect(1,168-30,30,30));
  bitmap_layer_set_bitmap(bluetooth_layer,bluetooth_bitmap);
  layer_set_hidden(bitmap_layer_get_layer(bluetooth_layer),true);
  battery_layer = bitmap_layer_create(GRect(143-32,167-20,32,20));
  bitmap_layer_set_bitmap(battery_layer,battery_bitmap);
  layer_set_hidden(bitmap_layer_get_layer(battery_layer),true);
  
  
  // init hands
  hands_layer = layer_create(bounds);
  layer_set_update_proc(hands_layer, hands_update_proc);
  
  GFont hour_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_SUBSET_24));
  GFont minute_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_SUBSET_20));
  for (int i=0;i<12;i++)
  {
    num_layer[i] = text_layer_create(GRect(1,1,40,20));
    snprintf(num_buffer[i],sizeof(num_buffer[i]),"%d",(i)*5);
    text_layer_set_text(num_layer[i],num_buffer[i]);
    text_layer_set_background_color(num_layer[i], GColorClear);
    text_layer_set_text_color(num_layer[i], GColorBlack);
    text_layer_set_text_alignment(num_layer[i],GTextAlignmentCenter);
    text_layer_set_font(num_layer[i], minute_font);
    layer_add_child(window_layer,text_layer_get_layer(num_layer[i]));
    layer_set_hidden(text_layer_get_layer(num_layer[i]),true);
    
    hour_layer[i] = text_layer_create(GRect(1,1,48,24));
    snprintf(hour_buffer[i],sizeof(hour_buffer[i]),"%d",(i+1));
    text_layer_set_text(hour_layer[i],hour_buffer[i]);
    text_layer_set_background_color(hour_layer[i], GColorClear);
    text_layer_set_text_color(hour_layer[i], GColorBlack);
    text_layer_set_font(hour_layer[i], hour_font);
    text_layer_set_text_alignment(hour_layer[i],GTextAlignmentCenter);
    layer_add_child(window_layer,text_layer_get_layer(hour_layer[i]));
    layer_set_hidden(text_layer_get_layer(hour_layer[i]),true);
  }
  
  
  // Inverter Layer
  inverter_layer = inverter_layer_create(bounds);
  layer_set_hidden(inverter_layer_get_layer(inverter_layer),!getInvert());
  layer_add_child(window_layer,inverter_layer_get_layer(inverter_layer));
  
  layer_add_child(window_layer, hands_layer);
  
  // Bluetooth Stuff
  bluetooth_connection_service_subscribe(handle_bluetooth);
  layer_add_child(window_layer,bitmap_layer_get_layer(bluetooth_layer));
  handle_bluetooth(bluetooth_connection_service_peek());
  
  // Battery Stuff
  battery_state_service_subscribe(handle_battery);
  layer_add_child(window_layer,bitmap_layer_get_layer(battery_layer));
  handle_battery(battery_state_service_peek());
  
  
  // Date Layer
  date_layer = text_layer_create(GRect(104,105,32,32));
  text_layer_set_text(date_layer,date_buffer);
  text_layer_set_background_color(date_layer,GColorClear);
  text_layer_set_text_color(date_layer,GColorWhite);
  text_layer_set_font(date_layer,hour_font);
  text_layer_set_text_alignment(date_layer,GTextAlignmentCenter);
  layer_add_child(window_layer,text_layer_get_layer(date_layer));
  layer_set_hidden(text_layer_get_layer(date_layer),true);
  
  // force update
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  snprintf(date_buffer, sizeof(date_buffer), "%d",t->tm_mday);
  handle_tick(t, MINUTE_UNIT);
  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);

}
Beispiel #27
0
void handle_init() {
  time_t clock = time(NULL);
  now = localtime(&clock);
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  date_layer = layer_create(GRect(0, 144, 144, 24));
  layer_set_update_proc(date_layer, &date_layer_update_callback);
  layer_add_child(window_get_root_layer(window), date_layer);

  background_layer = layer_create(GRect(0, 0, 144, 144));
  layer_set_update_proc(background_layer, &background_layer_update_callback);
  layer_add_child(window_get_root_layer(window), background_layer);

  logo = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO);  
  GRect frame = logo->bounds;
  grect_align(&frame, &GRect(0, 0, 144, 72), GAlignCenter, false);
  logo_layer = bitmap_layer_create(frame);
  bitmap_layer_set_bitmap	(logo_layer, logo);
  layer_add_child(background_layer, bitmap_layer_get_layer(logo_layer));

  hands_layer = layer_create(layer_get_frame(background_layer));
  layer_set_update_proc(hands_layer, &hands_layer_update_callback);
  layer_add_child(background_layer, hands_layer);

  for (int i = 0; i < 22; i++)
    battery_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_0 + i);  
  battery_layer = bitmap_layer_create(GRect(144-16-3, 3, 16, 10));
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(battery_layer));

  for (int i = 0; i < 2; i++)
    bluetooth_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF + i);  
  bluetooth_layer = bitmap_layer_create(GRect(66, 0, 13, 13));
  layer_add_child(background_layer, bitmap_layer_get_layer(bluetooth_layer));

#if DEBUG
  debug_layer = text_layer_create(GRect(0, 0, 32, 16));
  strcpy(debug_buffer, "");
  text_layer_set_text(debug_layer, debug_buffer);
  text_layer_set_text_color(debug_layer, GColorWhite);
  text_layer_set_background_color(debug_layer, GColorBlack);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(debug_layer));
#endif
  
  inverter_layer = inverter_layer_create(GRect(0, 0, 144, 168));
  layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter_layer));

  hour_path = gpath_create(&HOUR_POINTS);
  gpath_move_to(hour_path, GPoint(CENTER_X, CENTER_Y));
  min_path = gpath_create(&MIN_POINTS);
  gpath_move_to(min_path, GPoint(CENTER_X, CENTER_Y));
  sec_path = gpath_create(&SEC_POINTS);
  gpath_move_to(sec_path, GPoint(CENTER_X, CENTER_Y));

  font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_30));

  has_config = true;
  if (persist_exists(SECONDS_MODE)) seconds_mode = persist_read_int(SECONDS_MODE); else has_config = false;
  if (persist_exists(BATTERY_MODE)) battery_mode = persist_read_int(BATTERY_MODE); else has_config = false;
  if (persist_exists(DATE_MODE)) date_mode = persist_read_int(DATE_MODE); else has_config = false;
  if (persist_exists(BLUETOOTH_MODE)) bluetooth_mode = persist_read_int(BLUETOOTH_MODE); else has_config = false;
  if (has_config) APP_LOG(APP_LOG_LEVEL_DEBUG, "Loaded config");
  tick_timer_service_subscribe(hide_seconds ? MINUTE_UNIT : SECOND_UNIT, &handle_tick);
  battery_state_service_subscribe(&handle_battery);
  handle_battery(battery_state_service_peek());
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_inverter();
  app_message_register_inbox_received(&handle_appmessage_receive);
  app_message_open(INBOX_SIZE, OUTBOX_SIZE);
  if (!has_config) request_config();
}
Beispiel #28
0
void inicio(void)
{
  // Create our app's base window
  window = window_create();
  window_stack_push(window, true);
  window_set_background_color(window, GColorBlack);

  Layer *root_layer = window_get_root_layer(window);
  GRect frame = layer_get_frame(root_layer);
  
  
  //parte accelerometer

  text_layer_1 = text_layer_create(GRect(0, 0, frame.size.w, 22));
  text_layer_2 = text_layer_create(GRect(0, 22, frame.size.w, 18));
  text_layer_set_text_color(text_layer_1, GColorWhite);
  text_layer_set_background_color(text_layer_1, GColorClear);
  text_layer_set_text_color(text_layer_2, GColorWhite);
  text_layer_set_background_color(text_layer_2, GColorClear);
  layer_add_child(root_layer, text_layer_get_layer(text_layer_1));
  layer_add_child(root_layer, text_layer_get_layer(text_layer_2));
 
  accel_data_service_subscribe(1, accel_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
 
  accel_tap_service_subscribe(tap_handler);
  //----------------------
  

  // Init the text layer used to show the time
  time_layer = text_layer_create(GRect(0, 40, frame.size.w /* width */, 35/* height */));
  text_layer_set_text_color(time_layer, GColorWhite);
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  
  day_layer = text_layer_create(GRect(0, 75, frame.size.w /* width */, 30/* height */));
  text_layer_set_text_color(day_layer, GColorWhite);
  text_layer_set_background_color(day_layer, GColorClear);
  text_layer_set_font(day_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
  text_layer_set_text_alignment(day_layer, GTextAlignmentCenter);

  connection_layer = text_layer_create(GRect(0, 98, /* width */ frame.size.w, 24 /* height */));
  text_layer_set_text_color(connection_layer, GColorWhite);
  text_layer_set_background_color(connection_layer, GColorClear);
  text_layer_set_font(connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  text_layer_set_text_alignment(connection_layer, GTextAlignmentCenter);
  handle_bluetooth(bluetooth_connection_service_peek());

  battery_layer = text_layer_create(GRect(0, 120, /* width */ frame.size.w, 34 /* height */));
  text_layer_set_text_color(battery_layer, GColorWhite);
  text_layer_set_background_color(battery_layer, GColorClear);
  text_layer_set_font(battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  text_layer_set_text_alignment(battery_layer, GTextAlignmentCenter);
  text_layer_set_text(battery_layer, "100% cargado");

  // Ensures time is displayed immediately (will break if NULL tick event accessed).
  // (This is why it's a good idea to have a separate routine to do the update itself.)
  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_second_tick(current_time, SECOND_UNIT);

  tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);

  layer_add_child(root_layer, text_layer_get_layer(time_layer));
  layer_add_child(root_layer, text_layer_get_layer(day_layer));
  layer_add_child(root_layer, text_layer_get_layer(connection_layer));
  layer_add_child(root_layer, text_layer_get_layer(battery_layer));
}