Exemplo n.º 1
0
void timers_save(void) {
  if (timers_count() == 0) {
    persist_delete(PERSIST_TIMER_START);
    return;
  }
  TimerBlock* block = NULL;
  uint8_t block_count = 0;
  for (uint8_t b = 0; b < timers_count(); b += 1) {
    if (NULL == block) {
      block = malloc(sizeof(TimerBlock));
      block->total_timers = timers_count();
      block->save_time = time(NULL);
    }

    uint8_t timer_block_pos = b % TIMER_BLOCK_SIZE;
    block->timers[timer_block_pos] = *timers_get(b);

    bool is_last_timer_in_block = timer_block_pos == (TIMER_BLOCK_SIZE - 1);
    if (is_last_timer_in_block) {
      persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock));
      block_count += 1;
      free(block);
      block = NULL;
    }
  }
  if (block) {
    persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock));
  }
  persist_write_int(PERSIST_TIMERS_VERSION, TIMERS_VERSION_CURRENT);
}
Exemplo n.º 2
0
void storage_store(){
	APP_LOG(APP_LOG_LEVEL_INFO,"storage_store()");
	APP_LOG(APP_LOG_LEVEL_INFO,"max_cell_size: %d timer_size: %d laps_size: %d clock_size: %d",PERSIST_DATA_MAX_LENGTH,sizeof(Timer),sizeof(Laps),sizeof(Clock));
	
	int result;
	uint8_t c=timers_count();
	
	result=persist_write_int(STORAGE_KEY_VERSION,STORAGE_VERSION);
	if(result<0){
		APP_LOG(APP_LOG_LEVEL_ERROR,"write error count %d in storage %d #%d",c,STORAGE_KEY_COUNT,result);  
		return;
	}
	
	result=persist_write_int(STORAGE_KEY_COUNT,c);
	if(result<0){
		APP_LOG(APP_LOG_LEVEL_ERROR,"write error count %d in storage %d #%d",count_total(count),STORAGE_KEY_COUNT,result); 
		return;
	}
	APP_LOG(APP_LOG_LEVEL_INFO,"timer count %d",count_total(count));
	
	Timer* timer;
	for(uint8_t i=0;i<c;i++){
		timer=timers_get(i);
		result=persist_write_data(STORAGE_KEY_DATA+i,timer,sizeof(Timer));
		if(result<0){
			APP_LOG(APP_LOG_LEVEL_ERROR,"write error timer %d in storage %d #%d",i,STORAGE_KEY_DATA+i,result); 
			continue;
		}
		APP_LOG(APP_LOG_LEVEL_INFO,"stored timer %d",i);
	}
	APP_LOG(APP_LOG_LEVEL_INFO,"stored");
}
Exemplo n.º 3
0
void handleAlarm(void* data){
	APP_LOG(APP_LOG_LEVEL_INFO,"timer finished");
	for(uint8_t i=timers_stopwatch_count();i<timers_count();i++){
		timer_checkEnd(timers_get(i));
	}
	window_alarm_show();
	timers_updateNearest();
}
Exemplo n.º 4
0
int16_t timers_index_of(uint16_t id) {
  uint8_t count = timers_count();
  for (uint8_t c = 0; c < count; c += 1) {
    Timer* timer = timers_get(c);
    if (timer->id == id) {
      return c;
    }
  }
  return -1;
}
Exemplo n.º 5
0
Timer* timers_find(uint16_t id) {
  uint8_t count = timers_count();
  for (uint8_t c = 0; c < count; c += 1) {
    Timer* timer = timers_get(c);
    if (timer->id == id) {
      return timer;
    }
  }
  return NULL;
}
Exemplo n.º 6
0
Arquivo: io.c Projeto: yubo/bird
void
tm2_set(struct timer2 *t, btime when)
{
  struct birdloop *loop = birdloop_current();
  uint tc = timers_count(loop);

  if (!t->expires)
  {
    t->index = ++tc;
    t->expires = when;
    BUFFER_PUSH(loop->timers) = t;
    HEAP_INSERT(loop->timers.data, tc, struct timer2 *, TIMER_LESS, TIMER_SWAP);
  }
Exemplo n.º 7
0
Timer* timers_find_last_wakeup(void) {
  Timer* last = NULL;
  uint16_t last_wakeup_time = 0;
  uint8_t count = timers_count();
  for (uint8_t c = 0; c < count; c += 1) {
    Timer* timer = timers_get(c);
    if (timer->wakeup_id < 0) {
      continue;
    }
    if (timer->current_time > last_wakeup_time) {
      last = timer;
      last_wakeup_time = timer->current_time;
    }
  }
  return last;
}
Exemplo n.º 8
0
void timers_remove(uint8_t pos) {
	if(selected==pos){
		selected=-1;
	}
	if(selected>pos){
		selected--;
	}
	if(timer_getDirection(timers[pos])==TIMER_DIRECTION_UP){
		count->stopwatch--;
	}else{
		count->timer--;
	}
	timer_destroy(timers[pos]);
	for(uint8_t i=pos;i<timers_count();i++){
		timers[i]=timers[i+1];
	}
	timers_updateNearest();
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
void timers_updateNearest(){
	uint8_t min=0;
	Clock* minc=NULL;
	for(uint8_t i=timers_stopwatch_count();i<timers_count();i++){
		Timer* t=timers_get(i);
		Clock* c=timer_getNextFinish(t);
		if(c==NULL){
			continue;
		}
		if(minc==NULL||clock_compare(minc,c)>0){
			clock_destroy(minc);
			minc=c;
			min=i;
		}else{
			clock_destroy(c);
		}
	}
	nearest=min;
	scheduler_update(minc);
}
Exemplo n.º 11
0
bool timers_isSpace() {
	return timers_count()<TIMERS_MAX_COUNT;
}
Exemplo n.º 12
0
Timer* timers_add_timer() {
	if(timers_count()>=TIMERS_MAX_COUNT){
		return NULL;
	}
	return timers_select(timers_add(timer_create_timer()));
}