static void handle_battery(BatteryChargeState charge_state) { static char battery_text[] = "100%"; if (charge_state.is_charging && charge_state.charge_percent != 100) { snprintf(battery_text, sizeof(battery_text), "charging"); } else if (charge_state.is_plugged){ snprintf(battery_text, sizeof(battery_text), "full"); } else { snprintf(battery_text, sizeof(battery_text), "%d%%", charge_state.charge_percent); } text_layer_set_text(battery_layer, battery_text); if(charge_state.charge_percent <= 10){ deadBattery = true; gbitmap_destroy(background_bitmap); background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_DEAD_BATTERY); bitmap_layer_set_bitmap(background_layer, background_bitmap); }else if(deadBattery){ deadBattery = false; if(triedToUpdateWeather){ update_weather(); } } }
static void update_all(void) { update_minute(); update_daily(); update_weather(FORCE_WEATHER_UPDATE); battery_handler(battery_state_service_peek()); // force refresh bluetooth_handler(bluetooth_connection_service_peek()); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); // Get weather update every 30 minutes if(tick_time->tm_min % 30 == 0 && !deadBattery) { APP_LOG(APP_LOG_LEVEL_INFO, "Time TO update weather."); update_weather(); } }
static void time_handler(struct tm *tick_time, TimeUnits units_changed) { static int current_day = -1; update_minute(); update_weather(tick_time->tm_min); // saves computation of day, month, year, from being calculated every minute if(current_day != tick_time->tm_yday) { current_day = tick_time->tm_yday; update_daily(); } }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { if (units_changed & MINUTE_UNIT) { update(1); } if (units_changed & DAY_UNIT) { update(2); } if(tick_time->tm_min % 30 == 0) { #ifdef PBL_COLOR update_weather(); #endif } }
/** * Window load handler function */ static void mainWindowLoad(Window *w) { init_hardware_icons(); // Get information about the root window Layer *windowLayer = window_get_root_layer(w); GRect bounds = layer_get_bounds(windowLayer); // Set sleepy time flag time_t temp_time = time(NULL); struct tm *cur_time = localtime(&temp_time); s_is_sleepy_time = (cur_time->tm_hour <= SLEEPY_TIME_END_HOUR && cur_time->tm_hour >= SLEEPY_TIME_START_HOUR); ////////////////////////////////////////// // Battery GRect bat_icon_bounds = get_battery_icon_bounds(); // Create BitmapLayer to display the GBitmap s_powerIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + 2), 0, bat_icon_bounds.size.w, bat_icon_bounds.size.h)); // set background colout and compositing mode bitmap_layer_set_background_color(s_powerIconLayer, POWER_ICON_BACK_COLOR); bitmap_layer_set_compositing_mode(s_powerIconLayer, GCompOpSet); update_power_status(battery_state_service_peek()); // add the bitmap layer to the window layer_add_child(windowLayer, bitmap_layer_get_layer(s_powerIconLayer)); ////////////////////////////////////////// // BT connection GRect bt_icon_bounds = get_bt_icon_bounds(); // Create BitmapLayer to display the GBitmap s_btIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + bt_icon_bounds.size.w + 4), 4, bt_icon_bounds.size.w, bt_icon_bounds.size.h)); // set background colout and compositing mode bitmap_layer_set_background_color(s_btIconLayer, BT_ICON_BACK_COLOR); bitmap_layer_set_compositing_mode(s_btIconLayer, GCompOpSet); update_bt_status(connection_service_peek_pebble_app_connection()); // add the bitmap layer to the window layer_add_child(windowLayer, bitmap_layer_get_layer(s_btIconLayer)); //////////////////////////////////// // Create the time text layers // time accuracy text layer s_timeAccText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(-2, -6), 94, 28)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_timeAccText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_timeAccText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42)); GFont timeFont = fonts_get_system_font(FONT_KEY_GOTHIC_24); text_layer_set_font(s_timeAccText, timeFont); text_layer_set_text_alignment(s_timeAccText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_timeAccText)); // time text layer s_timeText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(20, 16), bounds.size.w-4, 100)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_timeText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_timeText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); update_timeish(s_timeText,s_timeAccText); //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42)); timeFont = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK); text_layer_set_font(s_timeText, timeFont); text_layer_set_text_alignment(s_timeText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_timeText)); /////////////////////////////////// // Create the date text layer s_dateText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(128, 122), bounds.size.w-4, 16)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_dateText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_dateText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); update_date(s_dateText); //s_dateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_24)); GFont dateFont = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD); text_layer_set_font(s_dateText, dateFont); text_layer_set_text_alignment(s_dateText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_dateText)); ////////////////////////////////// // Create the weather text layer s_weatherText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(112, 108), bounds.size.w-4, 18)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_weatherText, TIME_TEXT_BACK_COLOR); update_weather((Tuple *)NULL,(Tuple *)NULL, (Tuple *)NULL); GFont weatherFont = fonts_get_system_font(FONT_KEY_GOTHIC_14); text_layer_set_font(s_weatherText, weatherFont); text_layer_set_text_alignment(s_weatherText, GTextAlignmentLeft); // Set weather text colour set_weather_text_colour(); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_weatherText)); ////////////////////////////////// // Create the news text layer s_newsText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(142, 136), bounds.size.w-4, 30)); // Improve the layout to be more like a watchface text_layer_set_background_color(s_newsText, TIME_TEXT_BACK_COLOR); text_layer_set_text_color(s_newsText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY)); display_news_weather(); text_layer_set_font(s_newsText, weatherFont); text_layer_set_text_alignment(s_newsText, GTextAlignmentLeft); // Add it as a child layer to the Window's root layer layer_add_child(windowLayer, text_layer_get_layer(s_newsText)); }
void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); update_weather(); }