static void init(void) {

  memset(&normal_time_digits_layers, 0, sizeof(normal_time_digits_layers));
  memset(&normal_time_digits_images, 0, sizeof(normal_time_digits_images));
		
  // Setup messaging
  const int inbound_size = 256;
  const int outbound_size = 256;
  app_message_open(inbound_size, outbound_size);	
	
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);

  window_set_background_color(window, GColorBlack);


  GRect dummy_frame = { {0, 0}, {0, 0} };

	for (int i = 0; i < TOTAL_NORMAL_DIGITS; ++i) {
    normal_time_digits_layers[i] = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(normal_time_digits_layers[i]));
  }	
 
	
	 // ** { begin setup mask for MASK effect
  mask.text = NULL;
  mask.bitmap_mask = NULL;

  #ifdef PBL_COLOR
    mask.mask_colors = malloc(sizeof(GColor)*4);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorDarkGray;
    mask.mask_colors[2] = GColorLightGray;
//    mask.mask_colors[3] = GColorClear;
  #else
    mask.mask_colors = malloc(sizeof(GColor)*2);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorClear;
  #endif
	  
  mask.background_color = GColorClear;
  mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK);


  // ** end setup mask }
	
  //creating effect layer
  effect_layer_mask = effect_layer_create(GRect(0,0,144,168));
  effect_layer_add_effect(effect_layer_mask, effect_mask, &mask);
  layer_add_child((window_layer), effect_layer_get_layer(effect_layer_mask));

	
	img_battery_100   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_100);
    img_battery_30   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_005_030);
    img_battery_00   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_005);
    img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING);
    layer_batt_img  = bitmap_layer_create(GRect(66, 102, 9,11));
	bitmap_layer_set_bitmap(layer_batt_img, img_battery_100);
	layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img));
		
   bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_ICON_NOBLUETOOTH);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds_bt_on = gbitmap_get_bounds(bluetooth_image);
#else
  GRect bitmap_bounds_bt_on = bluetooth_image->bounds;
#endif	
  GRect frame_bt = GRect(66, 102, bitmap_bounds_bt_on.size.w, bitmap_bounds_bt_on.size.h);
  bluetooth_layer = bitmap_layer_create(frame_bt);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));
	
	date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ODIN_24));

	layer_date_text = text_layer_create(GRect(0, 10, 144, 26));
	text_layer_set_text_color(layer_date_text, GColorWhite);		
    text_layer_set_background_color(layer_date_text, GColorClear);
    text_layer_set_font(layer_date_text, date_font);
    text_layer_set_text_alignment(layer_date_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_date_text));

	layer_ampm_text = text_layer_create(GRect(0, 114, 140, 26));
    text_layer_set_text_color(layer_ampm_text, GColorWhite);
	text_layer_set_background_color(layer_ampm_text, GColorClear);
    text_layer_set_font(layer_ampm_text, date_font);
    text_layer_set_text_alignment(layer_ampm_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_ampm_text));

	
  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  struct tm *tick_time = localtime(&now);  
  handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);

  Tuplet initial_values[] = {
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
	TupletInteger(FLIP_KEY, persist_read_bool(FLIP_KEY)),
	TupletInteger(COLOUR_KEY, persist_read_bool(COLOUR_KEY)),
	TupletInteger(BLINK_KEY, persist_read_bool(BLINK_KEY)),
  };

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

  appStarted = true;
 
	 // handlers
    battery_state_service_subscribe(&update_battery);
    bluetooth_connection_service_subscribe(&bluetooth_connection_callback);
    tick_timer_service_subscribe(SECOND_UNIT, handle_tick);

	 // draw first frame
    force_update();
}
void communication_init() {
  app_message_register_inbox_received(communication_in_received_callback);
  app_message_register_inbox_dropped(communication_in_dropped_callback);

  app_message_open(/* size_inbound */ 124, /* size_outbound */ 256);
}
Exemple #3
0
static void app_message_init(void) {
  app_message_register_inbox_received(in_received_handler);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  fetch_data();
}
Exemple #4
0
void handle_init(void) {
    my_window = window_create();
	window_set_background_color(my_window, GColorBlack);
    window_stack_push(my_window, true);

    date_text_layer = text_layer_create(GRect(8, 0, 144, 30));
    text_layer_set_font(date_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
    text_layer_set_text_alignment(date_text_layer, GTextAlignmentLeft);
    text_layer_set_text_color(date_text_layer, GColorSpringBud);	
    text_layer_set_background_color(date_text_layer, GColorBlack);
    text_layer_set_text(date_text_layer, "Sun Jan 1");
	layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(date_text_layer));	
 
    temp_text_layer = text_layer_create(GRect(8, 24, 144, 30));
    text_layer_set_font(temp_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
    text_layer_set_text_alignment(temp_text_layer, GTextAlignmentLeft);
    text_layer_set_text_color(temp_text_layer, GColorSpringBud);	
    text_layer_set_background_color(temp_text_layer, GColorBlack);
    text_layer_set_text(temp_text_layer, "0000\u00B0C");
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(temp_text_layer));	
	
    time_text_layer = text_layer_create(GRect(0, 46, 144, 80));
    text_layer_set_font(time_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_52)));
    text_layer_set_text_alignment(time_text_layer, GTextAlignmentCenter);
    text_layer_set_text_color(time_text_layer, GColorBrightGreen);	
    text_layer_set_background_color(time_text_layer, GColorBlack);
	text_layer_set_text(time_text_layer, "00:00");
	layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(time_text_layer));

	s_icon_layer = bitmap_layer_create(GRect(48, 27, 20, 20));
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(s_icon_layer));

    for (unsigned int i = 0; i < ARRAY_LENGTH(AMD_LOGO_BACKGROUND_RESOURCE_IDS); i++) {
        bkgd_amd_img[i] = gbitmap_create_with_resource(AMD_LOGO_BACKGROUND_RESOURCE_IDS[i]);
    }
    
    layer_bkgd_img  = bitmap_layer_create(GRect(0, 102, 144, 68));
    bitmap_layer_set_bitmap(layer_bkgd_img, bkgd_amd_img[0]);
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(layer_bkgd_img));	
 	
