Thomas Milburn
/
FBRDash-tom
can't push chnages :(
Fork of FBRDash by
Diff: src/Gears.cpp
- Revision:
- 2:825f572902c6
- Parent:
- 1:b3907b8d9f65
--- a/src/Gears.cpp Mon Jun 25 21:01:02 2012 +0000 +++ b/src/Gears.cpp Mon Jun 25 21:20:22 2012 +0000 @@ -3,6 +3,9 @@ #include "PinDetect.h" #include "Comms.h" +//Detect and process presses of the Gear buttons + +//Initialise members and set up button handlers Gears::Gears(PinName up, PinName neutral, PinName down, unsigned char* _currentGear, Comms* _remote) { currentGear = _currentGear; @@ -12,14 +15,17 @@ btnNeutral = new PinDetect(neutral, PullUp); btnDown = new PinDetect(down, PullUp); + //Set buttons as pull down to assert btnUp->setAssertValue(0); btnDown->setAssertValue(0); btnNeutral->setAssertValue(0); + //Attach handlers btnUp->attach_asserted(this, &Gears::up); btnDown->attach_asserted(this, &Gears::down); btnNeutral->attach_asserted(this, &Gears::neutral); + //Start checking buttons btnUp->setSampleFrequency(); btnDown->setSampleFrequency(); btnNeutral->setSampleFrequency(); @@ -27,23 +33,29 @@ void Gears::up() { + //Send change up command remote->send(2); + //Update state if(*currentGear < 6) (*currentGear)++; } void Gears::neutral() { + //Sent neutral command remote->send(0); + //Update state *currentGear = 0; } void Gears::down() { + //Send change down command remote->send(1); + //Update state if(*currentGear > 0) { (*currentGear)--;