コード例 #1
0
ファイル: wakeup.c プロジェクト: clach04/alarmsplusplus
static void do_snooze(void)
{
  *s_snooze=true;
  int snooze_delay;
  snooze_delay = load_persistent_storage_int(SNOOZE_KEY,10);
  time_t timestamp = time(NULL) + 60*snooze_delay;
  s_alarm->alarm_id = wakeup_schedule(timestamp,0,true);
  struct tm *t = localtime(&timestamp);
  APP_LOG(APP_LOG_LEVEL_DEBUG,"Scheduled snooze at %d.%d %d:%d",t->tm_mday, t->tm_mon+1,t->tm_hour,t->tm_min);
  window_stack_pop(true);
}
コード例 #2
0
  }
}

void win_main_init(Alarm* alarms) {
  s_alarms = alarms;
  s_window = window_create();
  window_set_window_handlers(s_window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
    .appear = window_appear
  });
  win_edit_init();
  //win_snooze_init();
  //win_about_init();
  win_advanced_init();
  s_snooze_delay = load_persistent_storage_int(SNOOZE_KEY,10);
  update_id_enabled();
  refresh_timeout();
  s_show_remaining=false;
  refresh_next_alarm_text();
  snprintf(version_text, sizeof(version_text), "Alarms++ v%d.%d",__pbl_app_info.process_version.major,__pbl_app_info.process_version.minor);
  s_scroll_timer = app_timer_register(500,scroll_timer_callback,NULL);
#ifndef PBL_PLATFORM_APLITE
  s_logo_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON);
  s_logo_inv_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_INV_ICON);
#endif
  init_action_menu();
  char *sys_locale = setlocale(LC_ALL, "");
  if (strcmp("de_DE", sys_locale) == 0) {
    weekday_names = german;
  } else if (strcmp("fr_FR", sys_locale) == 0) {
コード例 #3
0
#ifdef PBL_HEALTH
static int s_smart_alarm;
#endif

static int16_t s_scroll_index;
static int16_t s_scroll_row_index;
static AppTimer *s_scroll_timer;

void win_advanced_init(void) {
  s_window = window_create();
  window_set_window_handlers(s_window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
    .appear = window_appear
  });
  s_konami_dismiss = load_persistent_storage_int(KONAMI_DISMISS_KEY,0);
  APP_LOG(APP_LOG_LEVEL_DEBUG,"key: %d",s_konami_dismiss);
  s_vibration_pattern = load_persistent_storage_int(VIBRATION_PATTERN_KEY,0);
  //s_flip_to_snooze = load_persistent_storage_bool(FLIP_TO_SNOOZE_KEY, false);
  s_vibration_duration = load_persistent_storage_int(VIBRATION_DURATION_KEY,2);
  s_auto_snooze = load_persistent_storage_bool(AUTO_SNOOZE_KEY,true);
  s_dismiss_top = load_persistent_storage_bool(TOP_BUTTON_DISMISS_KEY,true);
#ifdef PBL_HEALTH
  s_smart_alarm = load_persistent_storage_int(SMART_ALARM_KEY,0);
#endif
  //s_background_tracking = load_persistent_storage_bool(BACKGROUND_TRACKING_KEY,false);
  refresh_timeout();
  s_scroll_timer = app_timer_register(500,scroll_timer_callback,NULL);
}

void win_advanced_show(void) {
コード例 #4
0
ファイル: wakeup.c プロジェクト: clach04/alarmsplusplus
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);
  }*/
}
コード例 #5
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);
  }*/
}