File tree Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
#include " mbed_events.h"
6
6
#include < stdio.h>
7
+ using namespace std ::chrono_literals;
7
8
9
+ // In the example below there are 3 types of event callbacks
10
+ // 1) Call the provided function immediately
11
+ // 2) Call the provided function once (after the specified period)
12
+ // 3) Call the provided function every specified period
13
+ //
14
+ // Expected output:
15
+ //
16
+ // called immediately
17
+ // called every 1 seconds
18
+ // called in 2 seconds
19
+ // called every 1 seconds
20
+ // called every 1 seconds
21
+ // ^ repeated forever
22
+ //
8
23
int main ()
9
24
{
10
25
// creates a queue with the default size
11
26
EventQueue queue;
12
27
13
28
// events are simple callbacks
14
29
queue.call (printf, " called immediately\n " );
15
- queue.call_in (2000 , printf, " called in 2 seconds\n " );
16
- queue.call_every (1000 , printf, " called every 1 seconds\n " );
30
+ queue.call_in (2000ms , printf, " called in 2 seconds\n " );
31
+ queue.call_every (1000ms , printf, " called every 1 seconds\n " );
17
32
18
33
// events are executed by the dispatch_forever method
19
34
queue.dispatch_forever ();
Original file line number Diff line number Diff line change 4
4
*/
5
5
#include " mbed_events.h"
6
6
#include < stdio.h>
7
+ using namespace std ::chrono_literals;
7
8
8
9
/* *
9
10
Event queues easily align with module boundaries, where internal state can be
10
11
implicitly synchronized through event dispatch. Multiple modules can use
11
12
independent event queues, but still be composed through the EventQueue::chain function.
13
+
14
+ Note the call() methods in this example only dispatch once as no period is
15
+ set and thus defaults to dispatch_once(). The ordering of the chaining dictates
16
+ the order of the dispatching.
17
+
18
+ Expected output:
19
+
20
+ hello from a!
21
+ hello from c!
22
+ hello from b!
12
23
**/
13
24
14
25
int main ()
@@ -30,5 +41,5 @@ int main()
30
41
31
42
// Dispatching a will in turn dispatch b and c, printing hello from
32
43
// all three queues
33
- a.dispatch ();
44
+ a.dispatch_forever ();
34
45
}
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ int main()
96
96
// converted to using Chrono times and thus times are still specified
97
97
// in integer millisecond units.
98
98
// 800 ms will allow the posted events to be dispatched multiple times
99
- queue.dispatch ( 800 );
99
+ queue.dispatch_for (800ms );
100
100
101
101
event_thread.join ();
102
102
Original file line number Diff line number Diff line change @@ -70,8 +70,8 @@ int main()
70
70
printf (" *** start ***\n " );
71
71
Thread event_thread;
72
72
73
- // The event can be manually configured for special timing requirements
74
- // specified in milliseconds
73
+ // The event can be manually configured for special timing requirements.
74
+ // Timings are specified in milliseconds.
75
75
// Starting delay - 100 msec
76
76
// Delay between each event - 200msec
77
77
event1.delay (100 );
@@ -86,7 +86,7 @@ int main()
86
86
event_thread.start (callback (post_events));
87
87
88
88
// Posted events are dispatched in the context of the queue's dispatch function
89
- queue.dispatch ( 400 ); // Dispatch time - 400msec
89
+ queue.dispatch_for (400ms ); // Dispatch time - 400msec
90
90
// 400 msec - Only 2 set of events will be dispatched as period is 200 msec
91
91
92
92
event_thread.join ();
You can’t perform that action at this time.
0 commit comments