#if defined(PBL_COLOR)
    bt_connect_img     = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CONNECT);
    bt_disconnect_img  = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_DISCONNECT);
#elif defined(PBL_BW)
    bt_connect_img     = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CONNECT_BW);
    bt_disconnect_img  = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_DISCONNECT_BW);
#endif
    layer_conn_img     = bitmap_layer_create(GRect(118, 10, 20, 20));
    bitmap_layer_set_bitmap(layer_conn_img, bt_connect_img);
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(layer_conn_img));	

	bluetooth_connection_service_subscribe(&handle_bluetooth);
    tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	
	app_message_open(64, 64);
    Tuplet initial_values[] = {
    	TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
    	TupletCString(WEATHER_TEMPERATURE_KEY, "----\u00B0C"),
    	TupletCString(WEATHER_CITY_KEY, "St Pebblesburg"),
  	};
	app_sync_init(&s_sync, s_sync_buffer, sizeof(s_sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);
 }
Exemple #5
0
static void draw_proc(Layer *layer, GContext *ctx) {
  srand(time(NULL));  // For screenshots
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  
  int lastMin = 0;
  if (SCREENSHOT_RUN) {
    lastMin = s_last_time.seconds;  // For screenshots
  } else {
    lastMin = s_last_time.minutes;  // For real
  }

  for (int m = 0; m <= 59; m++) {
    if (m <= lastMin) {
      graphics_context_set_fill_color(ctx, getDotMainColor());
    } else {
      graphics_context_set_fill_color(ctx, getDotDarkColor());
    }
    
    int v = DOT_DISTANCE;
    
    int numDots = s_dotArray[m];
    
    if (m == lastMin || SCREENSHOT_RUN) {
      numDots = getNumDots();
      s_dotArray[m] = numDots;
    } else if (numDots == 0 && m <= lastMin) {
      numDots = 1;
    }

    // For each dot
    for (int i = 0; i < numDots; i++) {

      // Draw dot
      for(int y = 0; y < 1; y++) {
        for(int x = 0; x < 1; x++) {
          GPoint point = (GPoint) {
            .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * m / 60) * (int32_t)(v) / TRIG_MAX_RATIO) + center.x,
            .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * m / 60) * (int32_t)(v) / TRIG_MAX_RATIO) + center.y,
          };
          graphics_fill_circle(ctx, GPoint(point.x + x, point.y + y), s_dotSize);
        }
      }
      
      // Draw next dot farther away
      v += DOT_SPACING;
    }
  }
  
  if (config_get(PERSIST_KEY_WEATHER) && hasWeather) {
    // Get weather "minute"
    int m = weatherTemp % 60;
    
    // Get weather dot color
    if (weatherTemp < 0) {
      graphics_context_set_fill_color(ctx, GColorCeleste);
    } else if (weatherTemp < 60) {
      graphics_context_set_fill_color(ctx, GColorMediumAquamarine);
    } else {
      graphics_context_set_fill_color(ctx, GColorOrange);
    }
    
    // Draw dot
    int v = DOT_DISTANCE - DOT_SPACING - 1;
    for(int y = 0; y < 1; y++) {
      for(int x = 0; x < 1; x++) {
        GPoint point = (GPoint) {
          .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * m / 60) * (int32_t)(v) / TRIG_MAX_RATIO) + center.x,
          .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * m / 60) * (int32_t)(v) / TRIG_MAX_RATIO) + center.y,
        };
        graphics_fill_circle(ctx, GPoint(point.x + x, point.y + y), s_dotSize);
      }
    }
  }
}

static void health_handler(HealthEventType event, void *context) {
  // Which type of event occured?
  switch(event) {
    case HealthEventSignificantUpdate:
//       APP_LOG(APP_LOG_LEVEL_INFO, "New HealthService HealthEventSignificantUpdate event");
      break;
    case HealthEventMovementUpdate:
      APP_LOG(APP_LOG_LEVEL_INFO, "New HealthService HealthEventMovementUpdate event");
    
      // Mark layer dirty so it updates
      layer_mark_dirty(s_canvas_layer);
      break;
    case HealthEventSleepUpdate:
//       APP_LOG(APP_LOG_LEVEL_INFO, "New HealthService HealthEventSleepUpdate event");
      break;
  }
}

