void timer_task() { int i; for (i = 0; i < timer_ref_idx; i++) { timer_handle(timer_ref[i]); } }
static inline Handle<Timer> create(int clock, bool non_block = true) { int flag = non_block ? (TFD_NONBLOCK | TFD_CLOEXEC) : TFD_CLOEXEC; Handle<Timer> timer_handle(::timerfd_create(clock, flag)); if (!timer_handle) throw std::system_error(util::errc(), "ops::Timer::create"); return std::move(timer_handle); }
static gboolean my_timer_handle(GSource* source) { SHOW_CHECKPOINT; timer_handle (); timers_count--; addTimeout(); return FALSE; }
void module_wait_pipes_input (void (*as_msg_handler) (send_data_type type, send_data_type * body)) { fd_set in_fdset, out_fdset; int retval; struct timeval tv; struct timeval *t = NULL; int max_fd = 0; ASMessage msg; int as_fd = get_module_in_fd (); FD_ZERO (&in_fdset); FD_ZERO (&out_fdset); FD_SET (x_fd, &in_fdset); max_fd = x_fd; if (as_fd >= 0) { FD_SET (as_fd, &in_fdset); if (max_fd < as_fd) max_fd = as_fd; } if (timer_delay_till_next_alarm ((time_t *) & tv.tv_sec, (time_t *) & tv.tv_usec)) t = &tv; retval = PORTABLE_SELECT (min (max_fd + 1, fd_width), &in_fdset, &out_fdset, NULL, t); if (retval > 0) { /* check for incoming module connections */ if (as_fd >= 0) if (FD_ISSET (as_fd, &in_fdset)) if (ReadASPacket (as_fd, msg.header, &(msg.body)) > 0) { as_msg_handler (msg.header[1], msg.body); free (msg.body); } } /* handle timeout events */ timer_handle (); }
int main(void) { Initialize(); timer_start(TIMER_TEMP, TIMER_TEMP_DELAY); timer_start(TIMER_LCD, TIMER_LCD_DELAY); timer_start(TIMER_TURN90, TIMER_TURN90_DELAY); timer_start(TIMER_RECULE, TIMER_RECULE_DELAY); /* u08 tempmic; while (!GetMicValLuca(LEVELMIC, &tempmic)) { snprintf(str_l1, LCD_SIZE, "%02x - %02x", tempmic, LEVELMIC); }*/ int nb_s = 0; while (1) { timer_handle(); //Check switches if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_STARTSTOP)) { while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_STARTSTOP)); if (!enable) { enable = 1; } else { enable = 0; } } if (enable) { if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_MODESEL)) { while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_MODESEL)); mode++; mode %= 3; } } if (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_VAL)) { while (TactSWModuleCtrl(BUTTON_SLOT, BUTTON_VAL)); val_buttons++; val_buttons %= MAX_SPEED; } if (enable) { switch (mode) { case MODE_LINE: FollowLine(); break; case MODE_SUMO: StayInside(); break; case MODE_CARRE: DoCarre(); break; } } else { //Stop AVANCE(0); } //Test the timer if (timer_complete(TIMER_TEMP)) { timer_start(TIMER_TEMP, 500); nb_s ++; //snprintf(str_l1, LCD_SIZE, "%d", nb_s); } if (timer_complete(TIMER_LCD)) { if (!enable) { snprintf(str_l1, LCD_SIZE, "off"); } else { char mode_str[20]; switch (mode) { case MODE_LINE: snprintf(mode_str, LCD_SIZE, "line"); break; case MODE_SUMO: snprintf(mode_str, LCD_SIZE, "sumo"); break; case MODE_CARRE: snprintf(mode_str, LCD_SIZE, "carr"); break; default: snprintf(mode_str, LCD_SIZE, "????"); break; } snprintf(str_l1, LCD_SIZE, "%s %02d ", mode_str, val_buttons); } timer_start(TIMER_LCD, TIMER_LCD_DELAY); lcd_str_out(1,1, str_l1); lcd_str_out(2,1, str_l2); } } return 0; }