-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.h
58 lines (45 loc) · 1.57 KB
/
events.h
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
#ifndef EVENTS_H
#define EVENTS_H
typedef struct Event_S {
int nextInvoke;
void (*call)(unsigned,unsigned);
unsigned from;
unsigned to;
struct Event_S *next;
} Event;
void dumpEvent(Event * e); //for debugging
//Globals
extern Event *listEventHead; //Head of the list with the events
extern Event *currentEvent; //In the event loop this will have the current Context
extern Event *pendingEvents; //Head of the list of events pending for registration
extern void (*tickCallback)(); //Function called after finishing every tick
/*
* Initialises the event handler
* Takes as argument a callback to a function that may be called
* at the end of each tick
*/
void initEvent(void (*callback)());
/*
* Invokes the event loop. Does not return
* The delay is managed by the callback
*/
void eventLoop();
/*
* Performs all actions for one tick.
* Can be used for a timer/interrupt driven schedule
*/
void eventLoopInterrupt();
/*
* Registers an event in the handler. The arguments from and to describe the intervall the callback
* should work on. The callback get these as argument in the same order. The argument invoke
* describes in how many ticks the event is to be called.
*
* If the event is overlapping with an event that is already registered the event is removed.
* Registration is done at the end of each tick in the order the events were added.
*/
void registerEvent(void (*call)(unsigned,unsigned), unsigned from, unsigned to, unsigned invoke);
/*
* This function may be called inside an event callback to reschedule the current event.
*/
void recallEvent(unsigned ticks);
#endif