summaryrefslogtreecommitdiff
path: root/testing/timer_test.c
blob: 63083940cb76689632e64ff03b96e8409ad80185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "../core/timer.h"
#include <stdio.h>

#ifdef WINDOWS
#include <windows.h>
#else 
#include <unistd.h>
#endif

void mssleep(int ms)
{
#ifdef WINDOWS
    Sleep(ms);
#else
    usleep(ms * 1000);
#endif
}

int callback(timer* t, void* arg){
    printf("%s\n", (char*)arg);
    return 1;
}

int repeating(timer* t, void *arg) {
    printf("%s\n", (char*)arg);
    timer_start(t, 3);
    return 0;
}

extern void timer_debug_print();

int main(int argc, char** argv)
{
    timer_init();
    timer_debug_print();
    
    timer* t = new_timer();
    timer_setup(t, &callback, "Long setup method, 4 seconds");
    timer_start(t, 4);
    timer_debug_print();

    timer_single(&repeating, (void*)"This repeats every 3 seconds", 3);
    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();
    
    timer_us(&callback, "100000us", 100000);
    timer_us(&callback, "13s", 13 * US_PER_SECOND);

    while (true) {
        timer_poll();
        mssleep(10);
    }

    return 0;
}