robot

Dependencies:   FastPWM3 mbed

Revision:
75:591556ce033d
Parent:
19:a6cf15f89f3d
Child:
78:b8df106126a7
--- a/PwmIn/PwmIn.cpp	Fri Feb 24 13:03:34 2017 +0000
+++ b/PwmIn/PwmIn.cpp	Fri Feb 24 21:37:14 2017 +0000
@@ -10,6 +10,10 @@
     int_in->fall(this, &PwmIn::handle_fall);
     this->usec_min = usec_min;
     this->usec_max = usec_max;
+    
+    usecs = usec_min;
+    blocked = false;
+    enabled = false;
 }
 
 
@@ -21,19 +25,25 @@
 void PwmIn::handle_rise()
 {
     enabled = true;
+    
     timer.stop();
     timer.reset();
     timer.start();
-    was_on = true;
 }
 
 void PwmIn::handle_fall()
 {
-    was_on = false;
-    usecs = timer.read_us();
+    int usecs_new = timer.read_us();
     timer.stop();
     timer.reset();
     timer.start();
+    
+    if (blocked) {
+        blocked = false;
+        return;
+    }
+    
+    if (usecs_new <= usec_max) usecs = usecs_new;
 }
 
 float PwmIn::get_throttle()