static void toggleorienttoheading(ClickRecognizerRef recognizer, void *context) { if (hint_layer) { text_layer_destroy(hint_layer); hint_layer = NULL; } else { orientToHeading = !orientToHeading; if (orientToHeading) { compass_service_unsubscribe(); text_layer_set_text(direction_layer, "---"); if (heading >= 0) { text_layer_set_text(star_layer, "^"); orientation = -TRIG_MAX_ANGLE * heading / 360; draw_compass_face(); } else text_layer_set_text(star_layer, "?"); } else { compass_service_subscribe(&compass_direction_handler); text_layer_set_text(direction_layer, "!!!"); if (heading >= 0) { text_layer_set_text(star_layer, "*"); } else text_layer_set_text(star_layer, ""); } } }
void init_compass_service(Window * watchface) { if (is_module_enabled(MODULE_COMPASS)) { compass_service_subscribe((CompassHeadingHandler)compass_handler); compass_service_set_heading_filter(TRIG_MAX_ANGLE/64); } else { compass_service_unsubscribe(); } }
static void init () { 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); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); compass_service_set_heading_filter(10); compass_service_subscribe(&compass_handler); main_window = window_create(); window_set_window_handlers(main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload });
void handle_init(void) { my_window = window_create(); text_layer = text_layer_create(GRect(0, 70, 144, 20)); text_layer_set_text(text_layer, "Your Location"); text_layer_set_text_alignment(text_layer, GAlignBottom); Layer *windowLayer = window_get_root_layer(my_window); layer_add_child(windowLayer, text_layer_get_layer(text_layer)); window_set_background_color(my_window, GColorBlack); window_stack_push(my_window, true); compass_service_subscribe(compass_handler); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); app_message_open(inbox_size, outbox_size); compass_service_subscribe(compass_heading_handler); // We do this to account for the offset due to the status bar // at the top of the app window. GRect layer_frame_description = layer_get_frame(window_layer); layer_frame_description.origin.x = 0; layer_frame_description.origin.y = 0; // Add some background content to help demonstrate transparency. s_text_layer = text_layer_create(layer_frame_description); text_layer_set_text(s_text_layer, "Point towards\nthe device"); layer_add_child(window_layer, text_layer_get_layer(s_text_layer)); s_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_POINT); GPoint center = grect_center_point(&bounds); GSize image_size = gbitmap_get_bounds(s_bitmap).size; GRect image_frame = GRect(center.x, center.y, image_size.w, image_size.h); image_frame.origin.x -= image_size.w / 2; image_frame.origin.y -= image_size.h / 2 - 30; // Use GCompOpOr to display the white portions of the image s_layer = bitmap_layer_create(image_frame); bitmap_layer_set_bitmap(s_layer, s_bitmap); bitmap_layer_set_compositing_mode(s_layer, GCompOpSet); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21)); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, bitmap_layer_get_layer(s_layer)); }
static void main_window_load(Window *window) { // Set click config handler window_set_click_config_provider(s_spin_window, (ClickConfigProvider) start_spin_click_config_provider); // Window layer properties Layer *window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); // Points s_center = grect_center_point(&window_bounds); s_spin_circle_center = GPoint(s_center.x, s_center.y + 10); // Rects s_welcome_rect = GRect(112, s_center.y, 10, 10); // Welcome arrow s_welcome_arrow_path = gpath_create(&SPIN_ARROW_PATH_INFO); gpath_move_to(s_welcome_arrow_path, GPoint(120, s_center.y + 15)); s_welcome_canvas_layer = layer_create(window_bounds); layer_set_update_proc(s_welcome_canvas_layer, update_welcome_proc); layer_add_child(window_layer, s_welcome_canvas_layer); // Welcome text layer s_welcome_text_layer = text_layer_create(GRect(10, s_center.y - 12, 144, 50)); text_layer_set_text(s_welcome_text_layer, "Press and hold"); text_layer_set_background_color(s_welcome_text_layer, GColorClear); text_layer_set_text_color(s_welcome_text_layer, GColorWhite); text_layer_set_font(s_welcome_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); layer_add_child(window_layer, text_layer_get_layer(s_welcome_text_layer)); // Spin circle Layer s_spin_circle_canvas_layer = layer_create(window_bounds); layer_set_update_proc(s_spin_circle_canvas_layer, update_spin_circle_proc); layer_add_child(window_layer, s_spin_circle_canvas_layer); // Spin triangle / arrow Layer s_spin_arrow_path = gpath_create(&SPIN_ARROW_PATH_INFO); s_spin_triangle_path = gpath_create(&BOLT_PATH_INFO); gpath_move_to(s_spin_triangle_path, s_spin_circle_center); s_spin_triangle_canvas_layer = layer_create(window_bounds); layer_set_update_proc(s_spin_triangle_canvas_layer, update_triangle_proc); layer_add_child(window_layer, s_spin_triangle_canvas_layer); // Spin heading TextLayer s_spin_heading_text_layer = text_layer_create(GRect(0, 5, 144, 50)); text_layer_set_text(s_spin_heading_text_layer, "To turn off alarm"); text_layer_set_background_color(s_spin_heading_text_layer, GColorClear); text_layer_set_text_color(s_spin_heading_text_layer, GColorWhite); text_layer_set_font(s_spin_heading_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_spin_heading_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_spin_heading_text_layer)); // Spin top text TextLayer s_spin_top_text_layer = text_layer_create(GRect(0, s_spin_circle_center.y - 30, 144, 50)); text_layer_set_text(s_spin_top_text_layer, "Spin Around"); text_layer_set_background_color(s_spin_top_text_layer, GColorClear); text_layer_set_text_color(s_spin_top_text_layer, GColorWhite); text_layer_set_font(s_spin_top_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_spin_top_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_spin_top_text_layer)); // Spin spins TextLayer s_spin_spins_text_layer = text_layer_create(GRect(0, s_spin_circle_center.y - 14, 144, 50)); text_layer_set_text(s_spin_spins_text_layer, "2"); text_layer_set_background_color(s_spin_spins_text_layer, GColorClear); text_layer_set_text_color(s_spin_spins_text_layer, GColorWhite); text_layer_set_font(s_spin_spins_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); text_layer_set_text_alignment(s_spin_spins_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_spin_spins_text_layer)); // Spin bottom text TextLayer s_spin_bottom_text_layer = text_layer_create(GRect(0, s_spin_circle_center.y + 34 - 14, 144, 50)); text_layer_set_text(s_spin_bottom_text_layer, "Times!"); text_layer_set_background_color(s_spin_bottom_text_layer, GColorClear); text_layer_set_text_color(s_spin_bottom_text_layer, GColorWhite); text_layer_set_font(s_spin_bottom_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_spin_bottom_text_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_spin_bottom_text_layer)); // Spin time TextLayer s_spin_time_layer = text_layer_create(GRect(0, s_spin_circle_center.y + 38, 144, 50)); text_layer_set_background_color(s_spin_time_layer, GColorClear); text_layer_set_text_color(s_spin_time_layer, GColorWhite); text_layer_set_font(s_spin_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text_alignment(s_spin_time_layer, GTextAlignmentCenter); // layer_add_child(window_layer, text_layer_get_layer(s_spin_time_layer)); // Register with TickTimerService tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); // Subscribe to the compass data service when angle changes by 5 degrees compass_service_subscribe(compass_handler); compass_service_set_heading_filter(5); // Make sure the time is displayed from the start update_time(); // TODO: remove this set_alarm_on(true); }