void comm_init() {
  app_message_register_inbox_received(in_recv_handler);
  
  // Register callbacks
  app_message_register_inbox_dropped(inbox_dropped_callback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);
  
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
}
Exemple #6
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);
   GRect bounds = layer_get_bounds(window_layer);

   int smallh = 21;
   int largeh = 51;
   int halfw = bounds.size.w / 2;
   int margin = 8;
   int offy = bounds.origin.y;

   // Date in upper-left
   text_date_layer = text_layer_create(
      GRect(bounds.origin.x,
            offy,
            halfw,
            smallh));
   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_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_date_layer));

   // Watch battery in upper-right
   text_watchbatt_layer = text_layer_create(
      GRect(bounds.origin.x + halfw,
            offy,
            halfw,
            smallh));
   text_layer_set_text_color(text_watchbatt_layer, GColorWhite);
   text_layer_set_background_color(text_watchbatt_layer, GColorClear);
   text_layer_set_font(text_watchbatt_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   text_layer_set_text_alignment(text_watchbatt_layer, GTextAlignmentRight);
   layer_add_child(window_layer, text_layer_get_layer(text_watchbatt_layer));

   offy = offy + smallh;

   // Time next
   text_time_layer = text_layer_create(
      GRect(bounds.origin.x + margin,
            offy,
            bounds.size.w - margin*2,
            largeh));
   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_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
   layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

   offy = offy + largeh + 2;

   // Separator
   GRect line_frame = GRect(bounds.origin.x + margin,
                            offy,
                            bounds.size.w - margin*2,
                            2);
   line_layer = layer_create(line_frame);
   layer_set_update_proc(line_layer, line_layer_update_callback);
   layer_add_child(window_layer, line_layer);

   offy = offy + 2;

   // Event in bottom half -1
   text_event_layer = text_layer_create(
      GRect(bounds.origin.x,
            offy,
            bounds.size.w,
            bounds.size.h - offy - smallh));
   text_layer_set_text_color(text_event_layer, GColorWhite);
   text_layer_set_background_color(text_event_layer, GColorClear);
   text_layer_set_overflow_mode(text_event_layer, GTextOverflowModeFill);
   text_layer_set_font(text_event_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_event_layer));


   // Location in bottom row
   text_location_layer = text_layer_create(
      GRect(bounds.origin.x,
            bounds.size.h - smallh,
            bounds.size.w,
            smallh));
   text_layer_set_text_color(text_location_layer, GColorWhite);
   text_layer_set_background_color(text_location_layer, GColorClear);
   text_layer_set_overflow_mode(text_location_layer, GTextOverflowModeFill);
   text_layer_set_font(text_location_layer,
                       fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21));
   layer_add_child(window_layer, text_layer_get_layer(text_location_layer));



   // Subscribe to date/time
   tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

   // Subscribe to watchbatt
   battery_state_service_subscribe(handle_watchbatt_change);
   handle_watchbatt_change(battery_state_service_peek());

   // Subscribe to phone data
   const int inbound_size = 256;
   const int outbound_size = 16;
   app_message_open(inbound_size, outbound_size);
   Tuplet initial_values[] = {
       TupletCString(EVENT, "No event synced"),
       //TupletCString(EVENT, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"),
       TupletCString(LOCATION, ""),
   };
   app_sync_init(&sync, sync_buffer, sizeof(sync_buffer),
                 initial_values, ARRAY_LENGTH(initial_values),
                 sync_tuple_changed_callback,
                 sync_error_callback, NULL);

   app_sync_set(&sync, initial_values, ARRAY_LENGTH(initial_values));
}
Exemple #7
0
// Program initializer
void init(void){
  // Create a window and text layer
  window = window_create();
  window_set_background_color(window, GColorBlack);
  
  // Read settings
  if (persist_exists(KEY_MILITARY_TIME)) {
    militaryTime = persist_read_bool(KEY_MILITARY_TIME);
  }
  
  if (persist_exists(KEY_TEMPC)) {
    tempC = persist_read_bool(KEY_TEMPC);
  }
  
  if (persist_exists(KEY_DATEDDMM)) {
    dateDDMM = persist_read_bool(KEY_DATEDDMM);
  }
  
  // Initialize font for time
  s_orbitron_font_36 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_LIGHT_36));
  s_orbitron_font_20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_LIGHT_20));
  s_orbitron_font_15 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_LIGHT_15));
  
  // Initialize time angles decorations
  s_time_angles_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TIME_ANGLES);
  s_seconds_arows_layer = bitmap_layer_create(GRect(0, 56, 144, 38));
  bitmap_layer_set_bitmap(s_seconds_arows_layer, s_time_angles_bmp);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_seconds_arows_layer));
  
  // Initialize secnods arows decorations
  s_time_angles_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECOND_AROWS1);
  s_time_angles_layer = bitmap_layer_create(GRect(43, 107, 55, 5));
  bitmap_layer_set_bitmap(s_time_angles_layer, s_time_angles_bmp);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_time_angles_layer));
  
  // Initialize hours layers
  init_text_layer(&hours_1st_layer, GRect(4, 54, 32, 36), s_orbitron_font_36);
  init_text_layer(&hours_2nd_layer, GRect(35, 54, 32, 36), s_orbitron_font_36);
  
  init_text_layer(&minutes_1st_layer, GRect(75, 54, 32, 36), s_orbitron_font_36);
  init_text_layer(&minutes_2nd_layer, GRect(105, 54, 32, 36), s_orbitron_font_36);
  
  init_text_layer(&seconds_1st_layer, GRect(53, 95, 18, 20), s_orbitron_font_20);
  init_text_layer(&seconds_2nd_layer, GRect(71, 95, 18, 20), s_orbitron_font_20);
  
  init_text_layer(&date_1st_layer, GRect(6, 140, 18, 20), s_orbitron_font_20);
  init_text_layer(&date_2nd_layer, GRect(19, 140, 28, 20), s_orbitron_font_20);
  
  init_text_layer(&date_delimiter_layer, GRect(35, 140, 28, 20), s_orbitron_font_20);
      
  init_text_layer(&date_3rd_layer, GRect(57, 140, 18, 20), s_orbitron_font_20);
  init_text_layer(&date_4th_layer, GRect(75, 140, 18, 20), s_orbitron_font_20);
  
  init_text_layer(&day_of_week_layer, GRect(98, 140, 40, 20), s_orbitron_font_20);

  // Initialize weather layer
  s_weather_layer = text_layer_create(GRect(0, -2, 144, 25));
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, GColorWhite);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  text_layer_set_font(s_weather_layer, s_orbitron_font_20);
  text_layer_set_text(s_weather_layer, "Loading...");
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));
   weatherCountdown = weatherCountdownInit; // Time to re-read weather values
  
  // Initialize battery lightning
  s_battery_lightning_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_LIGHTNING);
  s_battery_lightning_layer = bitmap_layer_create(GRect(40, 39, 17, 14));
  bitmap_layer_set_bitmap(s_battery_lightning_layer, s_battery_lightning_bmp);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_battery_lightning_layer));

  // Initialize battery layer
  s_battery_info_layer = text_layer_create(GRect(60, 36, 47, 25));
  text_layer_set_background_color(s_battery_info_layer, GColorClear);
  text_layer_set_text_color(s_battery_info_layer, GColorWhite);
  text_layer_set_text_alignment(s_battery_info_layer, GTextAlignmentLeft);
  text_layer_set_font(s_battery_info_layer, s_orbitron_font_15);
  text_layer_set_text(s_battery_info_layer, "--%");
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_info_layer));
  
  // To launch time changing handler
  time_t now = time(NULL);
  handle_timechanges(localtime(&now), SECOND_UNIT);
  
  // Subscribe to time changing events
  tick_timer_service_subscribe(SECOND_UNIT, handle_timechanges);
  
  // Push the window
  window_stack_push(window, true);

  // Register callbacks for messages system AppMessage
  app_message_register_inbox_received(inbox_received_callback);
  app_message_register_inbox_dropped(inbox_dropped_calback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);
  
  // Register battery state callback
  battery_state_service_subscribe(battery_callback);
  battery_callback(battery_state_service_peek()); // get initial value
  
  // Open AppMessage
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
}
Exemple #8
0
static void app_message_init(void) {
    app_message_register_outbox_failed(out_failed_handler);
    app_message_register_inbox_received(in_received_handler);
    app_message_open(app_message_inbox_size_maximum() /* size_inbound */, 2 /* size_outbound */);
}
Exemple #9
0
static void init_app_messages() {
  app_message_register_inbox_received(in_received_handler);
  app_message_open(256, 256);
}
Exemple #10
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);
		
}
Exemple #11
0
static void window_load(Window *window) {
  Layer *root_layer = window_get_root_layer(window);

  // Create the Time text_layer
  time_layer = text_layer_create(GRect(0, 0, 144, 56));
  text_layer_set_background_color(time_layer, GColorBlack);
  text_layer_set_text_color(time_layer, GColorWhite);
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  text_layer_set_font(time_layer,
                      fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
  layer_add_child(root_layer, text_layer_get_layer(time_layer));

  // Create the Wind Direction text_layer
  wind_direction_layer = text_layer_create(GRect(0, 56, 144, 28));
  text_layer_set_background_color(wind_direction_layer, GColorBlack);
  text_layer_set_text_color(wind_direction_layer, GColorWhite);
  text_layer_set_text_alignment(wind_direction_layer, GTextAlignmentCenter);
  text_layer_set_font(wind_direction_layer,
                      fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD ));
  layer_add_child(root_layer, text_layer_get_layer(wind_direction_layer));

  // Create the last_update text_layer
  last_update_layer = text_layer_create(GRect(0, 88, 144, 16));
  text_layer_set_background_color(last_update_layer, GColorBlack);
  text_layer_set_text_color(last_update_layer, GColorWhite);
  text_layer_set_text_alignment(last_update_layer, GTextAlignmentCenter);
  text_layer_set_text(last_update_layer, "_-_ -:-");
  text_layer_set_font(last_update_layer,
                      fonts_get_system_font(FONT_KEY_GOTHIC_14 ));
  layer_add_child(root_layer, text_layer_get_layer(last_update_layer));

  Layer *window_layer = root_layer;
  GRect frame = layer_get_frame(window_layer);

  rounded_layer = layer_create(frame);
  layer_set_update_proc(rounded_layer, rounded_layer_update_callback);
  layer_add_child(window_layer, rounded_layer);

  // Create the Wind text_layer
  wind_layer = text_layer_create(GRect(8, 112, 128, 24));
  text_layer_set_text_alignment(wind_layer, GTextAlignmentCenter);
  text_layer_set_font(wind_layer,
                      fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD ));
  layer_add_child(root_layer, text_layer_get_layer(wind_layer));

  // Create the temp_and_level text_layer
  temp_and_level_layer = text_layer_create(GRect(8, 136, 128, 24));
  text_layer_set_text_alignment(temp_and_level_layer, GTextAlignmentCenter);
  text_layer_set_font(temp_and_level_layer,
                      fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  layer_add_child(root_layer, text_layer_get_layer(temp_and_level_layer));

  // Subscribe to tick_timer_service
  tick_timer_service_subscribe(MINUTE_UNIT, handle_timechanges);

  // Initialize app_message
  const int inbound_size = 128;
  const int outbound_size = 128;
  app_message_open(inbound_size, outbound_size);

  Tuplet initial_values[] = {
    TupletCString(WIND_DIRECTION_KEY, "-\u00B0 ---"),
    TupletCString(WIND_SPEED_KEY, "-kt -km/h"),
    TupletCString(TEMP_AND_LEVEL_KEY, "-\u00B0C | -m"),
    TupletCString(LAST_UPDATE_KEY, "_-_ -:-")
  };

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

  send_cmd();

  window_set_background_color(window, GColorBlack);

  // Push the window
  window_stack_push(window, true);
}
void handle_init(void) {

  const int inbound_size = 64;
  const int outbound_size = 64;
  app_message_open(inbound_size, outbound_size);

  clock_window = window_create();
  window_set_fullscreen(clock_window, true);
  window_stack_push(clock_window, true /* Animated */);
  window_set_background_color(clock_window, GColorBlack);
  window_set_click_config_provider(clock_window, click_config_provider);

  Layer *window_layer = window_get_root_layer(clock_window);
  // Date: wkday. mm/dd/yy
  text_date_layer = text_layer_create(GRect(0, 92, 145, 100));
  text_layer_set_text_color(text_date_layer, GColorBlack);
  text_layer_set_background_color(text_date_layer, GColorWhite);
  text_layer_set_font(text_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DROID_SERIF_20)));
  text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(text_date_layer));

  // Time - 12hr
  text_time_layer = text_layer_create(GRect(0, 117, 145, 50));
  text_layer_set_text_color(text_time_layer, GColorBlack);
  text_layer_set_background_color(text_time_layer, GColorClear);
  text_layer_set_font(text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DROID_SERIF_42)));
  text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(text_time_layer));

  // Percent charged battery display
  battery_layer = text_layer_create(GRect(0, 0, 144-0, 168-68));
  text_layer_set_text_color(battery_layer, GColorWhite);
  text_layer_set_background_color(battery_layer, GColorClear);
  text_layer_set_font(battery_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DROID_SERIF_BOLD_15)));           //FONT_ROBOTO_CONDENSED_18)));
  text_layer_set_text_alignment(battery_layer, GTextAlignmentCenter);
  text_layer_set_text(battery_layer, "...checking...");
  layer_add_child(window_layer, text_layer_get_layer(battery_layer));

  // Bluetooth connection
  connection_layer = text_layer_create(GRect(0, 22, 145, 20));
  text_layer_set_text_color(connection_layer, GColorWhite);
  text_layer_set_background_color(connection_layer, GColorClear);
  text_layer_set_font(connection_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DROID_SERIF_BOLD_15))); //FONT_ROBOTO_CONDENSED_18)));
  text_layer_set_text_alignment(connection_layer, GTextAlignmentCenter);
  text_layer_set_text(connection_layer, "");
  layer_add_child(window_layer, text_layer_get_layer(connection_layer));

  // black seperator bar
  bar_layer = text_layer_create(GRect(0, 118, 145, 3));
  text_layer_set_background_color(bar_layer, GColorBlack);
  layer_add_child(window_layer, text_layer_get_layer(bar_layer));

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

  // If bluetooth is disconnected, it will say so even if you leave watchface
  bool connected = bluetooth_connection_service_peek();
  if (!connected)
    text_layer_set_text(connection_layer, "BT: Disconnected");
}
Exemple #13
0
void comms_init() {
  app_message_register_inbox_received(appMessageInboxReceived);
  app_message_register_inbox_dropped(appMessageInboxDropped);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
}
static void window_load(Window *window) {
   
  /*
  //Setup BT Layer
  bt_layer = text_layer_create(GRect(5, 5, 144, 30));
  text_layer_set_font(bt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  if(bluetooth_connection_service_peek() == true)
  {
    text_layer_set_text(bt_layer, "BT: CONNECTED");
  }
  else
  {
    text_layer_set_text(bt_layer, "BT: DISCONNECTED");
  }
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(bt_layer));*/

  
  
        // Although we already defined NUM_FIRST_MENU_ITEMS, you can define
        // an int as such to easily change the order of menu items later
        int num_a_items = 0;

        // This is an example of how you'd set a simple menu item
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "Chambre",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        // The menu items appear in the order saved in the menu items array
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        .title = "Cuisine",
        // You can also give menu items a subtitle
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        .title = "Bureau",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        // This is how you would give a menu item an icon
        //  .icon = menu_icon_image,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "Salle de bain",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "TV",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };

        // This initializes the second section
        second_menu_items[0] = (SimpleMenuItem){
        .title = "Retour",
        // You can use different callbacks for your menu items
        .callback = special_select_callback,
        };

        // Bind the menu items to the corresponding menu sections
        menu_sections[0] = (SimpleMenuSection){
        .title = "Sélection des pièces",
        .num_items = NUM_FIRST_MENU_ITEMS,
        .items = first_menu_items,
        };
        menu_sections[1] = (SimpleMenuSection){
        // Menu sections can also have titles as well
        .title = "Fin de la sélection",
        .num_items = NUM_SECOND_MENU_ITEMS,
        .items = second_menu_items,
        };

// INITIALISATION WINDOW, MENU LAYER,...



        // Now we prepare to initialize the simple menu layer
        // We need the bounds to specify the simple menu layer's viewport size
        // In this case, it'll be the same as the window's
        Layer *window_layer = window_get_root_layer(window);
        GRect bounds = layer_get_frame(window_layer);

        // Initialize the simple menu layer
        simple_menu_layer = simple_menu_layer_create(bounds, window, menu_sections, NUM_MENU_SECTIONS, NULL);

        // Add it to the window for display
        layer_add_child(window_layer, simple_menu_layer_get_layer(simple_menu_layer));
        }

