Event class example to manually instantiate, configure and post events.

Files at this revision

API Documentation at this revision

Comitter:
deepikabhavnani
Date:
Thu Nov 30 21:50:58 2017 +0000
Commit message:
Initial Draft

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Thu Nov 30 21:50:58 2017 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 30 21:50:58 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+// Creates an event bound to the specified event queue
+EventQueue queue;
+void handler(int count);
+Event<void(int)> event(&queue, handler);
+
+void handler(int count) {
+    printf("Event = %d \n", count);
+    return;
+}
+
+void post_events(void) {
+
+    // Events can be posted multiple times and enqueue gracefully until
+    // the dispatch function is called.
+    event.post(1);
+    event.post(2);
+    event.post(3);    
+}
+
+int main() {
+
+    Thread event_thread;
+        
+    // The event can be manually configured for special timing requirements
+    // specified in milliseconds
+    event.delay(100);       // Starting delay - 100 msec
+    event.period(200);      // Delay between each evet - 200msec
+    
+    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
+    // 400 msec - Only 2 set of events will be dispatched as period is 200 msec
+    
+    event_thread.join();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Nov 30 21:50:58 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#182bbd51bc8d1b6217477c2b5de3f1d0c5e6249f