#include #include #include #include #define DELAY 100000 #define REPEAT 21 static f64 start; static u32 iter = 0u; static void timer_callback(void *userdata, struct nn_timer *timer) { (void)userdata; u64 now = nn_get_timestamp(); u64 diff = (nn_get_tick() - start) * 1000000; s64 adj = iter * DELAY - (s64)diff; al_printf("[%2u (%llu)] %fs(%s%f)\n", iter, now, diff / 1000000.0, adj >= 0 ? "+" : "", adj / 1000000.0); nn_timer_set_repeat(timer, NNWT_TS_FROM_USEC(MAX(DELAY + adj, (s64)1))); if (iter++ == 0) nn_timer_again(timer); else if (iter == REPEAT) nn_timer_stop(timer); } s32 main(void) { if (!nn_common_init(NULL)) return EXIT_FAILURE; struct nn_event_loop loop; struct nn_timer timer; nn_event_loop_init(&loop); start = nn_get_tick(); nn_timer_init(&timer, &loop, timer_callback, NULL); nn_timer_set_repeat(&timer, NNWT_TS_FROM_USEC(DELAY)); timer_callback(NULL, &timer); nn_event_loop_run(&loop); nn_event_loop_destroy(&loop); nn_common_close(); return EXIT_SUCCESS; }