// Deinitialize resources on window unload that were initialized on window load
        void window_unload(Window *window) {
        simple_menu_layer_destroy(simple_menu_layer);
         // text_layer_destroy(bt_layer);
        }


void init(void) {
	window = window_create();
  
  // Setup the window handlers
        window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
        });

	window_stack_push(window, true);
  

	
	// Register AppMessage handlers
	app_message_register_inbox_received(in_received_handler); 
	app_message_register_inbox_dropped(in_dropped_handler); 
	app_message_register_outbox_failed(out_failed_handler);
		
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

}

void deinit(void) {
	app_message_deregister_callbacks();
	window_destroy(window);
}

int main( void ) {
	init();
	app_event_loop();
	deinit();
}
Exemple #15
0
static void window_init(Window *window){
  bitcoin_img = gbitmap_create_with_resource(RESOURCE_ID_LG_BIT);
  dogecoin_img = gbitmap_create_with_resource(RESOURCE_ID_LG_DOGE);
  litecoin_img = gbitmap_create_with_resource(RESOURCE_ID_LG_LITE);
  
  first_it[0] = (SimpleMenuItem){
    .title = "BitCoin",
    .callback = coin_select_cb,
    .icon = bitcoin_img,
  };
  first_it[1] = (SimpleMenuItem){
    .title = "DogeCoin",
    .callback = coin_select_cb,
    .icon = dogecoin_img,
  };
  first_it[2] = (SimpleMenuItem){
    .title = "LiteCoin",
    .callback = coin_select_cb,
    .icon = litecoin_img,
  };
  menu_sec[0] = (SimpleMenuSection){
    .num_items = 3,
    .items = first_it,
  };
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);
  
  sml = simple_menu_layer_create(bounds, window, menu_sec, 2, NULL);
  
  layer_add_child(window_layer, simple_menu_layer_get_layer(sml));
  
  handle_wins_init();
  
  // Clicker
  // window_set_click_config_provider(window, click_config_provider);
}

