ReelTwo
RSeries astromech firmware
DelayCall.h
Go to the documentation of this file.
1
#ifndef DelayCall_h
2
#define DelayCall_h
3
4
#include "
ReelTwo.h
"
5
#include "
core/AnimatedEvent.h
"
6
7
#define MAX_DELAY_CALL 10
8
9
typedef
void (*
DelayCallPtr
)();
10
28
class
DelayCall
:
public
AnimatedEvent
29
{
30
public
:
34
static
void
schedule
(
DelayCallPtr
callptr, uint32_t delayMillis)
35
{
36
Call* call = storage();
37
for
(
int
i = 0; i <
MAX_DELAY_CALL
; i++, call++)
38
{
39
if
(call->fCallptr == NULL)
40
{
41
call->fScheduleTime = millis() + delayMillis;
42
call->fCallptr = callptr;
43
break
;
44
}
45
}
46
}
47
51
virtual
void
animate
()
52
{
53
Call* call = storage();
54
for
(
int
i = 0; i <
MAX_DELAY_CALL
; i++, call++)
55
{
56
if
(call->fCallptr != NULL && millis() >= call->fScheduleTime)
57
{
58
DelayCallPtr
callptr = call->fCallptr;
59
call->fCallptr = NULL;
60
callptr();
61
}
62
}
63
}
64
65
private
:
66
DelayCall
() {}
67
struct
Call
68
{
69
DelayCallPtr
fCallptr;
70
uint32_t fScheduleTime;
71
};
72
Call fStorage[
MAX_DELAY_CALL
];
73
74
static
Call* storage()
75
{
76
static
DelayCall
myself;
77
return
myself.fStorage;
78
}
79
};
80
#endif
ReelTwo.h
AnimatedEvent
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition:
AnimatedEvent.h:18
DelayCall::schedule
static void schedule(DelayCallPtr callptr, uint32_t delayMillis)
Schedules a function to be called after "delayMillis" milliseconds.
Definition:
DelayCall.h:34
AnimatedEvent.h
DelayCall
Schedules a function to be called at a later time.
Definition:
DelayCall.h:28
DelayCall::animate
virtual void animate()
Call any pending delay call if its delay timer has expired.
Definition:
DelayCall.h:51
MAX_DELAY_CALL
#define MAX_DELAY_CALL
Definition:
DelayCall.h:7
DelayCallPtr
void(* DelayCallPtr)()
Definition:
DelayCall.h:9
core
DelayCall.h
Generated by
1.8.17