void handle_init(void) { // Create a window and text layer window = window_create(); text_layer = text_layer_create(GRect(0, TIME_HEIGHT, 144, 168 - TIME_HEIGHT)); show_seconds = persist_read_bool(KEY_SHOW_SECONDS); invert_face = persist_read_bool(KEY_INVERT); metric_units = persist_read_bool(KEY_UNITS); latitude[0] = 0; longitude[0] = 0; location[0] = 0; weather[0] = 0; // Set the text, font, and text alignment //text_layer_set_text(text_layer, ""); // http://www.openweathermap.org/current // https://developer.getpebble.com/blog/2013/07/24/Using-Pebble-System-Fonts/ // https://github.com/JvetS/PebbleSimulator/blob/master/PebbleSimulator/pebble_fonts.h text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); // https://developer.getpebble.com/2/api-reference/group___graphics_types.html text_layer_set_text_alignment(text_layer, GTextAlignmentLeft); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); // date_layer = text_layer_create(GRect(0, 112, 144, 56)); // text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); // text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); // layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); time_layer = text_layer_create(GRect(0, 0, 144, TIME_HEIGHT)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_font(time_layer, fonts_get_system_font(FONT_PRO_32)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); inverter_layer = inverter_layer_create(GRect(0, 0, 144, 168)); layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter_layer)); layer_set_hidden(inverter_layer_get_layer(inverter_layer), invert_face); battery_state_service_subscribe(handle_battery_change); handle_battery_change(battery_state_service_peek()); bluetooth_connection_service_subscribe(handle_bluetooth_change); handle_bluetooth_change(bluetooth_connection_service_peek()); app_message_register_inbox_received(in_received_handler); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); time_t current_time = time(0); handle_timechanges(localtime(¤t_time), SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, handle_timechanges); // Push the window window_stack_push(window, true); // App Logging! //APP_LOG(APP_LOG_LEVEL_DEBUG, "Hello World from the applogs!"); }
void handle_init(void) { // Creates images resource bitmap_1 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_GROUND_TEMPLATE); bitmap_2 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_YL0); bitmap_3 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_YF0); bitmap_4 = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_YR0); // Create a window and text layer window = window_create(); text_layer = text_layer_create(GRect(0, 0, 144, 154)); // Set the text, font, and text alignment text_layer_set_text(text_layer, "Hello World!"); text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); // Add the text layer to the window layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); date_layer = text_layer_create(GRect(0, 112, 144, 56)); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); inverter_layer = inverter_layer_create(GRect(0, 112, 144, 56)); layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter_layer)); // Draws ground ground = bitmap_layer_create(GRect(0, 56, 144, 56)); yorp_left = bitmap_layer_create(r1); yorp_front = bitmap_layer_create(r2); yorp_right = bitmap_layer_create(r3); bitmap_layer_set_bitmap(ground, bitmap_1); bitmap_layer_set_bitmap(yorp_left, bitmap_2); bitmap_layer_set_bitmap(yorp_front, bitmap_3); bitmap_layer_set_bitmap(yorp_right, bitmap_4); Layer * l = window_get_root_layer(window); layer_add_child(l, bitmap_layer_get_layer(ground)); layer_add_child(l, bitmap_layer_get_layer(yorp_left)); layer_add_child(l, bitmap_layer_get_layer(yorp_front)); layer_add_child(l, bitmap_layer_get_layer(yorp_right)); time_t now = time(NULL); handle_timechanges(localtime(&now), SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, handle_timechanges); // Push the window window_stack_push(window, true); // App Logging! APP_LOG(APP_LOG_LEVEL_DEBUG, "Hello World from the applogs!"); }
static void init() { window = window_create(); window_set_background_color(window, GColorBlack); window_stack_push(window, false /* Animated */); window_layer = window_get_root_layer(window); // Set font GFont clock_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_Clock_60)); GFont date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_Date_10)); // Different layers hour_layer = text_layer_create(GRect(25, 0, 119, 84)); text_layer_set_font(hour_layer, clock_font); text_layer_set_text_color(hour_layer,GColorWhite); text_layer_set_background_color(hour_layer,GColorClear); text_layer_set_text_alignment(hour_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(hour_layer)); minute_layer = text_layer_create(GRect(25, 85, 119, 84)); text_layer_set_font(minute_layer, clock_font); text_layer_set_text_color(minute_layer,GColorWhite); text_layer_set_background_color(minute_layer,GColorClear); text_layer_set_text_alignment(minute_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(minute_layer)); day_layer = text_layer_create(GRect(0, 72, 144, 15)); text_layer_set_font(day_layer, date_font); text_layer_set_text_color(day_layer,GColorWhite); text_layer_set_background_color(day_layer,GColorClear); text_layer_set_text_alignment(day_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(day_layer)); date_layer = text_layer_create(GRect(0, 86, 144, 15)); text_layer_set_font(date_layer, date_font); text_layer_set_text_color(date_layer,GColorWhite); text_layer_set_background_color(date_layer,GColorClear); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(date_layer)); init_bar(charge_state); // Start with current time time_t now = time(NULL); handle_timechanges(localtime(&now), MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_timechanges); }
/* 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); }
// 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()); }