static void window_deinit(void) {
  handle_wins_deinit();
  simple_menu_layer_destroy(sml);
}

static void handle_init(void) {
  window = window_create();
  window_init(window);
  
  //Register AppMessage events
  app_message_register_inbox_received(in_received_handler);           
  app_message_open(512, 512);    //Large input and output buffer sizes
  
  //Register to receive minutely updates
  tick_timer_service_subscribe(MINUTE_UNIT, tick_callback);
  
  window_stack_push(window, true /* Animated */);
}

static void handle_deinit(void) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Hi im handeling deinit");
  gbitmap_destroy(bitcoin_img);
  gbitmap_destroy(dogecoin_img);
  gbitmap_destroy(litecoin_img);
  
  window_deinit();
  window_destroy(window);
  
  tick_timer_service_unsubscribe();
}

int main(void) {
  handle_init();
  app_event_loop();
  handle_deinit();
}
static void init(void) {
  memset(&time_digits_layers, 0, sizeof(time_digits_layers));
  memset(&time_digits_images, 0, sizeof(time_digits_images));

  memset(&date_digits_layers, 0, sizeof(date_digits_layers));
  memset(&date_digits_images, 0, sizeof(date_digits_images));

 // Setup messaging
  const int inbound_size = 128;
  const int outbound_size = 128;
  app_message_open(inbound_size, outbound_size);	
	
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
	
  window_set_background_color(window, GColorBlack);

	
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);
	
	// resources
  custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SQUARE_26));

    img_battery_100   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_090_100);
    img_battery_90   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_090);
    img_battery_80   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_070_080);
    img_battery_70   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_060_070);
    img_battery_60   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_050_060);
    img_battery_50   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_040_050);
    img_battery_40   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_030_040);
    img_battery_30    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_020_030);
    img_battery_20    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_010_020);
    img_battery_10    = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_010);
    img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING);

    // layers
    layer_batt_img  = bitmap_layer_create(GRect(132, 5, 9, 98));
    bitmap_layer_set_bitmap(layer_batt_img, img_battery_100);
	layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img));
	
  separator_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SEPARATOR);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds = gbitmap_get_bounds(separator_image);
