Thomas Milburn
/
FBRDash-tom
can't push chnages :(
Fork of FBRDash by
Diff: src/Gears.cpp
- Revision:
- 1:b3907b8d9f65
- Child:
- 2:825f572902c6
diff -r 1f422ed56e0f -r b3907b8d9f65 src/Gears.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Gears.cpp Mon Jun 25 21:01:02 2012 +0000 @@ -0,0 +1,51 @@ +#include "Gears.h" +#include "mbed.h" +#include "PinDetect.h" +#include "Comms.h" + +Gears::Gears(PinName up, PinName neutral, PinName down, unsigned char* _currentGear, Comms* _remote) +{ + currentGear = _currentGear; + remote = _remote; + + btnUp = new PinDetect(up, PullUp); + btnNeutral = new PinDetect(neutral, PullUp); + btnDown = new PinDetect(down, PullUp); + + btnUp->setAssertValue(0); + btnDown->setAssertValue(0); + btnNeutral->setAssertValue(0); + + btnUp->attach_asserted(this, &Gears::up); + btnDown->attach_asserted(this, &Gears::down); + btnNeutral->attach_asserted(this, &Gears::neutral); + + btnUp->setSampleFrequency(); + btnDown->setSampleFrequency(); + btnNeutral->setSampleFrequency(); +} + +void Gears::up() +{ + remote->send(2); + + if(*currentGear < 6) + (*currentGear)++; +} + +void Gears::neutral() +{ + remote->send(0); + + *currentGear = 0; +} + +void Gears::down() +{ + remote->send(1); + + if(*currentGear > 0) + { + (*currentGear)--; + } +} \ No newline at end of file