void watchfaceInit(){ battery_state_service_subscribe(handle_battery); for (int i=0;i<posmax;i++){ pos[i].x=((i%6)*18)+4; pos[i].y=(i/6)*15; } scramble(); memset(dsp,0,sizeof(dsp)); loadBitmapFromResource(0,RESOURCE_ID_d); loadBitmapFromResource(1,RESOURCE_ID_e1a1); loadBitmapFromResource(2,RESOURCE_ID_e1a2); loadBitmapFromResource(3,RESOURCE_ID_edie); loadBitmapFromResource(4,RESOURCE_ID_live); #ifdef PBL_PLATFORM_CHALK createTextLayer(0,GRect(40, 130, 100, 45),fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS),GTextAlignmentCenter,GColorGreen,GColorBlack); createTextLayer(1,GRect(50, 2, 80, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentCenter,GColorWhite,GColorBlack); createTextLayer(2,GRect(50, 120, 80, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentCenter,GColorWhite,GColorBlack); #else #ifdef PBL_COLOR createTextLayer(0,GRect(-3, 123, 114, 45),fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT),GTextAlignmentLeft,GColorGreen,GColorBlack); #else createTextLayer(0,GRect(-3, 123, 114, 45),fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT),GTextAlignmentLeft,GColorWhite,GColorBlack); #endif createTextLayer(2,GRect(111, 151, 32, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentRight,GColorWhite,GColorBlack); createTextLayer(1,GRect(111, 139, 33, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentRight,GColorWhite,GColorBlack); #endif setlocale(LC_ALL, ""); handle_battery(battery_state_service_peek()); update_time(true); }
void handle_appmessage_receive(DictionaryIterator *received, void *context) { Tuple *tuple = dict_read_first(received); while (tuple) { switch (tuple->key) { case SECONDS_MODE: seconds_mode = tuple->value->int32; break; case BATTERY_MODE: battery_mode = tuple->value->int32; break; case DATE_MODE: date_mode = tuple->value->int32; break; case BLUETOOTH_MODE: bluetooth_mode = tuple->value->int32; break; case GRAPHICS_MODE: graphics_mode = tuple->value->int32; break; case CONNLOST_MODE: connlost_mode = tuple->value->int32; break; } tuple = dict_read_next(received); } APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config"); has_config = true; handle_battery(battery_state_service_peek()); handle_bluetooth(bluetooth_connection_service_peek()); handle_inverter(); }
void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) { // Need to be static because they're used by the system later. static char time_text[] = "00:00:00"; static char date_text[] = "Xxxx 00/00/00"; char *time_format; handle_battery(battery_state_service_peek()); // TODO: Only update the date when it's changed. strftime(date_text, sizeof(date_text), "%a. %D", tick_time); text_layer_set_text(text_date_layer, date_text); if (clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } strftime(time_text, sizeof(time_text), time_format, tick_time); // Kludge to handle lack of non-padded hour format string // for twelve hour clock. if (!clock_is_24h_style() && (time_text[0] == '0')) { memmove(time_text, &time_text[1], sizeof(time_text) - 1); } text_layer_set_text(text_time_layer, time_text); }
void show_watchface(void) { initialise_ui(); s_res_charging = gbitmap_create_with_resource(RESOURCE_ID_CHARGING); s_res_battery_20 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_20); s_res_battery_40 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_40); s_res_battery_60 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_60); s_res_battery_80 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_80); s_res_battery_100 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_100); layer_set_update_proc(sCalendarLayer, calendar_layer_update_callback); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); battery_state_service_subscribe(handle_battery); bluetooth_connection_service_subscribe(handle_bluetooth); sTimer = NULL; btStatus = bluetooth_connection_service_peek(); handle_battery(battery_state_service_peek()); currentTime = get_time(); update_time_text(); update_date_text(); layer_mark_dirty(sCalendarLayer); window_set_window_handlers(s_window, (WindowHandlers) { .unload = handle_window_unload, });
void init() { window = window_create(); window_set_background_color(window, GColorBlack); WindowHandlers handlers = { .load = window_load, .unload = window_unload }; window_set_window_handlers(window, handlers); window_set_fullscreen(window, true); //Register AppMessage events app_message_register_inbox_received(in_received_handler); app_message_open(512, 512); //Large input and output buffer sizes window_stack_push(window, true); // Init the text layer used to show the time time_layer = text_layer_create(GRect(0, 0, 144 /* width */, 50 /* height */)); text_layer_set_text_color(time_layer, GColorBlack); text_layer_set_background_color(time_layer, GColorWhite); text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); // 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_battery(battery_state_service_peek()); handle_second_tick(current_time, SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick); battery_state_service_subscribe(&handle_battery); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); }
static void init(void) { memset(&time_digits_layers, 0, sizeof(time_digits_layers)); memset(&time_digits_images, 0, sizeof(time_digits_images)); const int inbound_size = 64; const int outbound_size = 64; app_message_open(inbound_size, outbound_size); window = window_create(); if (window == NULL) { return; } window_set_background_color(window, GColorBlack); canvas = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(canvas, (LayerUpdateProc) render); layer_add_child(window_get_root_layer(window), canvas); window_stack_push(window, true); Layer *window_layer = window_get_root_layer(window); load_settings(); // Open AppMessage connection app_message_register_inbox_received(inbox_received_handler); app_message_open(128, 128); //owm_weather_init(5ba77aab84470992ddc7e49e4985aeab); //events_app_message_open(); //owm_weather_fetch(); handle_weather(); handle_battery(battery_state_service_peek()); battery_state_service_subscribe(handle_battery); // Create time and date layers GRect dummy_frame = { {0, 0}, {0, 0} }; for (int i = 0; i < TOTAL_TIME_DIGITS; i++) { time_digits_layers[i] = bitmap_layer_create(dummy_frame); layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i])); } mFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20)); mDayText = malloc(mDayTextSize); mWeatherText = malloc(mWeatherTextSize); mBatteryText = malloc(mBatteryTextSize); // Avoids a blank screen on watch start. time_t now = time(NULL); struct tm *tick_time = localtime(&now); handle_tick(tick_time, DAY_UNIT + HOUR_UNIT + MINUTE_UNIT); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); }
void handle_init() { // Configure window window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, BKGD_COLOR); window_set_fullscreen(window, true); Layer *window_layer = window_get_root_layer(window); // Dynamic allocation of assets minuteFrame = GRect(53, 16, 40, 40); minuteLayer = text_layer_create(minuteFrame); hourLayer = bitmap_layer_create(GRect(0, 0, 144, 148)); batteryLogoLayer = bitmap_layer_create(GRect(65, 151, 10, 15)); batteryPercentLayer = text_layer_create(GRect(78, 150, 30, 167-150)); dateLayer = text_layer_create(GRect(3, 150, 38, 167-150)); dayLayer = text_layer_create(GRect(141-30, 150, 30, 167-150)); text_layer_set_text_alignment(dayLayer, GTextAlignmentRight); bottomBarLayer = layer_create(GRect(1, 149, 142, 18)); // Setup minute layer text_layer_set_text_color(minuteLayer, TEXT_COLOR); text_layer_set_background_color(minuteLayer, GColorClear); text_layer_set_font(minuteLayer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MINUTE_38))); // Setup date & day layer text_layer_set_text_color(dateLayer, TEXT_COLOR); text_layer_set_background_color(dateLayer, GColorClear); text_layer_set_text_color(dayLayer, TEXT_COLOR); text_layer_set_background_color(dayLayer, GColorClear); // Setup battery layers text_layer_set_text_color(batteryPercentLayer, TEXT_COLOR); text_layer_set_background_color(batteryPercentLayer, GColorClear); // Setup line layer layer_set_update_proc(bottomBarLayer, bottom_bar_layer_update_callback); // Add layers into hierachy layer_add_child(bitmap_layer_get_layer(hourLayer), text_layer_get_layer(minuteLayer)); layer_add_child(window_layer, bitmap_layer_get_layer(hourLayer)); layer_add_child(window_layer, bottomBarLayer); layer_add_child(window_layer, bitmap_layer_get_layer(batteryLogoLayer)); layer_add_child(window_layer, text_layer_get_layer(batteryPercentLayer)); layer_add_child(window_layer, text_layer_get_layer(dateLayer)); layer_add_child(window_layer, text_layer_get_layer(dayLayer)); // Avoids a blank screen on watch start. time_t tick_time = time(NULL); display_time(localtime(&tick_time)); handle_battery(battery_state_service_peek()); handle_bluetooth(bluetooth_connection_service_peek()); tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick); battery_state_service_subscribe(&handle_battery); bluetooth_connection_service_subscribe(&handle_bluetooth); initialized = true; }
static void do_init(void) { window = window_create(); window_stack_push(window, true); window_layer = window_get_root_layer(window); date_layer = text_layer_create(GRect(layers[0][0][0],layers[0][0][1],layers[0][1][0],layers[0][1][1])); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); text_layer_set_text(date_layer, ""); ampm_layer = text_layer_create(GRect(layers[3][0][0],layers[3][0][1],layers[3][1][0],layers[3][1][1])); text_layer_set_text_alignment(ampm_layer, GTextAlignmentCenter); text_layer_set_text(ampm_layer, ""); text_layer_set_text_color(date_layer, GColorBlack); text_layer_set_background_color(date_layer, GColorWhite); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16))); conn_layer = bitmap_layer_create( GRect(layers[1][0][0],layers[1][0][1],layers[1][1][0],layers[1][1][1])); load_icon_into_layer(0, bitmap_layer_get_layer(conn_layer)); battery_layer = bitmap_layer_create( GRect(layers[2][0][0],layers[2][0][1],layers[2][1][0],layers[2][1][1])); load_icon_into_layer(0, bitmap_layer_get_layer(battery_layer)); int adj = 0; for (int slot_number = 0; slot_number < TOTAL_IMAGE_SLOTS; slot_number++) { digit_slot[slot_number] = bitmap_layer_create( GRect(position[slot_number][0][0], position[slot_number][0][1], position[slot_number][1][0], position[slot_number][1][1])); load_digit_image_into_slot(slot_number, slot_number); layer_add_child(window_layer, bitmap_layer_get_layer(digit_slot[slot_number])); } time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_second_tick(current_time, SECOND_UNIT); handle_bluetooth(bluetooth_connection_service_peek()); handle_battery(battery_state_service_peek()); tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick); battery_state_service_subscribe(&handle_battery); bluetooth_connection_service_subscribe(&handle_bluetooth); layer_add_child(window_layer, text_layer_get_layer(date_layer)); window_set_background_color(window, GColorWhite); text_layer_set_text_color(date_layer, GColorBlack); text_layer_set_background_color(date_layer, GColorWhite); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16))); layer_add_child(window_layer, bitmap_layer_get_layer(conn_layer)); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); layer_add_child(window_layer, text_layer_get_layer(ampm_layer)); }
void handle_init(void) { window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); fontRobotoCondensed19 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19)); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); triangle_overlay_layer = layer_create(bounds); layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback); layer_add_child(window_layer, triangle_overlay_layer); triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS); gpath_move_to(triangle_overlay_path, grect_center_point(&bounds)); // init hand paths minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS); gpath_move_to(minute_arrow_path, grect_center_point(&bounds)); hour_arrow_path = gpath_create(&HOUR_HAND_POINTS); gpath_move_to(hour_arrow_path, grect_center_point(&bounds)); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); s_hands_layer = layer_create(bounds); layer_set_update_proc(s_hands_layer, hands_update_proc); layer_add_child(window_layer, s_hands_layer); // Battery Line Basalt #ifdef PBL_PLATFORM_BASALT GRect line_frame = GRect(22, 160, 104, 6); LineLayer = layer_create(line_frame); layer_set_update_proc(LineLayer, line_layer_update_callback); layer_add_child(window_layer, LineLayer); #else //Chalk GRect line_round_frame = GRect(1, 1, 180, 180); RoundBatteryLayer = layer_create(line_round_frame); layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback); layer_add_child(window_layer,RoundBatteryLayer); #endif //Service subscribes: battery_state_service_subscribe(&handle_battery); handle_battery(battery_state_service_peek()); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); app_focus_service_subscribe(&handle_appfocus); }
static void do_init(void) { window = window_create(); window_stack_push(window, true); window_set_background_color(window, GColorBlack); window_layer = window_get_root_layer(window); GRect line_frame = GRect(8, 120, 139, 2); line_layer = layer_create(line_frame); layer_set_update_proc(line_layer, draw_line); layer_add_child(window_layer, line_layer); time_layer = text_layer_create(GRect(5, 66, 118, 70)); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_44))); text_layer_set_text_alignment(time_layer,GTextAlignmentRight); layer_add_child(window_layer, text_layer_get_layer(time_layer)); date_layer = text_layer_create(GRect(65, 125, 79, 25)); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18))); layer_add_child(window_layer, text_layer_get_layer(date_layer)); wday_layer = text_layer_create(GRect(60, 143, 50, 25)); text_layer_set_text_color(wday_layer, GColorWhite); text_layer_set_background_color(wday_layer, GColorClear); text_layer_set_font(wday_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18))); layer_add_child(window_layer, text_layer_get_layer(wday_layer)); //+時間のNULL回避?(わかってない→調べる time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_time_tick(current_time, SECOND_UNIT); tick_timer_service_subscribe(SECOND_UNIT, &handle_time_tick); batt_layer = bitmap_layer_create(GRect(123, 151, 14, 10)); layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer)); //親レイヤに載せる watchicon_layer = bitmap_layer_create(GRect(131, 151, 6, 10)); layer_add_child(window_layer, bitmap_layer_get_layer(watchicon_layer)); bitmap_layer_set_background_color(watchicon_layer, GColorClear); bt_layer = bitmap_layer_create(GRect(110, 151, 11, 10)); layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer)); handle_battery(battery_state_service_peek()); battery_state_service_subscribe(&handle_battery); handle_bluetooth(bluetooth_connection_service_peek()); bluetooth_connection_service_subscribe(&handle_bluetooth); }
static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) { static char time_text[] = "00:00:00"; if (clock_is_24h_style() == true){ strftime(time_text, sizeof(time_text), "%T", tick_time); } else { strftime(time_text, sizeof(time_text), "%I:%M:%S %p", tick_time); } text_layer_set_text(time_layer, time_text); handle_battery(battery_state_service_peek()); }
static void handle_second_tick(struct tm* current_time, TimeUnits units_changed) { //Display Seconds set_container_image(&time_digits_images[4], time_digits_layers[4], DATENUM_IMAGE_RESOURCE_IDS[current_time->tm_sec/10], GPoint(107, 90)); set_container_image(&time_digits_images[5], time_digits_layers[5], DATENUM_IMAGE_RESOURCE_IDS[current_time->tm_sec%10], GPoint(120, 90)); //Update status of the battery handle_battery(battery_state_service_peek()); //If a minute has passed update rest of items if(current_time->tm_sec == 0) update_display(current_time); }
// Called once per second static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) { static char time_text[] = "00:00:00"; // Needs to be static because it's used by the system later. static char day_text[] = "- 00 / 00 / 00 -"; // Needs to be static because it's used by the system later. strftime(time_text, sizeof(time_text), "%T", tick_time); text_layer_set_text(time_layer, time_text); strftime(day_text, sizeof(day_text), " %d / %m / %y ", tick_time); text_layer_set_text(day_layer, day_text); handle_battery(battery_state_service_peek()); }
static void window_load(Window *window) { read_settings_from_memory(); GRect bounds = layer_get_bounds(window_get_root_layer(window)); time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(7, 0), bounds.size.w, 55)); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_text_color(time_layer, COLOR_FALLBACK(GColorFromHEX(0x1200ff), GColorBlack)); text_layer_set_text(time_layer, "nnn"); text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); date_layer = text_layer_create(GRect(0, 55, bounds.size.w, 20)); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_text_color(date_layer, COLOR_FALLBACK(GColorFromHEX(0x9b0000), GColorBlack)); text_layer_set_text(date_layer, "mm-dd-yyyy"); text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(date_layer, GTextAlignmentCenter); line = layer_create(GRect(PBL_IF_ROUND_ELSE(12, 8), 90, PBL_IF_ROUND_ELSE(155, 128), 2)); layer_set_update_proc(line, draw_line); condition_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(5, 0), 105, bounds.size.w/2, 168)); text_layer_set_background_color(condition_layer, GColorClear); text_layer_set_text_color(condition_layer, COLOR_FALLBACK(GColorFromHEX(0x666159), GColorBlack)); text_layer_set_text_alignment(condition_layer, GTextAlignmentCenter); text_layer_set_font(condition_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(condition_layer, "Loading"); temperature_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(5, 0), 125, bounds.size.w/2, 168)); text_layer_set_text_alignment(temperature_layer, GTextAlignmentCenter); text_layer_set_background_color(temperature_layer, GColorClear); text_layer_set_text_color(temperature_layer, COLOR_FALLBACK(GColorFromHEX(0x666159), GColorBlack)); text_layer_set_font(temperature_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(temperature_layer, "---"); battery = gbitmap_create_with_resource(BATTERY[0]); battery_layer = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(72, 67), 90, bounds.size.w/2, 78)); bitmap_layer_set_compositing_mode(battery_layer, GCompOpSet); bitmap_layer_set_bitmap(battery_layer, battery); layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer)); layer_add_child(window_get_root_layer(window), line); layer_add_child(window_get_root_layer(window), text_layer_get_layer(condition_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(temperature_layer)); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(battery_layer)); update_time(); handle_date(); handle_battery(); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); handle_battery(battery_state_service_peek()); // Get weather update every 30 minutes if(tick_time->tm_min % 30 == 0) { // Begin dictionary DictionaryIterator *iter; app_message_outbox_begin(&iter); // Add a key-value pair dict_write_uint8(iter, 0, 0); // Send the message! app_message_outbox_send(); } }
void battery_enable_display() { if (is_enabled) { return; } is_animating = false; is_enabled = true; // Kickoff first update handle_battery(battery_state_service_peek()); // Subscribe to the battery monitoring service battery_state_service_subscribe(&handle_battery); layer_set_hidden(battery_layer, false); }
static void update_time() { // Get a tm structure time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); if (tick_time->tm_min == 00) { vibes_short_pulse(); light_enable_interaction(); } if (tick_time->tm_min == 00 || tick_time->tm_min == 30) { request_weather(); } // Create a long-lived buffer static char hour_buffer[] = "00"; static char min_buffer[] = "00"; static char am_buffer[] = "00"; strftime(date_buffer, sizeof(date_buffer), " %a \n %b \n %e", tick_time); // Write the current hours and minutes into the buffer if(clock_is_24h_style() == true) { // Use 24 hour format strftime(hour_buffer, sizeof("00"), "%l", tick_time); strftime(min_buffer, sizeof("00"), "%M", tick_time); //"%H:%M", tick_time); strftime(am_buffer, sizeof("00"), "%p", tick_time); } else { // Use 12 hour format strftime(hour_buffer, sizeof("00"), "%l", tick_time); strftime(min_buffer, sizeof("00"), "%M", tick_time); strftime(am_buffer, sizeof("00"), "%p", tick_time); } // Display this time on the TextLayer //text_layer_set_text(s_time_layer, buffer); text_layer_set_text(hour_layer, hour_buffer); text_layer_set_text(min_layer, min_buffer); text_layer_set_text(date_layer, date_buffer); text_layer_set_text(am_layer, am_buffer); handle_battery(battery_state_service_peek()); }
void tick_handler(struct tm *tick_time, TimeUnits units_changed) { //Allocate long-lived storage (required by TextLayer) static char clock_buffer[6]; static char ampm_text[4]; static char date_buffer[12]; //Write the time to the buffer in a safe manner strftime(date_buffer, sizeof(date_buffer), "%e %b", tick_time); int hour = tick_time->tm_hour; int minute = tick_time->tm_min; if ( !clock_is_24h_style() ) { strftime(clock_buffer, sizeof(clock_buffer), "%I:%M", tick_time); } else { strftime(clock_buffer, sizeof(clock_buffer), "%H:%M", tick_time); } // Remove leading zero (only in 12h-mode) if ( !clock_is_24h_style() && (clock_buffer[0] == '0') ) { memmove( clock_buffer, &clock_buffer[1], sizeof( clock_buffer ) - 1 ); } text_layer_set_text(hour_layer, clock_buffer); // Update AM/PM indicator (i.e. AM or PM or nothing when using 24-hour style) strftime( ampm_text, sizeof( ampm_text ), clock_is_24h_style() ? "" : "%p", tick_time ); text_layer_set_text( ampm_layer, ampm_text ); text_layer_set_text(date_layer, date_buffer); int day = tick_time->tm_wday; set_day_layer(day); handle_battery(battery_state_service_peek()); }
void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) { handle_battery(); handle_date(); switch (clock_format) { case 0: // diurnal if(((tick_time->tm_min) * 60 + tick_time->tm_sec) % 50 == 0) update_time(); break; case 1: // semidiurnal if(((tick_time->tm_min) * 60 + tick_time->tm_sec) % 25 == 0) update_time(); break; } // Get weather update every 30 minutes if(tick_time->tm_min % 30 == 0) handle_weather(); }
static void handle_seconde_tick(struct tm* tick_time, TimeUnits units_changed) { // Needs to be static because it's used by the system later. static char s_time_text[] = "00:00"; static char s_date_text[] = "--------------------"; static char s_year_text[] = "----"; // Mise à jour de l'heure strftime(s_time_text, sizeof(s_time_text), "%R", tick_time); text_layer_set_text(s_time_layer, s_time_text); // Mise à jour de la date strftime(s_date_text, sizeof(s_date_text), "%A %d %B", tick_time); text_layer_set_text(s_Date_layer, s_date_text); // Mise à jour de l'année strftime(s_year_text, sizeof(s_year_text), "%Y", tick_time); text_layer_set_text(s_year_layer, s_year_text); handle_battery(battery_state_service_peek()); }
static void timer_callback(void *data) { //Render handle_battery(battery_state_service_peek()); btconnected=bluetooth_connection_service_peek(); layer_mark_dirty(canvas); #ifdef TEST uint32_t tim=1000; #else uint32_t tim=(showSeconds)?1000:60000; #endif if(firstBoot) { tim=100; firstBoot=false; } timer=app_timer_register(tim,(AppTimerCallback) timer_callback,0); }
void init() { time_buffer[TEXT_BUFFER_SIZE] = date_buffer[TEXT_BUFFER_SIZE] = weekday_buffer[TEXT_BUFFER_SIZE] = status_buffer[TEXT_BUFFER_SIZE] = '\0'; window = window_create(); WindowHandlers handlers = { .load = window_load, .unload = window_unload }; window_set_window_handlers(window, handlers); window_stack_push(window, true); app_message_init(); ping_app_message(); battery_state_service_subscribe(handle_battery); BatteryChargeState charge_state = battery_state_service_peek(); handle_battery(charge_state); app_log(APP_LOG_LEVEL_DEBUG, "pebblemonface.c", __LINE__, "Done Initializing"); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //Create GBitmap, then set to created BitmapLayer sushi_resource_id = RESOURCE_ID_SUSHI_S; s_background_bitmap = gbitmap_create_with_resource(sushi_resource_id); s_background_layer = bitmap_layer_create(GRect(0, 60, 720, 72)); 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_FONT_VIGRO_26)); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 20, bounds.size.w, 52)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorDarkGreen); text_layer_set_text(s_time_layer, "00:00:00"); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); s_battery_layer = text_layer_create(GRect(0, 140, bounds.size.w, 34)); text_layer_set_text_color(s_battery_layer, GColorDarkGreen); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentCenter); text_layer_set_text(s_battery_layer, "100% charged"); battery_state_service_subscribe(handle_battery); // 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_battery_layer)); // Make sure the time is displayed from the start update_time(); handle_battery(battery_state_service_peek()); }
void handle_appfocus(bool in_focus){ if (in_focus) { handle_bluetooth(bluetooth_connection_service_peek()); handle_battery(battery_state_service_peek()); } }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); handle_battery(battery_state_service_peek()); }
void handle_minute_tick(struct tm * tick_time, TimeUnits units_changed) { display_time(tick_time); handle_battery(battery_state_service_peek()); }
static void handle_init() { time_t clock = time(NULL); now = localtime(&clock); window = window_create(); window_stack_push(window, true /* Animated */); window_set_background_color(window, GColorBlack); Layer *window_layer = window_get_root_layer(window); background_layer = layer_create(GRect(0, 0, 144, 144)); layer_set_update_proc(background_layer, background_layer_update_callback); layer_add_child(window_layer, background_layer); hands_layer = layer_create(layer_get_frame(background_layer)); layer_set_update_proc(hands_layer, hands_layer_update_callback); layer_add_child(background_layer, hands_layer); for (int i = 0; i < 22; i++) { battery_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY_0 + i); } battery_layer = bitmap_layer_create(GRect(144-16-3, 3, 16, 10)); layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer)); for (int i = 0; i < 2; i++) bluetooth_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF + i); bluetooth_layer = bitmap_layer_create(GRect(66, 0, 13, 13)); layer_add_child(background_layer, bitmap_layer_get_layer(bluetooth_layer)); battp_layer = text_layer_create(GRect(0, 0, 32, 16)); text_layer_set_text_color(battp_layer, GColorWhite); text_layer_set_background_color(battp_layer, GColorBlack); layer_add_child(window_layer, text_layer_get_layer(battp_layer)); hour_path = gpath_create(&HOUR_POINTS); hour_in_path = gpath_create(&HOUR_IN_POINTS); gpath_move_to(hour_path, GPoint(CENTER_X, CENTER_Y)); gpath_move_to(hour_in_path, GPoint(CENTER_X, CENTER_Y)); min_path = gpath_create(&MIN_POINTS); gpath_move_to(min_path, GPoint(CENTER_X, CENTER_Y)); font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20)); font2 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_28)); time_layer = text_layer_create(GRect(25,146,94,24)); text_layer_set_text_alignment(time_layer, GTextAlignmentCenter); text_layer_set_text_color(time_layer, GColorWhite); text_layer_set_background_color(time_layer, GColorClear); text_layer_set_font(time_layer, font); layer_add_child(window_layer, text_layer_get_layer(time_layer)); date_layer = text_layer_create(GRect(94, 136, 50, 50)); text_layer_set_text_alignment(date_layer, GTextAlignmentRight); text_layer_set_text_color(date_layer, GColorWhite); text_layer_set_background_color(date_layer, GColorClear); text_layer_set_font(date_layer, font2); layer_add_child(window_layer, text_layer_get_layer(date_layer)); day_layer = text_layer_create(GRect(0, 146, 50, 24)); text_layer_set_text_alignment(day_layer, GTextAlignmentLeft); text_layer_set_text_color(day_layer, GColorWhite); text_layer_set_background_color(day_layer, GColorClear); text_layer_set_font(day_layer, font); layer_add_child(window_layer, text_layer_get_layer(day_layer)); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); battery_state_service_subscribe(&handle_battery); handle_battery(battery_state_service_peek()); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); handle_tick(now,1); }
//********************************** 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); }
static void tick_handler(struct tm *t, TimeUnits units_changed){ light_enable(true); handle_battery(battery_state_service_peek()); }
static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) { // Needs to be static because it's used by the system later. static char s_time_text[] = "00:00:00"; static char s_time_element_text[] = "000:000:000"; char s_time_hour_text[4] = "000"; char s_time_minute_text[4] = "000"; char s_time_second_text[4] = "000"; static char s_date_text[] = "0000/00/00"; static char s_date_element_text[] = "000000/000/000"; char s_date_year_text[3] = "00"; char s_date_year2_text[3] = "00"; char s_date_month_text[3] = "00"; char s_date_day_text[3] = "00"; int i_hour = tick_time->tm_hour; int i_min = tick_time->tm_min; int i_sec = tick_time->tm_sec; // 年は 1900 を加算、month は +1 する。 int i_year = (tick_time->tm_year + 1900) / 100; int i_year2 = (tick_time->tm_year + 1900) % 100; int i_month = tick_time->tm_mon + 1; int i_day = tick_time->tm_mday; // 時、分、秒の 0 はそれぞれ 24, 60, 60 として扱う i_hour = (i_hour == 0 ) ? 24 : i_hour; i_min = (i_min == 0 ) ? 60 : i_min; i_sec = (i_sec == 0 ) ? 60 : i_sec; i_year = ( i_year == 0 ) ? 1 : i_year; i_year2 = ( i_year2 == 0 ) ? 1 : i_year2; // 日付を数値で生成する処理 memset(s_date_text, 0, 11); strftime(s_date_text, sizeof(s_date_text), "%F", tick_time); // 日付を元素記号の文字列で生成する処理 strcpy( s_date_year_text, element[i_year] ); strcpy( s_date_year2_text, element[i_year2] ); strcpy( s_date_month_text, element[i_month] ); strcpy( s_date_day_text, element[i_day] ); memset( s_date_element_text, 0, 15 ); strcat( s_date_element_text, s_date_year_text ); strcat( s_date_element_text, s_date_year2_text ); strcat( s_date_element_text, "/" ); strcat( s_date_element_text, s_date_month_text ); strcat( s_date_element_text, "/" ); strcat( s_date_element_text, s_date_day_text ); // 時刻を数値で生成する処理 memset(s_time_text, 0, 8); strftime(s_time_text, sizeof(s_time_text), "%T", tick_time); // 時刻を元素記号の文字列で生成する処理 strcpy( s_time_hour_text, element[i_hour] ); strcpy( s_time_minute_text, element[i_min] ); strcpy( s_time_second_text, element[i_sec] ); memset( s_time_element_text, 0, 11 ); strcat( s_time_element_text, s_time_hour_text ); strcat( s_time_element_text, ":" ); strcat( s_time_element_text, s_time_minute_text ); strcat( s_time_element_text, ":" ); strcat( s_time_element_text, s_time_second_text ); // 日付時刻を所定の領域に表示する。 text_layer_set_text(s_time_layer, s_time_text); text_layer_set_text(s_time_element_layer, s_time_element_text); text_layer_set_text(s_date_layer, s_date_text); text_layer_set_text(s_date_element_layer, s_date_element_text); // バッテリーステータスも更新する。 handle_battery(battery_state_service_peek()); // 0分と30分にはバイブレーションする switch(i_min) { case 60: vibration_control(VIBE_EVERY_HOUR); break; case 30: vibration_control(VIBE_HALF_HOUR); break; } /* テストコード if ( i_min % 2 == 0 ) { vibration_control(VIBE_HALF_HOUR); } else { vibration_control(VIBE_EVERY_HOUR); } */ }