#else
  GRect bitmap_bounds = separator_image->bounds;
#endif	
  GRect frame = GRect(68, 81, bitmap_bounds.size.w, bitmap_bounds.size.h);
  separator_layer = bitmap_layer_create(frame);
  bitmap_layer_set_bitmap(separator_layer, separator_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(separator_layer));   

  bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds2 = gbitmap_get_bounds(bluetooth_image);
#else
  GRect bitmap_bounds2 = bluetooth_image->bounds;
#endif	
  GRect frame2 = GRect(128, 112, bitmap_bounds2.size.w, bitmap_bounds2.size.h);
  bluetooth_layer = bitmap_layer_create(frame2);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));

  Layer *weather_holder = layer_create(GRect(0, 0, 144, 168 ));
  layer_add_child(window_layer, weather_holder);

  icon_layer = bitmap_layer_create(GRect(-3, 100, 60, 75));
  layer_add_child(weather_holder, bitmap_layer_get_layer(icon_layer));
 	
  // Create time and date layers
  GRect dummy_frame = { {0, 0}, {0, 0} };	
   day_name_layer = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(day_name_layer));	
		
   month_layer = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(month_layer));	
	
    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]));
  }
	
    for (int i = 0; i < TOTAL_DATE_DIGITS; ++i) {
    date_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(date_digits_layers[i]));
  }
	
  for (int i = 0; i < TOTAL_SECONDS_DIGITS; ++i) {
    seconds_digits_layers[i] = bitmap_layer_create(dummy_frame);
    layer_add_child(window_layer, bitmap_layer_get_layer(seconds_digits_layers[i]));
  }

  temp_layer = text_layer_create(GRect(120, 135, 40, 40));
  text_layer_set_text_color(temp_layer, GColorWhite);
#ifdef PBL_COLOR	
		text_layer_set_text_color(temp_layer, GColorVividCerulean     );			
#endif
  text_layer_set_background_color(temp_layer, GColorClear);
 // text_layer_set_font(temp_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_font(temp_layer, custom_font);
  text_layer_set_text_alignment(temp_layer, GTextAlignmentLeft);
  layer_add_child(weather_holder, text_layer_get_layer(temp_layer));
	
 // creating effect layer to rotate temp
  effect_layer_2 = effect_layer_create(GRect(115,135,33,33));
  effect_layer_add_effect(effect_layer_2, effect_rotate_90_degrees, (void *)false);
  layer_add_child(window_get_root_layer(window), effect_layer_get_layer(effect_layer_2));
	
