void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; // Need to be static because they're used by the system later. static char time_text[] = "00:00"; char *time_format; if (clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } string_format_time(time_text, sizeof(time_text), time_format, t->tick_time); 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); text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter); rotbmp_pair_layer_set_angle(&bitmap_hour_container.layer, TRIG_MAX_ANGLE * get24HourAngle(t->tick_time->tm_hour, t->tick_time->tm_min)); bitmap_hour_container.layer.layer.frame.origin.x = (144/2) - (bitmap_hour_container.layer.layer.frame.size.w/2); bitmap_hour_container.layer.layer.frame.origin.y = (168/2) - (bitmap_hour_container.layer.layer.frame.size.h/2); updateDayAndNightInfo(); }
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; // Need to be static because they're used by the system later. static char time_text[] = "00:00"; static char dom_text[] = "00"; string_format_time(dom_text, sizeof(dom_text), "%e", t->tick_time); static char dow_text[] = "xxx"; string_format_time(dow_text, sizeof(dow_text), "%a", t->tick_time); static char yon_text[] = "00"; string_format_time(yon_text, sizeof(yon_text), "%y", t->tick_time); static char mon_text[] = "xxx"; string_format_time(mon_text, sizeof(mon_text), "%b", t->tick_time); char *time_format; if (clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } string_format_time(time_text, sizeof(time_text), time_format, t->tick_time); if (!clock_is_24h_style() && (time_text[0] == '0')) { memmove(time_text, &time_text[1], sizeof(time_text) - 1); } text_layer_set_text(&dow_layer, dow_text); text_layer_set_text(&dom_layer, dom_text); text_layer_set_text(&yon_layer, yon_text); text_layer_set_text(&mon_layer, mon_text); text_layer_set_text(&text_time_layer, time_text); text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter); rotbmp_pair_layer_set_angle(&bitmap_container.layer, TRIG_MAX_ANGLE * get24HourAngle(t->tick_time->tm_hour, t->tick_time->tm_min)); bitmap_container.layer.layer.frame.origin.x = (144/2) - (bitmap_container.layer.layer.frame.size.w/2); bitmap_container.layer.layer.frame.origin.y = (168/2) - (bitmap_container.layer.layer.frame.size.h/2); // Vibrate Every Hour #if HOUR_VIBRATION if ((t->tick_time->tm_min==0) && (t->tick_time->tm_sec==0)) { vibes_enqueue_custom_pattern(hour_pattern); } #endif updateDayAndNightInfo(false); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "SunClock"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorWhite); resource_init_current_app(&APP_RESOURCES); fontBig = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SUNCLOCK_30)); fontSmall = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SUNCLOCK_16)); fontMoonPhases = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MOON_PHASES_30)); layer_init(&graphics_sun_layer, window.layer.frame); graphics_sun_layer.update_proc = &graphics_sun_layer_update_callback; layer_add_child(&window.layer, &graphics_sun_layer); rotbmp_pair_init_container(RESOURCE_ID_IMAGE_WATCHFACE_WHITE, RESOURCE_ID_IMAGE_WATCHFACE_BLACK, &watchface_container); layer_add_child(&graphics_sun_layer, &watchface_container.layer.layer); watchface_container.layer.layer.frame.origin.x = (144/2) - (watchface_container.layer.layer.frame.size.w/2); watchface_container.layer.layer.frame.origin.y = (168/2) - (watchface_container.layer.layer.frame.size.h/2); rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_WHITE, RESOURCE_ID_IMAGE_HOUR_BLACK, &bitmap_hour_container); rotbmp_pair_layer_set_src_ic(&bitmap_hour_container.layer, GPoint(6,56)); layer_add_child(&window.layer, &bitmap_hour_container.layer.layer); PblTm t; get_time(&t); rotbmp_pair_layer_set_angle(&bitmap_hour_container.layer, TRIG_MAX_ANGLE * get24HourAngle(t.tm_hour, t.tm_min)); bitmap_hour_container.layer.layer.frame.origin.x = (144/2) - (bitmap_hour_container.layer.layer.frame.size.w/2); bitmap_hour_container.layer.layer.frame.origin.y = (168/2) - (bitmap_hour_container.layer.layer.frame.size.h/2); text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorBlack); text_layer_set_background_color(&text_time_layer, GColorClear); layer_set_frame(&text_time_layer.layer, GRect(0, 35, 144, 30)); text_layer_set_font(&text_time_layer, fontBig); layer_add_child(&window.layer, &text_time_layer.layer); text_layer_init(&text_sunrise_layer, window.layer.frame); text_layer_set_text_color(&text_sunrise_layer, GColorWhite); text_layer_set_background_color(&text_sunrise_layer, GColorClear); layer_set_frame(&text_sunrise_layer.layer, GRect(0, 150, 144, 18)); text_layer_set_font(&text_sunrise_layer, fontSmall); layer_add_child(&window.layer, &text_sunrise_layer.layer); text_layer_init(&text_sunset_layer, window.layer.frame); text_layer_set_text_color(&text_sunset_layer, GColorWhite); text_layer_set_background_color(&text_sunset_layer, GColorClear); layer_set_frame(&text_sunset_layer.layer, GRect(0, 150, 144, 18)); text_layer_set_font(&text_sunset_layer, fontSmall); layer_add_child(&window.layer, &text_sunset_layer.layer); updateDayAndNightInfo(); }
void handle_init(AppContextRef ctx) { (void)ctx; window_init(&window, "KP Sun-Moon-Clock"); window_stack_push(&window, true /* Animated */); window_set_background_color(&window, GColorWhite); resource_init_current_app(&APP_RESOURCES); font_moon = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MOON_PHASES_SUBSET_30)); layer_init(&graphics_sun_layer, window.layer.frame); graphics_sun_layer.update_proc = &graphics_sun_layer_update_callback; layer_add_child(&window.layer, &graphics_sun_layer); rotbmp_pair_init_container(RESOURCE_ID_IMAGE_WATCHFACE_WHITE, RESOURCE_ID_IMAGE_WATCHFACE_BLACK, &watchface_container); layer_add_child(&graphics_sun_layer, &watchface_container.layer.layer); rotbmp_pair_layer_set_angle(&watchface_container.layer, 1); watchface_container.layer.layer.frame.origin.x = (144/2) - (watchface_container.layer.layer.frame.size.w/2); watchface_container.layer.layer.frame.origin.y = (168/2) - (watchface_container.layer.layer.frame.size.h/2); text_layer_init(&text_time_layer, window.layer.frame); text_layer_set_text_color(&text_time_layer, GColorBlack); text_layer_set_background_color(&text_time_layer, GColorClear); layer_set_frame(&text_time_layer.layer, GRect(0, 35, 144, 30)); text_layer_set_font(&text_time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_30))); layer_add_child(&window.layer, &text_time_layer.layer); rotbmp_pair_init_container(RESOURCE_ID_IMAGE_HOUR_WHITE, RESOURCE_ID_IMAGE_HOUR_BLACK, &bitmap_container); rotbmp_pair_layer_set_src_ic(&bitmap_container.layer, GPoint(9,56)); layer_add_child(&window.layer, &bitmap_container.layer.layer); text_layer_init(&moonLayer, GRect(0, 100, 144 /* width */, 168-115 /* height */)); text_layer_set_text_color(&moonLayer, GColorWhite); text_layer_set_background_color(&moonLayer, GColorClear); text_layer_set_font(&moonLayer, font_moon); text_layer_set_text_alignment(&moonLayer, GTextAlignmentCenter); handle_day(ctx, NULL); layer_add_child(&window.layer, &moonLayer.layer); PblTm t; get_time(&t); rotbmp_pair_layer_set_angle(&bitmap_container.layer, TRIG_MAX_ANGLE * get24HourAngle(t.tm_hour, t.tm_min)); bitmap_container.layer.layer.frame.origin.x = (144/2) - (bitmap_container.layer.layer.frame.size.w/2); bitmap_container.layer.layer.frame.origin.y = (168/2) - (bitmap_container.layer.layer.frame.size.h/2); //Day of Week text text_layer_init(&dow_layer, GRect(0, 0, 144, 127+26)); text_layer_set_text_color(&dow_layer, GColorWhite); text_layer_set_background_color(&dow_layer, GColorClear); text_layer_set_font(&dow_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text_alignment(&dow_layer, GTextAlignmentLeft); text_layer_set_text(&dow_layer, "xxx"); layer_add_child(&window.layer, &dow_layer.layer); //Day of the Month text text_layer_init(&dom_layer, GRect(0, 10, 144, 137+26)); text_layer_set_text_color(&dom_layer, GColorWhite); text_layer_set_background_color(&dom_layer, GColorClear); text_layer_set_font(&dom_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(&dom_layer, GTextAlignmentLeft); text_layer_set_text(&dom_layer, "00"); layer_add_child(&window.layer, &dom_layer.layer); //Month Text text_layer_init(&mon_layer, GRect(0, 0, 144, 127+26)); text_layer_set_text_color(&mon_layer, GColorWhite); text_layer_set_background_color(&mon_layer, GColorClear); text_layer_set_font(&mon_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text_alignment(&mon_layer, GTextAlignmentRight); text_layer_set_text(&mon_layer, "xxx"); layer_add_child(&window.layer, &mon_layer.layer); //Year Number text text_layer_init(&yon_layer, GRect(0, 10, 144, 137+26)); text_layer_set_text_color(&yon_layer, GColorWhite); text_layer_set_background_color(&yon_layer, GColorClear); text_layer_set_font(&yon_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_text_alignment(&yon_layer, GTextAlignmentRight); text_layer_set_text(&yon_layer, "00"); layer_add_child(&window.layer, &yon_layer.layer); //Sunrise Text text_layer_init(&text_sunrise_layer, window.layer.frame); text_layer_set_text_color(&text_sunrise_layer, GColorWhite); text_layer_set_background_color(&text_sunrise_layer, GColorClear); layer_set_frame(&text_sunrise_layer.layer, GRect(0, 145, 144, 30)); text_layer_set_font(&text_sunrise_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); layer_add_child(&window.layer, &text_sunrise_layer.layer); //Sunset Text text_layer_init(&text_sunset_layer, window.layer.frame); text_layer_set_text_color(&text_sunset_layer, GColorWhite); text_layer_set_background_color(&text_sunset_layer, GColorClear); layer_set_frame(&text_sunset_layer.layer, GRect(0, 145, 144, 30)); text_layer_set_font(&text_sunset_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); layer_add_child(&window.layer, &text_sunset_layer.layer); http_set_app_id(55122370); http_register_callbacks((HTTPCallbacks){ .time=have_time, .location=have_location }, (void*)ctx);