Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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);


}
Ejemplo n.º 3
0
static void window_load(Window *window) {
  
  // Load the bitmap asset
  // resource_init_current_app must be called before all asset loading.
  menu_icons[0] = gbitmap_create_with_resource(RESOURCE_ID_HAPPY);
  menu_icons[1] = gbitmap_create_with_resource(RESOURCE_ID_SAD);
  menu_icons[2] = gbitmap_create_with_resource(RESOURCE_ID_STRESSED);
  menu_icons[3] = gbitmap_create_with_resource(RESOURCE_ID_CALM);
  
  // ******** Menu Items ********
  // First menu item.
  first_menu_items[0] = (SimpleMenuItem) {
    .icon = menu_icons[0],
    .title = "Happy",
    .subtitle = "Sweet!",
    .callback = menu_select_callback,
  };
  
  // Second menu item.
  first_menu_items[1] = (SimpleMenuItem) {
    .icon = menu_icons[1],
    .title = "Sad",
    .subtitle = "Cheer Up!",
    .callback = menu_select_callback,
  };
  
  // Third menu item.
  first_menu_items[2] = (SimpleMenuItem) {
    .icon = menu_icons[2],
    .title = "Stressed",
    .subtitle = "Take a chill pill!",
    .callback = menu_select_callback,
  };

  // Fourth menu item.
  first_menu_items[3] = (SimpleMenuItem){
    .icon = menu_icons[3],
    .title = "Calm",
    .subtitle = "Like a felon!",
    .callback = menu_select_callback,
  };
  
  // ******** SECTIONS ********
  menu_sections[0] = (SimpleMenuSection) {
    .num_items = NUM_FIRST_MENU_ITEM,
    .items = first_menu_items,
  };
  
  // Required: gets the root layer. ( base layer )
  Layer *window_layer = window_get_root_layer(window);
  
  // Required: Gets the dimensions of the whole pebble screen.
  GRect bounds = layer_get_bounds(window_layer);

  // initialize the menu.
  simple_menu_layer = simple_menu_layer_create(bounds, window, menu_sections, NUM_MENU_SECTIONS, NULL);
  
  // Required: add the window for display
  layer_add_child(window_layer, simple_menu_layer_get_layer(simple_menu_layer));
}

/************************************************************/
/* window_unload                                            */
/*                                                          */
/* Handles all the clean up before destroying the window.   */
/************************************************************/
static void window_unload(Window *window) {
  simple_menu_layer_destroy(simple_menu_layer);
  
  // Destroy the images
  for(int i = 0; i < NUM_MENU_ICONS; i++){
    gbitmap_destroy(menu_icons[i]);
  }
}

/************************************************************/
/* init                                                     */
/*                                                          */
/* Creates the window, sets the click_config_provider, sets */
/* the window handlers, and pushes the window onto the  top */
/* of the stack so it is visible.                           */
/************************************************************/
static void init(void) {
  
  // Required: Creates the window. Needed to display everything.
  window = window_create();
  
  // Required. Sets the hanldlers for the window. window_load for when the user enters the watchapp and
  // window_unload, for when the user leave the watch app.
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
  
  // Setup the messaging handlers.
  app_message_register_outbox_sent(out_sent_handler);
  app_message_register_outbox_failed(out_failed_handler);
  const uint32_t inbound_size = 10;
  const uint32_t outbound_size = 64;
  app_message_open(inbound_size, outbound_size);
  
  
  // Vibrate to let the user know.
  vibes_short_pulse();
  
  // Required: Will push the window to the top of the stack and therefore making it visible.
  const bool animated = true;
  window_stack_push(window, animated);
}

/************************************************************/
/* deinit                                                   */
/*                                                          */
/* Destroys the window and performs all of the necessary    */
/* clean up.                                                */
/************************************************************/
static void deinit(void) {
  window_destroy(window);
}
Ejemplo n.º 4
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 */);
}
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();
}
Ejemplo n.º 6
0
static void registerCallbacks(void) {
  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);
}
Ejemplo n.º 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());
}
Ejemplo n.º 8
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());
}