void start_vibration(void *data) { if(!already_running) { already_running=true; do_vibrate(); // switch off vibration after x minutes switch (s_vibration_duration) { case 0: s_vibration_duration = 30; break; case 1: s_vibration_duration = 60; break; case 2: s_vibration_duration = 120; break; case 3: s_vibration_duration = 300; break; case 4: s_vibration_duration = 2; break; case 5: s_vibration_duration = 10; break; default: break; } cancel_vibe_timer = app_timer_register(1000*s_vibration_duration,cancel_vibe_timer_callback,NULL); #ifndef PBL_PLATFORM_APLITE if(!alarm_has_description(s_alarm)) app_timer_register(33, next_frame_handler, NULL); #endif } }
void vibe_timer_callback(void* data) { if(!cancel_vibrate) do_vibrate(); }
static void main_window_load(Window *window) { GRect bounds = layer_get_bounds(window_get_root_layer(window)); action_bar = action_bar_layer_create(); action_bar_layer_set_click_config_provider(action_bar, click_config_provider); #ifdef PBL_COLOR action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_UP,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS_INV),true); action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_ZZ_INV),true); #else action_bar_layer_set_icon(action_bar,BUTTON_ID_UP,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS)); action_bar_layer_set_icon(action_bar,BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_ZZ)); #endif action_bar_layer_add_to_window(action_bar,window); // Create output TextLayer s_output_layer = text_layer_create(GRect(0, bounds.size.h/2-21-(clock_is_24h_style()?0:21), bounds.size.w-ACTION_BAR_WIDTH, bounds.size.h)); text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter); text_layer_set_font(s_output_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); //snprintf(output_text, sizeof(output_text), "00:00"); text_layer_set_text(s_output_layer, output_text); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_output_layer)); //snprintf(output_text, sizeof(output_text), "00:00"); if(alarm_has_description(s_alarm)) { // Create Description s_description_layer = text_layer_create(GRect(0, 6, bounds.size.w-ACTION_BAR_WIDTH, 36)); text_layer_set_text_alignment(s_description_layer, GTextAlignmentCenter); text_layer_set_font(s_description_layer,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(s_description_layer, s_alarm->description); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_description_layer)); } else { // Create Bitmap s_bitmap_layer = bitmap_layer_create(GRect(0,10,bounds.size.w-ACTION_BAR_WIDTH, bounds.size.h)); s_logo = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO); bitmap_layer_set_bitmap(s_bitmap_layer,s_logo); bitmap_layer_set_alignment(s_bitmap_layer,GAlignTop); layer_add_child(window_get_root_layer(window),bitmap_layer_get_layer(s_bitmap_layer)); } #ifdef PBL_SDK_2 s_inverter_layer = inverter_layer_create(GRect(0,0,bounds.size.w,bounds.size.h)); layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(s_inverter_layer)); #endif s_vibration_pattern = load_persistent_storage_int(VIBRATION_PATTERN_KEY,0); s_vibration_duration = load_persistent_storage_int(VIBRATION_DURATION_KEY, 2); s_auto_snooze = load_persistent_storage_bool(AUTO_SNOOZE_KEY, true); do_vibrate(); // switch off vibration after x minutes switch (s_vibration_duration) { case 0: s_vibration_duration = 30; break; case 1: s_vibration_duration = 60; break; case 2: s_vibration_duration = 120; break; case 3: s_vibration_duration = 300; break; default: break; } cancel_vibe_timer = app_timer_register(1000*s_vibration_duration,cancel_vibe_timer_callback,NULL); // test snoozing with the accelerometer /*if(s_flip_to_snooze) { accel_tap_service_subscribe(&accel_tap_handler); }*/ }
static void main_window_load(Window *window) { GRect bounds = layer_get_bounds(window_get_root_layer(window)); action_bar = action_bar_layer_create(); action_bar_layer_set_click_config_provider(action_bar, click_config_provider); //bool topbutton_dismiss = load_persistent_storage_bool(TOP_BUTTON_DISMISS_KEY, true); action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_UP,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS_INV),true); action_bar_layer_set_icon_animated(action_bar,BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_ZZ_INV),true); action_bar_layer_add_to_window(action_bar,window); // Create output TextLayer s_output_layer = text_layer_create(GRect(0, bounds.size.h/2-(clock_is_24h_style()?0:4), bounds.size.w-ACTION_BAR_WIDTH, bounds.size.h)); text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter); text_layer_set_font(s_output_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT)); //snprintf(output_text, sizeof(output_text), "00:00"); text_layer_set_text(s_output_layer, output_text); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_output_layer)); //snprintf(output_text, sizeof(output_text), "00:00"); s_command_seq = gdraw_command_sequence_create_with_resource(RESOURCE_ID_CLOCK_SEQUENCE); // Create the canvas Layer s_canvas_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(60,30)-ACTION_BAR_WIDTH/2, 0, bounds.size.w, bounds.size.h)); // Set the LayerUpdateProc layer_set_update_proc(s_canvas_layer, update_proc); // Add to parent Window layer_add_child(window_get_root_layer(window), s_canvas_layer); app_timer_register(33, next_frame_handler, NULL); time_t now = time(NULL); struct tm *t = localtime(&now); update_text(t); s_vibration_pattern = 0; //s_vibration_pattern = load_persistent_storage_int(VIBRATION_PATTERN_KEY,0); //s_vibration_duration = load_persistent_storage_int(VIBRATION_DURATION_KEY, 2); s_vibration_duration = CONF_VIBRATION_DURATION; //s_auto_snooze = load_persistent_storage_bool(AUTO_SNOOZE_KEY, true); do_vibrate(); // switch off vibration after x minutes /*switch (s_vibration_duration) { case 0: s_vibration_duration = 30; break; case 1: s_vibration_duration = 60; break; case 2: s_vibration_duration = 120; break; case 3: s_vibration_duration = 300; break; case 4: s_vibration_duration = 2; break; case 5: s_vibration_duration = 10; break; default: break; }*/ cancel_vibe_timer = app_timer_register(1000*s_vibration_duration,cancel_vibe_timer_callback,NULL); // test snoozing with the accelerometer /*if(s_flip_to_snooze) { accel_tap_service_subscribe(&accel_tap_handler); }*/ }