/* workqueue function */
static int cable_type_detect(void)
{
	struct i2c_client *client = charger->client;
	u8 retval;
	int  success = 0;
	int gpio = TEGRA_GPIO_PV1;

	if(grouper_query_pcba_revision() <= 0x02)
		return 0;

	mutex_lock(&charger->cable_lock);

	if (gpio_get_value(gpio)) {
			printk("INOK=H\n");
			success = battery_callback(non_cable);
	} else {
			printk("INOK=L\n");

			/* cable type dection */
			retval = smb347_read(client, smb347_STS_REG_E);
			SMB_NOTICE("Reg3F : 0x%02x\n", retval);
			if(retval & USBIN) {	//USBIN
					retval = smb347_read(client, smb347_STS_REG_D);
					SMB_NOTICE("Reg3E : 0x%02x\n", retval);
				if(retval & APSD_OK) {	//APSD completed
						retval &= APSD_RESULT;
					if(retval == APSD_CDP) {	//APSD resulted
							printk("Cable: CDP\n");
							success = battery_callback(ac_cable);
					} else if(retval == APSD_DCP) {
							printk("Cable: DCP\n");
							success = battery_callback(ac_cable);
					} else if(retval == APSD_OTHER) {
							printk("Cable: OTHER\n");
					} else if(retval == APSD_SDP) {
							printk("Cable: SDP\n");
							success = battery_callback(usb_cable);
					} else
							printk("Unkown Plug In Cable type !\n");
				}else
					printk("APSD not completed\n");
			}
			else
			{
					printk("USBIN=0\n");
			}
	}

	mutex_unlock(&charger->cable_lock);

	return success;
}
Beispiel #2
0
void battery_load(Layer *root_layer) {
  GRect layer_bounds = layer_get_bounds(root_layer);

  battery_layer = layer_create(GRect( 0, layer_bounds.size.h - 4, layer_bounds.size.w, BATTERY_METER_THICKNESS));
  layer_set_update_proc(battery_layer, update_battery);
  layer_add_child(root_layer, battery_layer);
  
  // Ensure battery level is displayed from the start
  battery_callback(battery_state_service_peek());
}
Beispiel #3
0
static void init() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "start of init");
  autoconfig_init(512, 512);
  app_message_register_inbox_received(in_received_handler);
  main_window_set_config(getMinutes_color(), getMinutes_no_bt_color(), getHours_color(), getHours_no_bt_color(), getText_color(), getText_low_battery_color(), getBg_color(), getBar_radius(), getBar_offset(), getRing_markings(), getLow_bat_threshold());
  BT_VIBE = getBt_vibe();
  main_window_init();
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  battery_state_service_subscribe(battery_callback);
  battery_callback(battery_state_service_peek());
  bluetooth_connection_service_subscribe(bluetooth_callback);
  bluetooth_callback(bluetooth_connection_service_peek());
  APP_LOG(APP_LOG_LEVEL_DEBUG, "end of init");
}
Beispiel #4
0
void handle_init(void) {
  my_window = window_create();
  Layer *window_layer = window_get_root_layer(my_window);
  GRect bounds = layer_get_bounds(window_layer);
  static GFont s_time_font, s_date_font;
  srand(time(NULL));    
  
  text_layer = text_layer_create(GRect(0, 48, bounds.size.w, 55));
  text_layer_set_background_color(text_layer, GColorRed);
  text_layer_set_text_color(text_layer, GColorWhite);
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
    
  text_layer2 = text_layer_create(GRect(0, 0, bounds.size.w, 168));
  text_layer_set_background_color(text_layer2, GColorBlack);
  text_layer_set_text_color(text_layer2, GColorWhite);
  text_layer_set_font(text_layer2, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(text_layer2, GTextAlignmentCenter);
    
  layer_add_child(window_layer, text_layer_get_layer(text_layer2));
  layer_add_child(window_layer, text_layer_get_layer(text_layer));
    
  s_date_layer = text_layer_create(GRect(0, 103, 144, 37));
  text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_background_color(s_date_layer, GColorGreen);
  text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
    
  s_batt_layer = text_layer_create(GRect(0, 143, 144, 25)); 
  text_layer_set_text_color(s_batt_layer, GColorBlack);
  text_layer_set_background_color(s_batt_layer, GColorWhite);
  text_layer_set_font(s_batt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_batt_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_batt_layer));
    
  window_stack_push(my_window, true);
  update_time();

  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  battery_callback(battery_state_service_peek());
  battery_state_service_subscribe(battery_callback);
  accel_tap_service_subscribe(tap_handler); 
}
Beispiel #5
0
/* workqueue function */
static int cable_type_detect(void)
{
	struct i2c_client *client = charger->client;
	u8 retval;
	int  success = 0;
	int ac_ok = GPIO_AC_OK;
	int dock_in = gpio_dock_in;

	/*
	printk("cable_type_detect %d %lu %d %x jiffies=%lu %lu+\n",
	charger->old_cable_type,
	charger->time_of_1800mA_limit,
	gpio_get_value(gpio),
	time_after(charger->time_of_1800mA_limit+(4*HZ), jiffies ),
	jiffies,
	charger->time_of_1800mA_limit+(ADAPTER_PROTECT_DELAY*HZ));
	*/

	if((pcba_ver <= GROUPER_PCBA_ER2) && (project_id == GROUPER_PROJECT_NAKASI))
		return 0;

	mutex_lock(&charger->cable_lock);

	if ((charger->old_cable_type == ac_cable) &&
	charger->time_of_1800mA_limit && gpio_get_value(ac_ok) &&
	time_after(charger->time_of_1800mA_limit+
					ADAPTER_PROTECT_DELAY, jiffies)) {
		smb347_set_InputCurrentlimit(client, 900);
		charger->test_1800mA_fail = 1;
		queue_delayed_work(smb347_wq,
				&charger->test_fail_clear_work, 1*HZ);
	}

	if (gpio_get_value(ac_ok)) {
		printk(KERN_INFO "INOK=H\n");
		charger->cur_cable_type = non_cable;
		smb347_set_InputCurrentlimit(client, 900);
		success = battery_callback(non_cable);
#ifdef TOUCH_CALLBACK_ENABLED
               touch_callback(non_cable);
#endif
		wake_unlock(&charger_wakelock);
	} else {
		printk(KERN_INFO "INOK=L\n");
		retval = smb347_read(client, smb347_INTR_STS_E);
		SMB_NOTICE("Reg39 : 0x%02x\n", retval);
		if (!(retval & DCIN_OV_UV_STS) && !gpio_get_value(dock_in)) {
			SMB_NOTICE("DC_IN\n");
			success = battery_callback(ac_cable);
		} else {

			/* cable type dection */
			retval = smb347_read(client, smb347_STS_REG_E);
			SMB_NOTICE("Reg3F : 0x%02x\n", retval);
			if (retval & USBIN) {
				SMB_NOTICE("USB_IN\n");
				retval = smb347_read(client, smb347_STS_REG_D);
				SMB_NOTICE("Reg3E : 0x%02x\n", retval);
				if (retval & APSD_OK) {
						retval &= APSD_RESULT;
					if (retval == APSD_CDP) {
						printk(KERN_INFO "Cable: CDP\n");
						charger->cur_cable_type = ac_cable;
						success = battery_callback(ac_cable);
#ifdef TOUCH_CALLBACK_ENABLED
	                                    touch_callback(ac_cable);
#endif
					} else if (retval == APSD_DCP) {
						printk(KERN_INFO "Cable: DCP\n");
						charger->cur_cable_type = ac_cable;
						success = battery_callback(ac_cable);
#ifdef TOUCH_CALLBACK_ENABLED
	                                    touch_callback(ac_cable);
#endif
					} else if (retval == APSD_OTHER) {
						charger->cur_cable_type = ac_cable;
						success = battery_callback(ac_cable);
#ifdef TOUCH_CALLBACK_ENABLED
	                                   touch_callback(ac_cable);
#endif
						printk(KERN_INFO "Cable: OTHER\n");
					} else if (retval == APSD_SDP) {
						printk(KERN_INFO "Cable: SDP\n");
						charger->cur_cable_type = usb_cable;
						success = battery_callback(usb_cable);
#ifdef TOUCH_CALLBACK_ENABLED
	                                    touch_callback(usb_cable);
#endif
					} else {
						charger->cur_cable_type = unknow_cable;
						printk(KERN_INFO "Unkown Plug In Cable type !\n");

						if(usb_det_cable_type) {
							printk(KERN_INFO "Use usb det %s cable to report\n",
								(usb_det_cable_type == ac_cable) ? "ac" : "usb");
							charger->cur_cable_type = usb_det_cable_type;
							success = battery_callback(usb_det_cable_type);
						}
					}
				} else {
					charger->cur_cable_type = unknow_cable;
					printk(KERN_INFO "APSD not completed\n");
				}
			} else {
				charger->cur_cable_type = unknow_cable;
				printk(KERN_INFO "USBIN=0\n");
			}
		}
	}

	if (charger->cur_cable_type == ac_cable &&
		charger->old_cable_type != ac_cable &&
		charger->test_1800mA_fail == 0) {
		wake_lock(&charger_wakelock);
		queue_delayed_work(smb347_wq, &charger->curr_limit_work,
					DELAY_FOR_CURR_LIMIT_RECONF*HZ);
	}
	charger->old_cable_type = charger->cur_cable_type;

	mutex_unlock(&charger->cable_lock);
	return success;
}
Beispiel #6
0
static void main_window_load(Window *window) {
  // background
  //s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  //s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));  // startx, starty, widthx, widthy
  //bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  //layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));

  // Create GFont
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_NINE_42));
  s_ampm_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_NINE_14));

  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 54, 144, 60));
  text_layer_set_background_color(s_time_layer, GColorBlack);
  text_layer_set_text_color(s_time_layer, GColorBlack);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft);
  text_layer_set_font(s_time_layer, s_time_font);
  
    // Create ampm TextLayer
  s_ampm_layer = text_layer_create(GRect(0,77,144,50));
  text_layer_set_background_color(s_ampm_layer, GColorClear);
  text_layer_set_text_color(s_ampm_layer, GColorBlack);
  text_layer_set_text_alignment(s_ampm_layer, GTextAlignmentRight);
  text_layer_set_font(s_ampm_layer, s_ampm_font);
  
  
  // create date textlayer
  s_date_layer = text_layer_create(GRect(0,130,144,40));
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  text_layer_set_font(s_date_layer, s_ampm_font);
  
   // Create DOW TextLayer
  s_dow_layer = text_layer_create(GRect(0, 0, 144, 45));
  text_layer_set_background_color(s_dow_layer, GColorClear);
  text_layer_set_text_color(s_dow_layer, GColorDukeBlue);
  text_layer_set_text_alignment(s_dow_layer, GTextAlignmentCenter);
  text_layer_set_font(s_dow_layer, s_time_font);

  // Add layers to the window
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_ampm_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_dow_layer));
  
  // Create battery meter Layer
