vote controller implementatie van Jonas De Rynck

Dependencies:   MQTT

Fork of PGO6_VoteController_template by Jens de hoog

Revision:
2:5f2104244c27
Parent:
1:34e76c0cbe5a
--- a/debounce_button.cpp	Sun Oct 29 23:01:06 2017 +0000
+++ b/debounce_button.cpp	Mon Oct 30 16:43:58 2017 +0000
@@ -34,8 +34,56 @@
 /**
     This function is called when the button has been pressed by the user.
 */
+Timeout timeout;
+Timeout timeout2;
+DigitalOut busy_led(LED2);
+DigitalOut testled(LED1);
+volatile bool button1_enabled = true;  
+volatile int multiclick_state = 0;
+volatile bool button1_busy = false;      // Informs the mainloop that the user is clicking the button
+volatile int multiclick_state_mem = 0;
+volatile bool isready = false;
 
 void button1_onpressed_cb(void)
 {
+    if (button1_enabled)
+    {
+        if(multiclick_state == 0) //eerste druk binnen een seconde
+        {
+            button1_busy = true; //knop is busy voor 1 sec
+            busy_led = 1;
+            timeout2.attach(callback(button1_multiclick_reset_cb), 1.0);
+        }
+        multiclick_state += 1;
+        button1_enabled = false;
+        timeout.attach(callback(&button1_enabled_cb), 0.075);
+    }
+}
+
+void button1_multiclick_reset_cb(void)
+{
+    isready = true;
+    multiclick_state_mem = multiclick_state; // aantal kliks onthouden
+    multiclick_state = 0;
+    button1_busy = false;               //button niet meer busy
+    busy_led = 0;
+    for(int i = 0; i<multiclick_state_mem; i++)
+    {
+        testing();
+    }
     
+}
+
+
+void button1_enabled_cb(void)
+{
+    button1_enabled = true;
+}
+
+void testing(void)
+{
+    testled = 1;
+    wait(0.2);
+    testled = 0;
+    wait(0.2);
 }
\ No newline at end of file