Files at this revision

API Documentation at this revision

Comitter:
lucaspennati
Date:
Fri Nov 30 11:49:21 2018 +0000
Parent:
0:6ab5b8697bfb
Commit message:
Published

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6ab5b8697bfb -r 1d5875aad591 main.cpp
--- a/main.cpp	Mon Nov 12 12:10:30 2018 +0000
+++ b/main.cpp	Fri Nov 30 11:49:21 2018 +0000
@@ -5,30 +5,31 @@
 EventQueue queue(32 * EVENTS_EVENT_SIZE);
 Thread t;
 
-void rise_handler_thread_context(void) {
-    printf("rise_handler_thread_context in context %p\r\n", Thread::gettid());
-}
-
-void rise_handler_iterrupt_context(void) {
-    // Execute the time critical part first
-    led1 = !led1;
-    // The rest can execute later in user context (and can contain code that's not interrupt safe)
-    // We use the 'queue.call' function to add an event (the call to 'rise_handler_user_context') to the queue
-    queue.call(rise_handler_thread_context);
-}
+time_t last_click;
 
 void fall_handler(void) {
-    printf("fall_handler in context %p\r\n", Thread::gettid());
-    // Toggle LED
-    led1 = !led1;
+    printf("Button pressed\r\n");
+    
+    time_t current = time(NULL);
+    
+    if (current - last_click <= 2) {
+        // Turn on the led, wait one sec, and then turn it off
+        led1 = !led1;
+        wait(0.5);
+        led1 = !led1;
+    }
+    
+    // Update the last_click time
+    last_click = current;
 }
 
 int main() {
+    // We start by setting a last click bogus time
+    last_click = time(NULL);
+    
     // Start the event queue
     t.start(callback(&queue, &EventQueue::dispatch_forever));
-    printf("Starting in context %p\r\n", Thread::gettid());
-    // The 'rise' handler will execute in IRQ context
-    button.rise(rise_handler_iterrupt_context);
-    // The 'fall' handler will execute in the context of thread 't'
     button.fall(queue.event(fall_handler));
+    
+    printf("Setup complete\n");
 }