static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_layer = layer_create(layer_get_bounds(window_get_root_layer(window))); layer_add_child(window_get_root_layer(window), s_layer); layer_set_update_proc(s_layer, draw_watchface); s_time_layer = text_layer_create(GRect(0, 0, 24, 24)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); if (persist_read_int(KEY_BACKGROUND_COLOR)) { background_color = GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR)); window_set_background_color(window, GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR))); } else { background_color = GColorWhite; } setup_blocks(); if (persist_read_int(KEY_DEGREEOPTION)) { degreeOption = persist_read_int(KEY_DEGREEOPTION); } else { degreeOption = 0; } s_weather_layer = text_layer_create(GRect(0,152, 144, 14)); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight); text_layer_set_text(s_weather_layer, "Loading..."); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30)); layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc); bluetooth_path = gpath_create(&BLUETOOTH_INFO); layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer); //show the correct state of the bluetooth connection from the start #ifdef PBL_SDK_2 bluetooth_callback(bluetooth_connection_service_peek()); #elif PBL_SDK_3 bluetooth_callback(connection_service_peek_pebble_app_connection()); #endif s_date_layer = text_layer_create(GRect(0,0,144,14)); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); }
int bluetooth_input(FAR struct radio_driver_s *radio, FAR struct iob_s *framelist, FAR struct bluetooth_frame_meta_s *meta) { FAR struct bluetooth_conn_s *conn; FAR struct iob_s *frame; FAR struct iob_s *next; int ret = OK; /* Check if there is a connection that will accept this packet */ conn = bluetooth_conn_active(meta); if (conn != NULL) { /* Setup for the application callback (NOTE: These should not be * used by PF_BLUETOOTH sockets). */ radio->r_dev.d_appdata = radio->r_dev.d_buf; radio->r_dev.d_len = 0; radio->r_dev.d_sndlen = 0; /* The framelist probably contains only a single frame, but we will * process it as a list of frames. */ for (frame = framelist; frame != NULL; frame = next) { /* Remove the frame from the list */ next = frame->io_flink; frame->io_flink = NULL; /* Add the frame to the RX queue */ ret = bluetooth_queue_frame(conn, frame, meta); if (ret < 0) { nerr("ERROR: Failed to queue frame: %d\n", ret); iob_free(frame); } } /* Perform the application callback. The frame may be processed now * if there is a user wait for an incoming frame. Or it may pend in * the RX queue until some user process reads the frame. NOTE: The * return value from bluetooth_callback would distinguish these * cases: BLUETOOTH_NEWDATA will still be processed if the frame * was not consumed. */ (void)bluetooth_callback(radio, conn, BLUETOOTH_NEWDATA); } else { nwarn("WARNING: No listener\n"); } return ret; }
void load_batteries(Window *window, Layer *window_layer, GRect bounds) { s_watch_battery_layer = text_layer_create( GRect(25, 70, bounds.size.w, 50)); s_phone_battery_layer = text_layer_create( GRect(100, 70, bounds.size.w, 50)); text_layer_set_background_color(s_watch_battery_layer, GColorClear); text_layer_set_background_color(s_phone_battery_layer, GColorClear); text_layer_set_text_color(s_watch_battery_layer, GColorWhite); text_layer_set_text_color(s_phone_battery_layer, GColorWhite); text_layer_set_text(s_watch_battery_layer, " ?"); text_layer_set_text(s_phone_battery_layer, " ?"); text_layer_set_text_alignment(s_watch_battery_layer, GTextAlignmentLeft); text_layer_set_text_alignment(s_phone_battery_layer, GTextAlignmentLeft); text_layer_set_font(s_watch_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_font(s_phone_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); // Create the Bluetooth icon GBitmap s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BLUETOOTH_DISABLED); // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = bitmap_layer_create(GRect(95, 70, 30, 30)); 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)); layer_add_child(window_layer, text_layer_get_layer(s_watch_battery_layer)); layer_add_child(window_layer, text_layer_get_layer(s_phone_battery_layer)); // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); }
static void main_window_load(Window *window) { GRect bounds = layer_get_bounds(window_get_root_layer(window)); //Create GBitmap, then set to created BitmapLayer //s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND); //s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); //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 canvas layer s_vert_layer = layer_create(bounds); s_vert2_layer = layer_create(bounds); s_canvas_layer = layer_create(bounds); s_canvas2_layer = layer_create(bounds); // Assign the custom drawing procedure layer_set_update_proc(s_vert_layer, vert_update_proc); layer_set_update_proc(s_vert2_layer, vert2_update_proc); layer_set_update_proc(s_canvas_layer, canvas_update_proc); layer_set_update_proc(s_canvas2_layer, canvas2_update_proc); // Add to Window layer_add_child(window_get_root_layer(window), s_vert_layer); layer_add_child(window_get_root_layer(window), s_vert2_layer); layer_add_child(window_get_root_layer(window), s_canvas_layer); layer_add_child(window_get_root_layer(window), s_canvas2_layer); // Create GFonts s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPEN_60)); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPEN_17)); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 30, 144, 60)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorLightGray); 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_get_root_layer(window), text_layer_get_layer(s_time_layer)); // Create date TextLayer s_date_layer = text_layer_create(GRect(0, 120, 144, 23)); text_layer_set_text_color(s_date_layer, GColorLightGray); 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)); // Initialize the display update_time(); bluetooth_callback(connection_service_peek_pebble_app_connection()); }
static void main_window_load(Window *window) { time_layer = text_layer_create(GRect(0, 30, 144, 61)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_color(time_layer, GColorBlack); time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LIBERATION_NARROW_BOLD_60)); text_layer_set_font(time_layer, time_font); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(main_window), text_layer_get_layer(time_layer)); seconds_layer = text_layer_create(GRect(0, 90, 144, 34)); text_layer_set_background_color(seconds_layer, GColorClear); text_layer_set_text_color(seconds_layer, GColorBlack); seconds_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LIBERATION_NARROW_BOLD_30)); text_layer_set_font(seconds_layer, seconds_font); text_layer_set_text_alignment(seconds_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(main_window), text_layer_get_layer(seconds_layer)); date_layer = text_layer_create(GRect(0, 125, 144, 34)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, GColorBlack); date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LIBERATION_NARROW_BOLD_30)); text_layer_set_font(date_layer, date_font); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(main_window), text_layer_get_layer(date_layer)); battery_text_layer = text_layer_create(GRect(32, 0, 67, 34)); text_layer_set_background_color(battery_text_layer, GColorClear); text_layer_set_text_color(battery_text_layer, GColorBlack); battery_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LIBERATION_NARROW_BOLD_30)); text_layer_set_font(battery_text_layer, battery_font); text_layer_set_text_alignment(battery_text_layer, GTextAlignmentLeft); layer_add_child(window_get_root_layer(main_window), text_layer_get_layer(battery_text_layer)); battery_0_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_0); battery_1_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_1); battery_2_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_2); battery_3_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_3); battery_4_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_4); battery_5_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_5); battery_loading_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_LOADING); battery_icon_layer = bitmap_layer_create(GRect(10, 7, 15, 24)); bitmap_layer_set_bitmap(battery_icon_layer, battery_0_bitmap); layer_add_child(window_get_root_layer(main_window), bitmap_layer_get_layer(battery_icon_layer)); bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); bt_icon_layer = bitmap_layer_create(GRect(116, 7, 18, 24)); bitmap_layer_set_bitmap(bt_icon_layer, bt_icon_bitmap); layer_add_child(window_get_root_layer(main_window), bitmap_layer_get_layer(bt_icon_layer)); bluetooth_callback(bluetooth_connection_service_peek()); }
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"); }
static void main_window_load(Window *window) { // Get information about the Window Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); APP_LOG(APP_LOG_LEVEL_INFO, "Main window loading"); APP_LOG(APP_LOG_LEVEL_INFO, "battery time"); s_battery_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(0, 20), PBL_IF_ROUND_ELSE(0, 154), PBL_IF_ROUND_ELSE(180, 104), PBL_IF_ROUND_ELSE(180, 2))); s_weather_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(117, 120), bounds.size.w, 55)); s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(52, 46), bounds.size.w, 80)); s_date_layer = PBL_IF_BW_ELSE(text_layer_create(GRect(1, 2, bounds.size.w, 50)), text_layer_create(GRect(PBL_IF_ROUND_ELSE(42, 1), PBL_IF_ROUND_ELSE(15, 1), PBL_IF_ROUND_ELSE(97, 65), 55))); s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30))); int textcolor = persist_read_int(MESSAGE_KEY_TextColor); int background = persist_read_int(MESSAGE_KEY_BackgroundColor); GColor bg_color = GColorFromHEX(background); GColor text_color = GColorFromHEX(textcolor); window_set_background_color(s_main_window, bg_color); APP_LOG(APP_LOG_LEVEL_INFO, "Text Color is: %d", textcolor); APP_LOG(APP_LOG_LEVEL_INFO, "Background Color is: %d", background); // Battery Layer layer_set_update_proc(s_battery_layer, battery_update_proc); // Add Battery Layer to Window layer_add_child(window_get_root_layer(window), s_battery_layer); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: celsius"); if (persist_read_bool(MESSAGE_KEY_Celsius)) { celsius = persist_read_int(MESSAGE_KEY_Celsius); } /* APP_LOG(APP_LOG_LEVEL_INFO, "reading key: customLocation"); if (persist_read_string(KEY_CUSTOM_LOCATION)) { customLocation = persist_read_string(KEY_CUSTOM_LOCATION); }*/ APP_LOG(APP_LOG_LEVEL_INFO, "weather time"); // Weather Layer text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, text_color); //text_layer_set_text_color(s_weather_layer, GColorBlack); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter); PBL_IF_BW_ELSE(text_layer_set_text(s_weather_layer, ""), text_layer_set_text(s_weather_layer, "Loading...")); s_weather_font = PBL_IF_ROUND_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20))); text_layer_set_font(s_weather_layer, s_weather_font); // Add Weather Layer to Window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); APP_LOG(APP_LOG_LEVEL_INFO, "time layer"); // Time Layer s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_53)); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, text_color); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: invert"); APP_LOG(APP_LOG_LEVEL_INFO, "reading key: 24h"); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Add Time Layer to Window layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); APP_LOG(APP_LOG_LEVEL_INFO, "date time"); // Date Layer s_date_font = PBL_IF_BW_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17))); text_layer_set_text_color(s_date_layer, text_color); //text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_font(s_date_layer, s_date_font); APP_LOG(APP_LOG_LEVEL_INFO, "updating time"); // Add Date Layer to Window layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); // Create the Bluetooth icon GBitmap APP_LOG(APP_LOG_LEVEL_INFO, "Reading Bluetooth color: %d", persist_read_bool(MESSAGE_KEY_Bluetooth)); if (persist_read_int(MESSAGE_KEY_Bluetooth) == 102) { s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); } else { s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON_BLACK); } // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30))); layer_set_update_proc(s_bt_icon_layer, layer_update_proc); //bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); layer_add_child(window_layer, s_bt_icon_layer); APP_LOG(APP_LOG_LEVEL_INFO, "steps time"); // Steps Layer // subscribe to health events int goal_num = persist_read_int(MESSAGE_KEY_Step_Goal); int steps = persist_read_int(MESSAGE_KEY_Goal_Color); GColor steps_color = GColorFromHEX(steps); s_num_label = text_layer_create(GRect(PBL_IF_ROUND_ELSE(67, 90), PBL_IF_ROUND_ELSE(37, 1), 50, 45)); text_layer_set_background_color(s_num_label, GColorClear); text_layer_set_text_color(s_num_label, text_color); int s_step_count = (int)health_service_sum_today(HealthMetricStepCount); if (goal_num == 0 || s_step_count < goal_num) { int textcolor = persist_read_int(MESSAGE_KEY_TextColor); GColor text_color = GColorFromHEX(textcolor); text_layer_set_text_color(s_num_label, text_color); } else { text_layer_set_text_color(s_num_label, steps_color); } //text_layer_set_text_color(s_num_label, GColorBlack); text_layer_set_text_alignment(s_num_label, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight)); text_layer_set_font(s_num_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17))); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_num_label)); if(health_service_events_subscribe(health_handler, NULL)) { // force initial steps display health_handler(HealthEventMovementUpdate, NULL); } else { APP_LOG(APP_LOG_LEVEL_ERROR, "Health not available!"); } // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); APP_LOG(APP_LOG_LEVEL_INFO, "Main window loaded"); update_time(); }
static void main_window_load(Window *window) { printf("main_window_load function"); //Create GBitmap, then set to created BitmapLayer s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND); s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); 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 time TextLayer s_time_layer = text_layer_create(GRect(5, 52, 139, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text(s_time_layer, "00:00"); // Create temperature Layer s_weather_layer = text_layer_create(GRect(0, 130, 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_text(s_weather_layer, "Loading..."); // Create date TextLayer s_date_layer = text_layer_create(GRect(0, 115, 144, 30)); text_layer_set_text_color(s_date_layer, GColorWhite); 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, "Date Load..."); //Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48)); text_layer_set_font(s_time_layer, s_time_font); s_weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_20)); text_layer_set_font(s_weather_layer, s_weather_font); s_date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_15)); text_layer_set_font(s_date_layer, s_date_font); // Create the Bluetooth icon GBitmap s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON); // Create the BitmapLayer to display the GBitmap s_bt_icon_layer = bitmap_layer_create(GRect(59, 12, 30, 30)); bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap); // Show the correct state of the BT connection from the start bluetooth_callback(connection_service_peek_pebble_app_connection()); // Add it as a child layer to the Window's root layer 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_weather_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bt_icon_layer)); // Create battery meter Layer s_battery_layer = layer_create(GRect(14, 54, 115, 2)); layer_set_update_proc(s_battery_layer, battery_update_proc); // Add to Window layer_add_child(window_get_root_layer(window), s_battery_layer); // Make sure the time is displayed from the start update_time(); }
//////////////////////////////////////////////////// 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()); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_layer = layer_create(layer_get_bounds(window_get_root_layer(window))); layer_add_child(window_get_root_layer(window), s_layer); layer_set_update_proc(s_layer, draw_watchface); uint16_t vert_padding = (bounds.size.h - ((NUM_BARS - 1)*PADDING) - (NUM_BARS*HEIGHT)) / 2; uint16_t width = bounds.size.w - (2 * PADDING); //this is 120 on basalt //create the unary ticks image s_unary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_UNARY_TICKS); s_unary_ticks_layer = bitmap_layer_create(GRect(PADDING,vert_padding,width + 1,HEIGHT)); bitmap_layer_set_background_color(s_unary_ticks_layer, GColorClear); bitmap_layer_set_bitmap(s_unary_ticks_layer, s_unary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_unary_ticks_layer, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_unary_ticks_layer)); //create the ternary ticks image and layer for minutes s_ternary_ticks_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_TERNARY_TICKS); s_ternary_ticks_layer_minutes = bitmap_layer_create(GRect(PADDING, vert_padding + PADDING + HEIGHT, width + 1, HEIGHT)); bitmap_layer_set_background_color(s_ternary_ticks_layer_minutes, GColorClear); bitmap_layer_set_bitmap(s_ternary_ticks_layer_minutes, s_ternary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_minutes, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_minutes)); //create the ternary ticks layer for seconds s_ternary_ticks_layer_seconds = bitmap_layer_create(GRect(PADDING, vert_padding + (2*PADDING) + (2*HEIGHT), width + 1, HEIGHT)); bitmap_layer_set_background_color(s_ternary_ticks_layer_seconds, GColorClear); bitmap_layer_set_bitmap(s_ternary_ticks_layer_seconds, s_ternary_ticks_bitmap); bitmap_layer_set_compositing_mode(s_ternary_ticks_layer_seconds, GCompOpSet); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_ticks_layer_seconds)); if (persist_read_int(KEY_TOP_BAR_COLOR)) { s_top_bar_color = GColorFromHEX(persist_read_int(KEY_TOP_BAR_COLOR)); /// set_background_and_text_color(background_color); } else { s_top_bar_color = GColorRed; } if (persist_read_int(KEY_MIDDLE_BAR_COLOR)) { s_middle_bar_color = GColorFromHEX(persist_read_int(KEY_MIDDLE_BAR_COLOR)); } else { s_middle_bar_color = GColorGreen; } if (persist_read_int(KEY_BOTTOM_BAR_COLOR)) { s_bottom_bar_color = GColorFromHEX(persist_read_int(KEY_BOTTOM_BAR_COLOR)); } else { s_bottom_bar_color = GColorBlue; } if (persist_read_int(KEY_BACKGROUND_COLOR)) { set_background_and_text_color(persist_read_int(KEY_BACKGROUND_COLOR)); } else { set_background_and_text_color(0xFFFFFF); } if (persist_read_int(KEY_DEGREEOPTION)) { degreeOption = persist_read_int(KEY_DEGREEOPTION); } else { degreeOption = 0; } s_weather_layer = text_layer_create(GRect(0,152, 144, 14)); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight); text_layer_set_text(s_weather_layer, "Loading..."); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30)); layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc); bluetooth_path = gpath_create(&BLUETOOTH_INFO); layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer); //show the correct state of the bluetooth connection from the start #ifdef PBL_SDK_2 bluetooth_callback(bluetooth_connection_service_peek()); #elif PBL_SDK_3 bluetooth_callback(connection_service_peek_pebble_app_connection()); #endif s_date_layer = text_layer_create(GRect(0,0,144,14)); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); }
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; }