can't push chnages :(

Dependencies:   PinDetect TextLCD mbed

Fork of FBRDash by Michael Allan

Committer:
intrinseca
Date:
Mon Jun 25 21:20:22 2012 +0000
Revision:
2:825f572902c6
Parent:
1:b3907b8d9f65
Add comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
intrinseca 1:b3907b8d9f65 1 #include "Gears.h"
intrinseca 1:b3907b8d9f65 2 #include "mbed.h"
intrinseca 1:b3907b8d9f65 3 #include "PinDetect.h"
intrinseca 1:b3907b8d9f65 4 #include "Comms.h"
intrinseca 1:b3907b8d9f65 5
intrinseca 2:825f572902c6 6 //Detect and process presses of the Gear buttons
intrinseca 2:825f572902c6 7
intrinseca 2:825f572902c6 8 //Initialise members and set up button handlers
intrinseca 1:b3907b8d9f65 9 Gears::Gears(PinName up, PinName neutral, PinName down, unsigned char* _currentGear, Comms* _remote)
intrinseca 1:b3907b8d9f65 10 {
intrinseca 1:b3907b8d9f65 11 currentGear = _currentGear;
intrinseca 1:b3907b8d9f65 12 remote = _remote;
intrinseca 1:b3907b8d9f65 13
intrinseca 1:b3907b8d9f65 14 btnUp = new PinDetect(up, PullUp);
intrinseca 1:b3907b8d9f65 15 btnNeutral = new PinDetect(neutral, PullUp);
intrinseca 1:b3907b8d9f65 16 btnDown = new PinDetect(down, PullUp);
intrinseca 1:b3907b8d9f65 17
intrinseca 2:825f572902c6 18 //Set buttons as pull down to assert
intrinseca 1:b3907b8d9f65 19 btnUp->setAssertValue(0);
intrinseca 1:b3907b8d9f65 20 btnDown->setAssertValue(0);
intrinseca 1:b3907b8d9f65 21 btnNeutral->setAssertValue(0);
intrinseca 1:b3907b8d9f65 22
intrinseca 2:825f572902c6 23 //Attach handlers
intrinseca 1:b3907b8d9f65 24 btnUp->attach_asserted(this, &Gears::up);
intrinseca 1:b3907b8d9f65 25 btnDown->attach_asserted(this, &Gears::down);
intrinseca 1:b3907b8d9f65 26 btnNeutral->attach_asserted(this, &Gears::neutral);
intrinseca 1:b3907b8d9f65 27
intrinseca 2:825f572902c6 28 //Start checking buttons
intrinseca 1:b3907b8d9f65 29 btnUp->setSampleFrequency();
intrinseca 1:b3907b8d9f65 30 btnDown->setSampleFrequency();
intrinseca 1:b3907b8d9f65 31 btnNeutral->setSampleFrequency();
intrinseca 1:b3907b8d9f65 32 }
intrinseca 1:b3907b8d9f65 33
intrinseca 1:b3907b8d9f65 34 void Gears::up()
intrinseca 1:b3907b8d9f65 35 {
intrinseca 2:825f572902c6 36 //Send change up command
intrinseca 1:b3907b8d9f65 37 remote->send(2);
intrinseca 1:b3907b8d9f65 38
intrinseca 2:825f572902c6 39 //Update state
intrinseca 1:b3907b8d9f65 40 if(*currentGear < 6)
intrinseca 1:b3907b8d9f65 41 (*currentGear)++;
intrinseca 1:b3907b8d9f65 42 }
intrinseca 1:b3907b8d9f65 43
intrinseca 1:b3907b8d9f65 44 void Gears::neutral()
intrinseca 1:b3907b8d9f65 45 {
intrinseca 2:825f572902c6 46 //Sent neutral command
intrinseca 1:b3907b8d9f65 47 remote->send(0);
intrinseca 1:b3907b8d9f65 48
intrinseca 2:825f572902c6 49 //Update state
intrinseca 1:b3907b8d9f65 50 *currentGear = 0;
intrinseca 1:b3907b8d9f65 51 }
intrinseca 1:b3907b8d9f65 52
intrinseca 1:b3907b8d9f65 53 void Gears::down()
intrinseca 1:b3907b8d9f65 54 {
intrinseca 2:825f572902c6 55 //Send change down command
intrinseca 1:b3907b8d9f65 56 remote->send(1);
intrinseca 1:b3907b8d9f65 57
intrinseca 2:825f572902c6 58 //Update state
intrinseca 1:b3907b8d9f65 59 if(*currentGear > 0)
intrinseca 1:b3907b8d9f65 60 {
intrinseca 1:b3907b8d9f65 61 (*currentGear)--;
intrinseca 1:b3907b8d9f65 62 }
intrinseca 1:b3907b8d9f65 63 }