Tuplet initial_values[] = {
    TupletInteger(WEATHER_ICON_KEY, (uint8_t) 14),
    TupletInteger(INVERT_COLOR_KEY, persist_read_bool(INVERT_COLOR_KEY)),
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(STYLE_KEY, persist_read_bool(STYLE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
    TupletInteger(HIDE_BATT_KEY, persist_read_bool(HIDE_BATT_KEY)),
	TupletInteger(HIDE_DATE_KEY, persist_read_bool(HIDE_DATE_KEY)),
	TupletInteger(HIDE_WEATHER_KEY, persist_read_bool(HIDE_WEATHER_KEY)),
	TupletCString(WEATHER_TEMPERATURE_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);
  struct tm *tick_time = localtime(&now);  
  handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);

  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);	

	 // handlers
    battery_state_service_subscribe(&handle_battery);
    bluetooth_connection_service_subscribe(&handle_bluetooth);
	
	 // draw first frame
    force_update();

}
Exemple #17
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);
}
Exemple #18
0
static void window_load(Window *window) {
/*
What the output needs to look like

|route|Route name|
    ETA
    ETA
Station
Station name

*/


  Layer *window_layer = window_get_root_layer(window);

  layer_route = text_layer_create(GRect(0, 0, 40, 30));
  text_layer_set_text_color(layer_route, GColorWhite);
  text_layer_set_background_color(layer_route, GColorClear);
  text_layer_set_font(layer_route, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(layer_route, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(layer_route));

  layer_destination = text_layer_create(GRect(35, 0, 144, 30));
  text_layer_set_text_color(layer_destination, GColorBlack);
  text_layer_set_background_color(layer_destination, GColorWhite);
  text_layer_set_font(layer_destination, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(layer_destination, GTextAlignmentLeft);
  text_layer_set_overflow_mode (layer_destination, GTextOverflowModeFill);
  layer_add_child(window_layer, text_layer_get_layer(layer_destination));

  layer_eta = text_layer_create(GRect(0, 30 , 144, 68));
  text_layer_set_text_color(layer_eta, GColorWhite);
  text_layer_set_background_color(layer_eta, GColorClear);
  text_layer_set_font(layer_eta, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
  text_layer_set_text_alignment(layer_eta, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(layer_eta));

  layer_eta_mins_str  = text_layer_create(GRect(115, 80 , 144, 68));
  text_layer_set_text_color(layer_eta_mins_str, GColorWhite);
  text_layer_set_background_color(layer_eta_mins_str, GColorClear);
  text_layer_set_font(layer_eta_mins_str, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(layer_eta_mins_str, GTextAlignmentLeft);
  text_layer_set_text(layer_eta_mins_str, "mins");
  layer_add_child(window_layer, text_layer_get_layer(layer_eta_mins_str));


  layer_station = text_layer_create(GRect(0, 90, 144, 68));
  text_layer_set_text_color(layer_station, GColorWhite);
  text_layer_set_background_color(layer_station, GColorClear);
  text_layer_set_font(layer_station, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(layer_station, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(layer_station));

  layer_station_str = text_layer_create(GRect(0, 120, 144, 68));
  text_layer_set_text_color(layer_station_str, GColorBlack);
  text_layer_set_background_color(layer_station_str, GColorWhite);
  text_layer_set_font(layer_station_str, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(layer_station_str, GTextAlignmentLeft);
  layer_add_child(window_layer, text_layer_get_layer(layer_station_str));

  layer_gps_str  = text_layer_create(GRect(50, 100 , 144, 68));
  text_layer_set_text_color(layer_gps_str, GColorWhite);
  text_layer_set_background_color(layer_gps_str, GColorClear);
  text_layer_set_font(layer_gps_str, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(layer_gps_str, GTextAlignmentLeft);
  text_layer_set_text(layer_gps_str, "GPS tracking");
  layer_add_child(window_layer, text_layer_get_layer(layer_gps_str));

  Tuplet bus_values[] = {
    TupletInteger(KEY_ROUTE, -1),
    TupletInteger(KEY_STOP_NUM, -1),
    TupletInteger(KEY_ETA, -1),
    TupletCString(KEY_DST, "  bootup              "),
    TupletCString(KEY_STATION_STR, " none            "),
    TupletInteger(KEY_DIRECTION, 0),
    TupletInteger(KEY_GPS, 0),
  };

    int inbound_size = app_message_inbox_size_maximum();
    int outbound_size = app_message_outbox_size_maximum();
    app_message_open(inbound_size, outbound_size);
    app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), bus_values, ARRAY_LENGTH(bus_values),
    sync_tuple_changed_callback, sync_error_callback, NULL);

    app_timer_register(TIMER, decrement_eta_handler, NULL);

  //send_cmd();
}
Exemple #19
0
static void inbox_received_handler(DictionaryIterator *iterator, void *context) {
  Tuple *t = dict_read_first(iterator);

  while (t) {
//    if (t->type == TUPLE_CSTRING) {
//      APP_LOG(APP_LOG_LEVEL_INFO, "RxTuple %d:%s", (int)t->key, t->value->cstring);
//    } else {
//      APP_LOG(APP_LOG_LEVEL_INFO, "RxTuple (unknown type)");
//    }

    switch(t->key) {
      case ConfShowTime:
        switch (atoi(t->value->cstring)) {
          default:
          case 0: // Hide
            conf.showTime = false;
            conf.showTimeOnTap = false;
          break;
          case 1: // Show
            conf.showTime = true;
            conf.showTimeOnTap = false;
          break;
          case 2: // Show on tap
            conf.showTime = false;
            conf.showTimeOnTap = true;
          break;
        }
        persist_write_bool(t->key, conf.showTime);
        persist_write_bool(ConfShowTimeOnTap, conf.showTimeOnTap);
        layer_set_hidden(text_layer_get_layer(s_time_layer), !conf.showTime);
        if (conf.showTimeOnTap) {
          accel_tap_service_subscribe(tap_handler);
//          APP_LOG(APP_LOG_LEVEL_INFO, "Subscribe tap");
        } else {
          accel_tap_service_unsubscribe();
//          APP_LOG(APP_LOG_LEVEL_INFO, "Unsubscribe tap");
        }
        break;
      case ConfShowDate:
        conf.showDate = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showDate);
        layer_set_hidden(text_layer_get_layer(s_date_layer), !(conf.showDate || conf.showMonth));
        break;
      case ConfShowMonth:
        conf.showMonth = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showMonth);
        layer_set_hidden(text_layer_get_layer(s_date_layer), !(conf.showDate || conf.showMonth));
        break;
      case ConfShowWeekNum:
        conf.showWeekNum = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showWeekNum);
        layer_set_hidden(text_layer_get_layer(s_week_layer), !conf.showWeekNum);
        break;
      case ConfShowCharge:
        conf.showCharge = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showCharge);
        layer_set_hidden(s_charge_layer, !conf.showCharge);
        break;
      case ConfShowBluetooth:
        conf.showBluetooth = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showBluetooth);
        layer_set_hidden(s_bluetooth_layer, !conf.showBluetooth);
        break;
      case ConfVibeBluetooth:
        conf.vibeBluetooth = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.vibeBluetooth);
        break;
      case ConfShowSpiral:
        conf.showSpiral = atoi(t->value->cstring);
        persist_write_bool(t->key, conf.showSpiral);
        layer_set_hidden(s_arc1x1L_layer, !conf.showSpiral);
        layer_set_hidden(s_arc1x1R_layer, !conf.showSpiral);
        layer_set_hidden(s_arc2x2_layer, !conf.showSpiral);
        layer_set_hidden(s_arc3x3_layer, !conf.showSpiral);
        layer_set_hidden(s_arc5x5_layer, !conf.showSpiral);
        break;
      case ConfHourColor:
        conf.hourColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.hourColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfMinuteColor:
        conf.minuteColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.minuteColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfHourMinuteColor:
        conf.hourMinuteColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.hourMinuteColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfNoneColor:
        conf.noneColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.noneColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfSpiralColor:
        conf.spiralColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.spiralColor.argb);
        layer_mark_dirty(s_arc1x1L_layer);
        layer_mark_dirty(s_arc1x1R_layer);
        layer_mark_dirty(s_arc2x2_layer);
        layer_mark_dirty(s_arc3x3_layer);
        layer_mark_dirty(s_arc5x5_layer);
        break;
      case ConfBackgroundColor: {
        conf.backgroundColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.backgroundColor.argb);
        window_set_background_color(s_window, conf.backgroundColor);
      }  break;
      case ConfGridColor:
        conf.gridColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.gridColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfDotColor:
        conf.dotColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.dotColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfTimeColor: {
        int value = atoi(t->value->cstring);
        conf.legibleText = (value == 256);
        conf.timeColor = (GColor){.argb = (uint8_t)(value & 0xFF)};
        persist_write_int(t->key, value);
        tick_handler(NULL, (TimeUnits)0);
      } break;
      case ConfOutlineColor:
        conf.outlineColor = (GColor){.argb = atoi(t->value->cstring)};
        persist_write_int(t->key, conf.outlineColor.argb);
        layer_mark_dirty(s_fibo_layer);
        break;
      case ConfFiboDisplay:
        conf.fiboDisplay = atoi(t->value->cstring);
        persist_write_int(t->key, conf.fiboDisplay);
        layer_mark_dirty(s_fibo_layer);
        layer_set_frame(s_arc1x1L_layer, fibo[conf.fiboDisplay].s_1x1L_square);
        layer_set_frame(s_arc1x1R_layer, fibo[conf.fiboDisplay].s_1x1R_square);
        layer_set_frame(s_arc2x2_layer,  fibo[conf.fiboDisplay].s_2x2_square);
        layer_set_frame(s_arc3x3_layer,  fibo[conf.fiboDisplay].s_3x3_square);
        layer_set_frame(s_arc5x5_layer,  fibo[conf.fiboDisplay].s_5x5_square);
        layer_set_frame(text_layer_get_layer(s_time_layer), fibo[conf.fiboDisplay].s_time);
        layer_set_frame(text_layer_get_layer(s_date_layer), fibo[conf.fiboDisplay].s_date);
        layer_set_frame(text_layer_get_layer(s_week_layer), fibo[conf.fiboDisplay].s_week);
        break;
    }
    t = dict_read_next(iterator);
  }
}

