Example #1
0
Timer* timers_find_wakeup_collision(Timer* timer) {
  time_t wakeup_time;
  wakeup_query(timer->wakeup_id, &wakeup_time);
  uint8_t count = timers_count();
  for (uint8_t c = 0; c < count; c += 1) {
    Timer* timer_to_check = timers_get(c);
    if (timer_to_check->wakeup_id < 0) {
      continue;
    }
    if (timer_to_check->id == timer->id) {
      continue;
    }
    time_t check_time;
    wakeup_query(timer_to_check->wakeup_id, &check_time);
    if (abs(check_time - wakeup_time) <= 60) {
      return timer_to_check;
    }
  }
  return NULL;
}
Example #2
0
static void count_timer_handler(void *data) {
  if(s_is_running) {
    if (s_wakeup_timestamp == 0) {
      // get the wakeup timestamp for showing a countdown
      wakeup_query(s_wakeup_id, &s_wakeup_timestamp);
    }
  
    int countdown = s_wakeup_timestamp - time(NULL);
    static char s_left_time_buf[16];
    snprintf(s_left_time_buf, sizeof(s_left_time_buf), "%02d:%02d", countdown/60, countdown%60);
    text_layer_set_text(s_left_time_label, s_left_time_buf);
  }
  layer_mark_dirty(text_layer_get_layer(s_left_time_label));
  app_timer_register(1000, count_timer_handler, data);
}