示例#1
0
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
  }
}
示例#2
0
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);
  }*/
}
示例#3
0
static void handle_tick(struct tm *t, TimeUnits units_changed) {
  update_text(t);
  layer_mark_dirty(text_layer_get_layer(s_output_layer));
  if(alarm_has_description(s_alarm))
    layer_mark_dirty(text_layer_get_layer(s_description_layer));
}
示例#4
0
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,topbutton_dismiss?BUTTON_ID_UP:BUTTON_ID_DOWN,gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_CROSS_INV),true);
  action_bar_layer_set_icon_animated(action_bar,topbutton_dismiss?BUTTON_ID_DOWN:BUTTON_ID_UP,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-(is_24h()?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");
  if(alarm_has_description(s_alarm))
  {
    // Create Description
    s_description_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(20,0), PBL_IF_ROUND_ELSE(20,6), bounds.size.w-ACTION_BAR_WIDTH-PBL_IF_ROUND_ELSE(20,0), bounds.size.h/2-10));
    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
  {
#ifndef PBL_PLATFORM_APLITE
    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);
    
#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));
    s_pat.durations = s_segments;
    s_pat.num_segments = 2;

#endif
  }
  s_vibration_pattern = load_persistent_storage_int(VIBRATION_PATTERN_KEY,0);
  s_vibration_duration = load_persistent_storage_int(VIBRATION_DURATION_KEY, 2);
  s_konami_dismiss = load_persistent_storage_bool(KONAMI_DISMISS_KEY,false);

  s_auto_snooze = load_persistent_storage_bool(AUTO_SNOOZE_KEY, true);
  // do smart-alarmy stuff here
#ifdef PBL_HEALTH
  if(s_alarm->smart_alarm_minutes>0)
  {
    // Attempt to subscribe
    if(!health_service_events_subscribe(health_handler, NULL)) {
      APP_LOG(APP_LOG_LEVEL_ERROR, "Health not available!");
      start_vibration(NULL);
    }
    else {
      // Check which activities are available
      HealthServiceAccessibilityMask activity_mask = health_service_any_activity_accessible(HealthActivityMaskAll,time(NULL)-SECONDS_PER_HOUR,time(NULL));
      
      if(activity_mask & HealthServiceAccessibilityMaskAvailable){
        APP_LOG(APP_LOG_LEVEL_INFO, "We can read activities!");
        // Get an activities mask
        HealthActivityMask activities = health_service_peek_current_activities();
        
        // Determine if the user is sleeping
        if(activities & HealthActivitySleep) { // give him time to wake
          APP_LOG(APP_LOG_LEVEL_INFO, "User is sleeping!");
          s_start_smart_alarm_timer = app_timer_register(1000*60*s_alarm->smart_alarm_minutes,start_vibration,NULL);
        } else { // just vibrate
          start_vibration(NULL);
        }
      }
      else { // we don't get the current activity, so just vibrate
        start_vibration(NULL);
      }
    }
  }
  else {
    start_vibration(NULL);
  }
  
#else
  start_vibration(NULL);
#endif
  // test snoozing with the accelerometer
  /*if(s_flip_to_snooze)
  {
    accel_tap_service_subscribe(&accel_tap_handler);
  }*/
}