Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: PwmIn/PwmIn.cpp
- Revision:
- 92:a9dac72d8cac
- Parent:
- 78:b8df106126a7
- Child:
- 137:54c47ef47bbb
--- a/PwmIn/PwmIn.cpp Wed Apr 05 20:57:18 2017 +0000 +++ b/PwmIn/PwmIn.cpp Thu Apr 06 17:33:47 2017 +0000 @@ -2,7 +2,7 @@ #include "PwmIn.h" #include "MathHelpers.h" -PwmIn::PwmIn(PinName pin, int usec_min, int usec_max, int usec_crazy) +PwmIn::PwmIn(PinName pin, int usec_min, int usec_max, int usec_crazy_low, int usec_crazy_hi) { int_in = new InterruptIn(pin); dig_in = new DigitalIn(pin); @@ -10,11 +10,13 @@ int_in->fall(this, &PwmIn::handle_fall); this->usec_min = usec_min; this->usec_max = usec_max; - this->usec_crazy = usec_crazy; + this->usec_crazy_low = usec_crazy_low; + this->usec_crazy_hi = usec_crazy_hi; usecs = usec_min; blocked = false; enabled = false; + risen = false; } @@ -26,6 +28,7 @@ void PwmIn::handle_rise() { enabled = true; + risen = true; timer.stop(); timer.reset(); @@ -41,10 +44,12 @@ if (blocked) { blocked = false; + risen = false; return; } - if (usecs_new <= usec_crazy) usecs = usecs_new; + if (usecs_new <= usec_crazy_hi && usecs_new >= usec_crazy_low && risen) usecs = usecs_new; + risen = false; } float PwmIn::get_throttle()