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 44 */
55#include " mbed_events.h"
66#include < stdio.h>
7+ using namespace std ::chrono_literals;
78
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+ //
823int main ()
924{
1025 // creates a queue with the default size
1126 EventQueue queue;
1227
1328 // events are simple callbacks
1429 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 " );
1732
1833 // events are executed by the dispatch_forever method
1934 queue.dispatch_forever ();
Original file line number Diff line number Diff line change 44 */
55#include " mbed_events.h"
66#include < stdio.h>
7+ using namespace std ::chrono_literals;
78
89/* *
910Event queues easily align with module boundaries, where internal state can be
1011implicitly synchronized through event dispatch. Multiple modules can use
1112independent 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!
1223**/
1324
1425int main ()
@@ -30,5 +41,5 @@ int main()
3041
3142 // Dispatching a will in turn dispatch b and c, printing hello from
3243 // all three queues
33- a.dispatch ();
44+ a.dispatch_forever ();
3445}
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ int main()
9696 // converted to using Chrono times and thus times are still specified
9797 // in integer millisecond units.
9898 // 800 ms will allow the posted events to be dispatched multiple times
99- queue.dispatch ( 800 );
99+ queue.dispatch_for (800ms );
100100
101101 event_thread.join ();
102102
Original file line number Diff line number Diff line change @@ -70,8 +70,8 @@ int main()
7070 printf (" *** start ***\n " );
7171 Thread event_thread;
7272
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.
7575 // Starting delay - 100 msec
7676 // Delay between each event - 200msec
7777 event1.delay (100 );
@@ -86,7 +86,7 @@ int main()
8686 event_thread.start (callback (post_events));
8787
8888 // 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
9090 // 400 msec - Only 2 set of events will be dispatched as period is 200 msec
9191
9292 event_thread.join ();
You can’t perform that action at this time.
0 commit comments