s_battery_layer = layer_create(GRect(0, 150, 144, 50));
layer_set_update_proc(s_battery_layer, battery_update_proc);

// Add to Window
layer_add_child(window_get_root_layer(window), s_battery_layer);
// Update meter
layer_mark_dirty(s_battery_layer);

  // Ensure battery level is displayed from the start
battery_callback(battery_state_service_peek());

  
  update_time();
}
Beispiel #7
0
//////////////////////////////////////////////////// Main Visuals /////////////////////////////
static void main_window_load(Window *window) {
  
  window = window_create();
  window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
  time_color = GColorFromRGB(0, 170, 255);
  
	Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  
  // position battery and bluetooth icons depending on screen
  #ifdef PBL_ROUND
    int topright = bounds.size.w / 2;
  #else
    int topright = bounds.size.w - (bounds.size.w / 4);  
  #endif
    
  // Create GFonts
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_Prototype_42));
  s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_Prototype_20));
   
    
 // Create TIME TextLayer and set colour
  s_time_layer = text_layer_create(GRect(0, 40, bounds.size.w, bounds.size.h));
  text_layer_set_background_color(s_time_layer, GColorClear);
  // Read saved config
  #if defined(PBL_BW)
    text_layer_set_text_color(s_time_layer, GColorWhite);
  #elif defined(PBL_COLOR)
    // Use background color setting
    red = persist_read_int(KEY_COLOR_RED);
    green = persist_read_int(KEY_COLOR_GREEN);
    blue = persist_read_int(KEY_COLOR_BLUE);
    time_color = GColorFromRGB(red, green, blue);    
    text_layer_set_text_color(s_time_layer, time_color);
  #endif
  text_layer_set_text(s_time_layer, "00:00");
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
  
  
  // Create DATE TextLayer
  s_date_layer = text_layer_create(GRect(0, 115, bounds.size.w, bounds.size.h));
  text_layer_set_text_color(s_date_layer, GColorFromHEX(0xFFFFFF));
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  text_layer_set_text(s_date_layer, "Sept 23");
  text_layer_set_font(s_date_layer, s_date_font);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

  // Create Divider
  GRect line_frame = GRect(20, 104, bounds.size.w -40, 2);
  line_layer = layer_create(line_frame);
  layer_set_update_proc(line_layer, draw_line);
	layer_add_child(window_layer, line_layer);
  
  
  // Create the BitmapLayer to display the Bluetooth icon
  s_bt_icon_layer = bitmap_layer_create(GRect(topright - 12, bounds.origin.x + 10, 11, 10));
  bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer));
 
  
   // Create the BitmapLayer to display the Battery
  s_batt_icon_layer = bitmap_layer_create(GRect(topright + 5, bounds.origin.x + 10, 16, 10));
  bitmap_layer_set_bitmap(s_batt_icon_layer, s_batt_icon_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_batt_icon_layer));
  
  // Initialize the display
  update_time();
  
  battery_callback(battery_state_service_peek());

  bluetooth_callback(connection_service_peek_pebble_app_connection());
}
Beispiel #8
0
static void window_load()
{
    // Create window
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    // Background layer
    s_bg_layer = layer_create(bounds);
    layer_set_update_proc(s_bg_layer, bg_update_proc);
    layer_add_child(window_layer, s_bg_layer);

    // Time layer
    s_time_layer = layer_create(bounds);
    layer_set_update_proc(s_time_layer, time_update_proc);
    layer_add_child(window_layer, s_time_layer);

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

    // Battery layer
    s_battery_bitmap[0] = gbitmap_create_with_resource(RESOURCE_ID_BATTERY);
    s_battery_bitmap[1] = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING);
    s_battery_layer = layer_create(bounds);
    layer_set_update_proc(s_battery_layer, battery_update_proc);
    layer_add_child(window_layer, s_battery_layer);

    // Bluetooth layer
    s_bt_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BLUETOOTH);
    s_bt_layer = layer_create(bounds);
    layer_set_update_proc(s_bt_layer, bt_update_proc);
    layer_add_child(window_layer, s_bt_layer);

    // Weather layer
    s_weather_bitmap[0] = gbitmap_create_with_resource(RESOURCE_ID_W01D);
    s_weather_bitmap[1] = gbitmap_create_with_resource(RESOURCE_ID_W01N);
    s_weather_bitmap[2] = gbitmap_create_with_resource(RESOURCE_ID_W02D);
    s_weather_bitmap[3] = gbitmap_create_with_resource(RESOURCE_ID_W02N);
    s_weather_bitmap[4] = gbitmap_create_with_resource(RESOURCE_ID_W03);
    s_weather_bitmap[5] = gbitmap_create_with_resource(RESOURCE_ID_W04);
    s_weather_bitmap[6] = gbitmap_create_with_resource(RESOURCE_ID_W09);
    s_weather_bitmap[7] = gbitmap_create_with_resource(RESOURCE_ID_W10D);
    s_weather_bitmap[8] = gbitmap_create_with_resource(RESOURCE_ID_W10N);
    s_weather_bitmap[9] = gbitmap_create_with_resource(RESOURCE_ID_W11);
    s_weather_bitmap[10] = gbitmap_create_with_resource(RESOURCE_ID_W13);
    s_weather_bitmap[11] = gbitmap_create_with_resource(RESOURCE_ID_W50);
    s_weather_layer = layer_create(bounds);
    layer_set_update_proc(s_weather_layer, weather_update_proc);
    layer_add_child(window_layer, s_weather_layer);

    // Foreground layer
    s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_FRAME);
    s_fg_layer = layer_create(bounds);
    layer_set_update_proc(s_fg_layer, fg_update_proc);
    layer_add_child(window_layer, s_fg_layer);

    // Time Zone layer
    s_window_bitmap = gbitmap_create_with_resource(RESOURCE_ID_WINDOW);
    s_tz_layer = layer_create(bounds);
    layer_set_update_proc(s_tz_layer, tz_update_proc);
    layer_add_child(window_layer, s_tz_layer);

    // Init callback
    bluetooth_callback(bluetooth_connection_service_peek());
    battery_callback(battery_state_service_peek());

    // Init
    s_weather_temp = persist_exists(KEY_TEMPERATURE) ? persist_read_int(KEY_TEMPERATURE) : -100;
    s_weather_icon = persist_exists(KEY_ICON) ? persist_read_int(KEY_ICON) : -1;
    s_last_update_time = persist_exists(KEY_LAST_WEATHER_UPDATE_TIME) ? persist_read_int(KEY_LAST_WEATHER_UPDATE_TIME) : -1;
    s_ad_time_zone = persist_exists(KEY_ADTZ) ? persist_read_int(KEY_ADTZ) : 0;
    s_vibe_bt = persist_exists(KEY_BLUETOOTH_VIBE) ? persist_read_int(KEY_BLUETOOTH_VIBE) : 0;
    s_vibe_hourly = persist_exists(KEY_HOURLY_VIBE) ? persist_read_int(KEY_HOURLY_VIBE) : 0;
    s_hour_r = persist_exists(KEY_HOUR_RED) ? persist_read_int(KEY_HOUR_RED) : 0;
    s_hour_g = persist_exists(KEY_HOUR_GREEN) ? persist_read_int(KEY_HOUR_GREEN) : 170;
    s_hour_b = persist_exists(KEY_HOUR_BLUE) ? persist_read_int(KEY_HOUR_BLUE) : 255;
    s_minute_r = persist_exists(KEY_MINUTE_RED) ? persist_read_int(KEY_MINUTE_RED) : 255;
    s_minute_g = persist_exists(KEY_MINUTE_GREEN) ? persist_read_int(KEY_MINUTE_GREEN) : 0;
    s_minute_b = persist_exists(KEY_MINUTE_BLUE) ? persist_read_int(KEY_MINUTE_BLUE) : 0;
    s_second_r = persist_exists(KEY_SECOND_RED) ? persist_read_int(KEY_SECOND_RED) : 0;
    s_second_g = persist_exists(KEY_SECOND_GREEN) ? persist_read_int(KEY_SECOND_GREEN) : 255;
    s_second_b = persist_exists(KEY_SECOND_BLUE) ? persist_read_int(KEY_SECOND_BLUE) : 0;
    s_ps_start_time = persist_exists(KEY_POWER_SAVING_START) ? persist_read_int(KEY_POWER_SAVING_START) : 0;
    s_ps_end_time = persist_exists(KEY_POWER_SAVING_END) ? persist_read_int(KEY_POWER_SAVING_END) : 0;
    s_second_bar = persist_exists(KEY_SECOND_BAR) ? persist_read_int(KEY_SECOND_BAR) : 0;
    s_second_bar_r = persist_exists(KEY_SECOND_BAR_RED) ? persist_read_int(KEY_SECOND_BAR_RED) : 0;
    s_second_bar_g = persist_exists(KEY_SECOND_BAR_GREEN) ? persist_read_int(KEY_SECOND_BAR_GREEN) : 255;
    s_second_bar_b = persist_exists(KEY_SECOND_BAR_BLUE) ? persist_read_int(KEY_SECOND_BAR_BLUE) : 0;
    s_second_rate = persist_exists(KEY_SECOND_REFRESH_RATE) ? persist_read_int(KEY_SECOND_REFRESH_RATE) : 0;
    s_12hour = persist_exists(KEY_12HOUR) ? persist_read_bool(KEY_12HOUR) : false;

    if (s_second_rate < 2)
    {
        app_timer_register(1000, animation_timer_callback, NULL);
    }
    else if (s_second_rate == 2)
    {
        app_timer_register(500, animation_timer_callback, NULL);
    }
    else if (s_second_rate == 3)
    {
        app_timer_register(250, animation_timer_callback, NULL);
    }
    else if (s_second_rate == 4)
    {
        app_timer_register(100, animation_timer_callback, NULL);
    }
    else if (s_second_rate == 5)
    {
        app_timer_register(66, animation_timer_callback, NULL);
    }
    s_last_second = -1;
    s_msecond = 0;

}
Beispiel #9
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());
}