can't push chnages :(
Dependencies: PinDetect TextLCD mbed
Fork of FBRDash by
src/Gears.cpp@1:b3907b8d9f65, 2012-06-25 (annotated)
- Committer:
- intrinseca
- Date:
- Mon Jun 25 21:01:02 2012 +0000
- Revision:
- 1:b3907b8d9f65
- Child:
- 2:825f572902c6
Prototype before adding full CAN comms
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:b3907b8d9f65 | 6 | Gears::Gears(PinName up, PinName neutral, PinName down, unsigned char* _currentGear, Comms* _remote) |
intrinseca | 1:b3907b8d9f65 | 7 | { |
intrinseca | 1:b3907b8d9f65 | 8 | currentGear = _currentGear; |
intrinseca | 1:b3907b8d9f65 | 9 | remote = _remote; |
intrinseca | 1:b3907b8d9f65 | 10 | |
intrinseca | 1:b3907b8d9f65 | 11 | btnUp = new PinDetect(up, PullUp); |
intrinseca | 1:b3907b8d9f65 | 12 | btnNeutral = new PinDetect(neutral, PullUp); |
intrinseca | 1:b3907b8d9f65 | 13 | btnDown = new PinDetect(down, PullUp); |
intrinseca | 1:b3907b8d9f65 | 14 | |
intrinseca | 1:b3907b8d9f65 | 15 | btnUp->setAssertValue(0); |
intrinseca | 1:b3907b8d9f65 | 16 | btnDown->setAssertValue(0); |
intrinseca | 1:b3907b8d9f65 | 17 | btnNeutral->setAssertValue(0); |
intrinseca | 1:b3907b8d9f65 | 18 | |
intrinseca | 1:b3907b8d9f65 | 19 | btnUp->attach_asserted(this, &Gears::up); |
intrinseca | 1:b3907b8d9f65 | 20 | btnDown->attach_asserted(this, &Gears::down); |
intrinseca | 1:b3907b8d9f65 | 21 | btnNeutral->attach_asserted(this, &Gears::neutral); |
intrinseca | 1:b3907b8d9f65 | 22 | |
intrinseca | 1:b3907b8d9f65 | 23 | btnUp->setSampleFrequency(); |
intrinseca | 1:b3907b8d9f65 | 24 | btnDown->setSampleFrequency(); |
intrinseca | 1:b3907b8d9f65 | 25 | btnNeutral->setSampleFrequency(); |
intrinseca | 1:b3907b8d9f65 | 26 | } |
intrinseca | 1:b3907b8d9f65 | 27 | |
intrinseca | 1:b3907b8d9f65 | 28 | void Gears::up() |
intrinseca | 1:b3907b8d9f65 | 29 | { |
intrinseca | 1:b3907b8d9f65 | 30 | remote->send(2); |
intrinseca | 1:b3907b8d9f65 | 31 | |
intrinseca | 1:b3907b8d9f65 | 32 | if(*currentGear < 6) |
intrinseca | 1:b3907b8d9f65 | 33 | (*currentGear)++; |
intrinseca | 1:b3907b8d9f65 | 34 | } |
intrinseca | 1:b3907b8d9f65 | 35 | |
intrinseca | 1:b3907b8d9f65 | 36 | void Gears::neutral() |
intrinseca | 1:b3907b8d9f65 | 37 | { |
intrinseca | 1:b3907b8d9f65 | 38 | remote->send(0); |
intrinseca | 1:b3907b8d9f65 | 39 | |
intrinseca | 1:b3907b8d9f65 | 40 | *currentGear = 0; |
intrinseca | 1:b3907b8d9f65 | 41 | } |
intrinseca | 1:b3907b8d9f65 | 42 | |
intrinseca | 1:b3907b8d9f65 | 43 | void Gears::down() |
intrinseca | 1:b3907b8d9f65 | 44 | { |
intrinseca | 1:b3907b8d9f65 | 45 | remote->send(1); |
intrinseca | 1:b3907b8d9f65 | 46 | |
intrinseca | 1:b3907b8d9f65 | 47 | if(*currentGear > 0) |
intrinseca | 1:b3907b8d9f65 | 48 | { |
intrinseca | 1:b3907b8d9f65 | 49 | (*currentGear)--; |
intrinseca | 1:b3907b8d9f65 | 50 | } |
intrinseca | 1:b3907b8d9f65 | 51 | } |