void show_main(void) {
  initialise_ui();
  window_set_window_handlers(s_window, (WindowHandlers) {
    .unload = handle_window_unload,
  });
  window_stack_push(s_window, true);

  // Set up layer callbacks
  layer_set_update_proc(s_fibo_layer, fibo_layer_update_callback);
  layer_set_update_proc(s_charge_layer, charge_layer_update_callback);
  layer_set_update_proc(s_arc3x3_layer, arc3x3_layer_update_callback);
  layer_set_update_proc(s_arc2x2_layer, arc2x2_layer_update_callback);
  layer_set_update_proc(s_arc1x1L_layer, arc1x1L_layer_update_callback);
  layer_set_update_proc(s_arc1x1R_layer, arc1x1R_layer_update_callback);
  layer_set_update_proc(s_arc5x5_layer, arc5x5_layer_update_callback);
  layer_set_update_proc(s_bluetooth_layer, bluetooth_layer_update_callback);

  // Create bitmaps
  s_charging_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CHARGING);
  s_plugged_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLUGGED);
  s_bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH);
  s_cross_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CROSS);

  // Register with TickTimerService
#if ACTIVATE_COLOR_LOOP
  tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
#else
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
#endif
  
  // Register with BatteryStateService
  battery_state_service_subscribe(battery_charge_handler);

  // Register with BluetoothConnectionService
  bluetooth_connection_service_subscribe(bluetooth_handler);

  app_message_register_inbox_received((AppMessageInboxReceived) inbox_received_handler);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  load_config();

  layer_set_hidden(text_layer_get_layer(s_time_layer), !conf.showTime);
  layer_set_hidden(text_layer_get_layer(s_date_layer), !(conf.showDate || conf.showMonth));
  layer_set_hidden(text_layer_get_layer(s_week_layer), !conf.showWeekNum);

  // Create used path
  s_bat_frame_path_ptr = gpath_create(&BAT_FRAME_PATH_INFO);
  
  // Make sure that the currnet time is displayed from the start
  time_t temp = time(NULL);
  struct tm *tick_time = localtime(&temp);
  tick_handler(tick_time, YEAR_UNIT | MONTH_UNIT | DAY_UNIT | HOUR_UNIT | MINUTE_UNIT | SECOND_UNIT);
}

void hide_main(void) {
  window_stack_remove(s_window, true);

  gbitmap_destroy(s_battery_image);
  gbitmap_destroy(s_charging_image);
  gbitmap_destroy(s_plugged_image);
  gbitmap_destroy(s_bluetooth_image);
  gbitmap_destroy(s_cross_image);

  tick_timer_service_unsubscribe();
  battery_state_service_unsubscribe();
  bluetooth_connection_service_unsubscribe();
}

int main(void) {
  show_main();
  app_event_loop();
  hide_main();
}