Microcontroller firmware that uses a simple, yet powerful scripting language to control the timing of input and output events with high temporal resolution. Written by Mattias Karlsson

Dependencies:   SMARTWAV mbed

Revision:
2:35266b266eaa
Parent:
0:8dbd6bd9167f
Child:
3:d7b0a0890d96
diff -r 8dbd6bd9167f -r 35266b266eaa behave.cpp
--- a/behave.cpp	Tue May 19 15:45:42 2015 +0000
+++ b/behave.cpp	Wed Jun 03 23:41:16 2015 +0000
@@ -441,12 +441,16 @@
 bool digitalPort::update() {
 
     bool changed = false;
+    bool execUp = false;
+    bool execDown = false;
     if ((timeKeeper - lastChangeTime) > 1) { //prevents flutter triggers when button is pressed
 
         //changed = (lastInState != inState);
 
         changed = (inPin->lastUpEvent.triggered || inPin->lastDownEvent.triggered);
         if (changed) {
+            inPin->setUpdate(true); //Once we get the state of the pin, we buffer any pin changes until we are done checking
+
             inState = getDigitalIn();
 
             //We need to ignore flutter when levers/beam breaks are triggered. So
@@ -506,12 +510,16 @@
                     if (triggerDownEventPtr != NULL) {triggerDownEventPtr->execute();}
                 }
             }
+            
+            lastInState = inState;
+            inPin->lastUpEvent.triggered = false;
+            inPin->lastDownEvent.triggered = false;
+            
+            inPin->setUpdate(false); //This also checks if there were any buffered changes that occured
 
         }
 
-        lastInState = inState;
-        inPin->lastUpEvent.triggered = false;
-        inPin->lastDownEvent.triggered = false;
+        
 
     }