2013-08-12 20:08:03 +08:00
|
|
|
#include "../core/timer.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef WINDOWS
|
|
|
|
#include <windows.h>
|
2013-08-17 01:11:09 +08:00
|
|
|
#else
|
2013-08-12 20:08:03 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void mssleep(int ms)
|
|
|
|
{
|
|
|
|
#ifdef WINDOWS
|
|
|
|
Sleep(ms);
|
|
|
|
#else
|
|
|
|
usleep(ms * 1000);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-17 01:11:09 +08:00
|
|
|
int callback(timer *t, void *arg)
|
|
|
|
{
|
|
|
|
printf("%s\n", (char *)arg);
|
2013-08-12 20:08:03 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-08-17 01:11:09 +08:00
|
|
|
int repeating(timer *t, void *arg)
|
|
|
|
{
|
|
|
|
printf("%s\n", (char *)arg);
|
2013-08-12 20:08:03 +08:00
|
|
|
timer_start(t, 3);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void timer_debug_print();
|
|
|
|
|
2013-08-17 01:11:09 +08:00
|
|
|
int main(int argc, char **argv)
|
2013-08-12 20:08:03 +08:00
|
|
|
{
|
|
|
|
timer_init();
|
|
|
|
timer_debug_print();
|
2013-08-17 01:11:09 +08:00
|
|
|
|
|
|
|
timer *t = new_timer();
|
2013-08-12 20:08:03 +08:00
|
|
|
timer_setup(t, &callback, "Long setup method, 4 seconds");
|
|
|
|
timer_start(t, 4);
|
|
|
|
timer_debug_print();
|
|
|
|
|
2013-08-17 01:11:09 +08:00
|
|
|
timer_single(&repeating, (void *)"This repeats every 3 seconds", 3);
|
2013-08-12 20:08:03 +08:00
|
|
|
timer_debug_print();
|
|
|
|
|
|
|
|
timer_single(&callback, "Short method, 4 seconds", 4);
|
|
|
|
timer_debug_print();
|
|
|
|
|
|
|
|
timer_single(&callback, "1 second", 1);
|
|
|
|
timer_debug_print();
|
|
|
|
|
|
|
|
timer_single(&callback, "15 seconds", 15);
|
|
|
|
timer_debug_print();
|
|
|
|
|
|
|
|
timer_single(&callback, "10 seconds", 10);
|
|
|
|
timer_debug_print();
|
2013-08-17 01:11:09 +08:00
|
|
|
|
2013-08-12 20:08:03 +08:00
|
|
|
timer_us(&callback, "100000us", 100000);
|
|
|
|
timer_us(&callback, "13s", 13 * US_PER_SECOND);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
timer_poll();
|
|
|
|
mssleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|