diff --git a/APIs_RTOS/EventQueue_ex_2/main.cpp b/APIs_RTOS/EventQueue_ex_2/main.cpp index bd30707..2ca789a 100644 --- a/APIs_RTOS/EventQueue_ex_2/main.cpp +++ b/APIs_RTOS/EventQueue_ex_2/main.cpp @@ -4,7 +4,22 @@ */ #include "mbed_events.h" #include +using namespace std::chrono_literals; +// In the example below there are 3 types of event callbacks +// 1) Call the provided function immediately +// 2) Call the provided function once (after the specified period) +// 3) Call the provided function every specified period +// +// Expected output: +// +// called immediately +// called every 1 seconds +// called in 2 seconds +// called every 1 seconds +// called every 1 seconds +// ^ repeated forever +// int main() { // creates a queue with the default size @@ -12,8 +27,8 @@ int main() // events are simple callbacks queue.call(printf, "called immediately\n"); - queue.call_in(2000, printf, "called in 2 seconds\n"); - queue.call_every(1000, printf, "called every 1 seconds\n"); + queue.call_in(2000ms, printf, "called in 2 seconds\n"); + queue.call_every(1000ms, printf, "called every 1 seconds\n"); // events are executed by the dispatch_forever method queue.dispatch_forever(); diff --git a/APIs_RTOS/EventQueue_ex_3/main.cpp b/APIs_RTOS/EventQueue_ex_3/main.cpp index e5de693..c98d4d0 100644 --- a/APIs_RTOS/EventQueue_ex_3/main.cpp +++ b/APIs_RTOS/EventQueue_ex_3/main.cpp @@ -4,11 +4,22 @@ */ #include "mbed_events.h" #include +using namespace std::chrono_literals; /** Event queues easily align with module boundaries, where internal state can be implicitly synchronized through event dispatch. Multiple modules can use independent event queues, but still be composed through the EventQueue::chain function. + +Note the call() methods in this example only dispatch once as no period is +set and thus defaults to dispatch_once(). The ordering of the chaining dictates +the order of the dispatching. + +Expected output: + +hello from a! +hello from c! +hello from b! **/ int main() @@ -30,5 +41,5 @@ int main() // Dispatching a will in turn dispatch b and c, printing hello from // all three queues - a.dispatch(); + a.dispatch_forever(); } diff --git a/APIs_RTOS/Events_ex_1/main.cpp b/APIs_RTOS/Events_ex_1/main.cpp index 895c232..92dba9a 100644 --- a/APIs_RTOS/Events_ex_1/main.cpp +++ b/APIs_RTOS/Events_ex_1/main.cpp @@ -96,7 +96,7 @@ int main() // converted to using Chrono times and thus times are still specified // in integer millisecond units. // 800 ms will allow the posted events to be dispatched multiple times - queue.dispatch(800); + queue.dispatch_for(800ms); event_thread.join(); diff --git a/APIs_RTOS/UserAllocatedEvent_ex_1/main.cpp b/APIs_RTOS/UserAllocatedEvent_ex_1/main.cpp index 258446a..cfe65c9 100644 --- a/APIs_RTOS/UserAllocatedEvent_ex_1/main.cpp +++ b/APIs_RTOS/UserAllocatedEvent_ex_1/main.cpp @@ -70,8 +70,8 @@ int main() printf("*** start ***\n"); Thread event_thread; - // The event can be manually configured for special timing requirements - // specified in milliseconds + // The event can be manually configured for special timing requirements. + // Timings are specified in milliseconds. // Starting delay - 100 msec // Delay between each event - 200msec event1.delay(100); @@ -86,7 +86,7 @@ int main() event_thread.start(callback(post_events)); // Posted events are dispatched in the context of the queue's dispatch function - queue.dispatch(400); // Dispatch time - 400msec + queue.dispatch_for(400ms); // Dispatch time - 400msec // 400 msec - Only 2 set of events will be dispatched as period is 200 msec event_thread.join();