For Telliskivi2 2014
Fork of HumanInterface by
HumanInterface.cpp@4:0a82202bc5df, 2014-11-21 (annotated)
- Committer:
- Reiko
- Date:
- Fri Nov 21 18:19:47 2014 +0000
- Revision:
- 4:0a82202bc5df
- Parent:
- 3:92390ebe4903
- Child:
- 5:64a46d67cb6e
RGB leds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reiko | 0:ccf47494061b | 1 | #include "HumanInterface.h" |
Reiko | 0:ccf47494061b | 2 | |
mlaane | 2:1ef07b660873 | 3 | |
Reiko | 1:9b2455659c7d | 4 | HumanInterface::HumanInterface (PCA9555 *ioExt, |
Reiko | 4:0a82202bc5df | 5 | unsigned int redLed1Pin, unsigned int greenLed1Pin, unsigned int blueLed1Pin, |
Reiko | 4:0a82202bc5df | 6 | unsigned int redLed2Pin, unsigned int greenLed2Pin, unsigned int blueLed2Pin, |
Reiko | 1:9b2455659c7d | 7 | PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin): |
Reiko | 4:0a82202bc5df | 8 | extIO(ioExt), |
Reiko | 4:0a82202bc5df | 9 | rgbLed1(ioExt, redLed1Pin, greenLed1Pin, blueLed1Pin), |
Reiko | 4:0a82202bc5df | 10 | rgbLed2(ioExt, redLed2Pin, greenLed2Pin, blueLed2Pin), |
mlaane | 2:1ef07b660873 | 11 | buttonGoal(goalButtonPin), buttonStart(startButtonPin), inputBall(ballSensePin) |
mlaane | 2:1ef07b660873 | 12 | { |
mlaane | 2:1ef07b660873 | 13 | goalButtonPressed = false; |
mlaane | 2:1ef07b660873 | 14 | startButtonReleased = false; |
mlaane | 2:1ef07b660873 | 15 | ballState = 0; |
mlaane | 2:1ef07b660873 | 16 | |
mlaane | 2:1ef07b660873 | 17 | buttonGoal.mode(PullUp); |
mlaane | 2:1ef07b660873 | 18 | buttonStart.mode(PullUp); |
mlaane | 2:1ef07b660873 | 19 | |
mlaane | 2:1ef07b660873 | 20 | buttonGoal.attach_deasserted(this, &HumanInterface::goalFall); |
mlaane | 2:1ef07b660873 | 21 | buttonStart.attach_asserted(this, &HumanInterface::startRise); |
mlaane | 2:1ef07b660873 | 22 | inputBall.attach_asserted(this, &HumanInterface::ballRise); |
mlaane | 2:1ef07b660873 | 23 | inputBall.attach_deasserted(this, &HumanInterface::ballFall); |
mlaane | 2:1ef07b660873 | 24 | |
mlaane | 2:1ef07b660873 | 25 | buttonGoal.setSamplesTillAssert(20); |
mlaane | 2:1ef07b660873 | 26 | buttonStart.setSamplesTillAssert(20); |
Reiko | 3:92390ebe4903 | 27 | inputBall.setSamplesTillAssert(2); |
mlaane | 2:1ef07b660873 | 28 | |
mlaane | 2:1ef07b660873 | 29 | buttonGoal.setSampleFrequency(1000); |
mlaane | 2:1ef07b660873 | 30 | buttonStart.setSampleFrequency(1000); |
Reiko | 4:0a82202bc5df | 31 | inputBall.setSampleFrequency(5000); |
mlaane | 2:1ef07b660873 | 32 | |
Reiko | 0:ccf47494061b | 33 | redBlinking = false; |
Reiko | 4:0a82202bc5df | 34 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 35 | |
Reiko | 0:ccf47494061b | 36 | setGoal(UNSET); |
Reiko | 0:ccf47494061b | 37 | |
Reiko | 0:ccf47494061b | 38 | ledTicker.attach(this, &HumanInterface::blinkLeds, 0.2); |
Reiko | 1:9b2455659c7d | 39 | |
Reiko | 0:ccf47494061b | 40 | } |
Reiko | 0:ccf47494061b | 41 | |
Reiko | 0:ccf47494061b | 42 | void HumanInterface::setError(bool state) { |
Reiko | 0:ccf47494061b | 43 | if (state) { |
Reiko | 0:ccf47494061b | 44 | redBlinking = true; |
Reiko | 4:0a82202bc5df | 45 | rgbLed2.setGreen(false); |
Reiko | 4:0a82202bc5df | 46 | rgbLed2.setColor(RgbLed::RED); |
Reiko | 0:ccf47494061b | 47 | } else { |
Reiko | 0:ccf47494061b | 48 | redBlinking = false; |
Reiko | 4:0a82202bc5df | 49 | rgbLed2.setRed(false); |
Reiko | 0:ccf47494061b | 50 | } |
Reiko | 0:ccf47494061b | 51 | } |
Reiko | 0:ccf47494061b | 52 | |
Reiko | 1:9b2455659c7d | 53 | void HumanInterface::setGo(bool state) { |
Reiko | 1:9b2455659c7d | 54 | if (state) { |
Reiko | 4:0a82202bc5df | 55 | rgbLed2.setColor(RgbLed::GREEN); |
Reiko | 4:0a82202bc5df | 56 | redBlinking = false; |
Reiko | 1:9b2455659c7d | 57 | } else { |
Reiko | 4:0a82202bc5df | 58 | rgbLed2.setGreen(false); |
Reiko | 1:9b2455659c7d | 59 | } |
Reiko | 1:9b2455659c7d | 60 | } |
Reiko | 0:ccf47494061b | 61 | |
Reiko | 0:ccf47494061b | 62 | void HumanInterface::setGoal(Goal goal) { |
Reiko | 0:ccf47494061b | 63 | if (goal == YELLOW) { |
Reiko | 4:0a82202bc5df | 64 | rgbLed1.setColor(RgbLed::YELLOW); |
Reiko | 4:0a82202bc5df | 65 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 66 | } else if (goal == BLUE) { |
Reiko | 4:0a82202bc5df | 67 | rgbLed1.setColor(RgbLed::BLUE); |
Reiko | 4:0a82202bc5df | 68 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 69 | } else if (goal == UNSET) { |
Reiko | 4:0a82202bc5df | 70 | rgbLed1.setColor(RgbLed::YELLOW); |
Reiko | 4:0a82202bc5df | 71 | goalBlinking = true; |
Reiko | 0:ccf47494061b | 72 | } |
Reiko | 0:ccf47494061b | 73 | } |
Reiko | 0:ccf47494061b | 74 | |
Reiko | 0:ccf47494061b | 75 | void HumanInterface::blinkLeds(void) { |
Reiko | 0:ccf47494061b | 76 | if (redBlinking) |
Reiko | 4:0a82202bc5df | 77 | rgbLed2.toggleRed(); |
Reiko | 4:0a82202bc5df | 78 | if (goalBlinking) |
Reiko | 4:0a82202bc5df | 79 | rgbLed1.toggle(); |
Reiko | 0:ccf47494061b | 80 | } |
Reiko | 0:ccf47494061b | 81 | |
mlaane | 2:1ef07b660873 | 82 | |
Reiko | 1:9b2455659c7d | 83 | |
mlaane | 2:1ef07b660873 | 84 | int HumanInterface::getBallState() { |
Reiko | 4:0a82202bc5df | 85 | //int ret = ballState; |
Reiko | 4:0a82202bc5df | 86 | //ballState = 0; |
Reiko | 4:0a82202bc5df | 87 | return ballState; |
Reiko | 1:9b2455659c7d | 88 | } |
Reiko | 1:9b2455659c7d | 89 | |
mlaane | 2:1ef07b660873 | 90 | bool HumanInterface::isGoalChange() { |
mlaane | 2:1ef07b660873 | 91 | bool ret = goalButtonPressed; |
mlaane | 2:1ef07b660873 | 92 | goalButtonPressed = false; |
mlaane | 2:1ef07b660873 | 93 | return ret; |
Reiko | 0:ccf47494061b | 94 | } |
Reiko | 4:0a82202bc5df | 95 | |
mlaane | 2:1ef07b660873 | 96 | bool HumanInterface::isStart() { |
mlaane | 2:1ef07b660873 | 97 | bool ret = startButtonReleased; |
mlaane | 2:1ef07b660873 | 98 | startButtonReleased = false; |
mlaane | 2:1ef07b660873 | 99 | return ret; |
Reiko | 0:ccf47494061b | 100 | } |
Reiko | 0:ccf47494061b | 101 | |
mlaane | 2:1ef07b660873 | 102 | void HumanInterface::goalFall() { |
mlaane | 2:1ef07b660873 | 103 | goalButtonPressed = true; |
Reiko | 0:ccf47494061b | 104 | } |
Reiko | 0:ccf47494061b | 105 | |
mlaane | 2:1ef07b660873 | 106 | void HumanInterface::startRise() { |
mlaane | 2:1ef07b660873 | 107 | startButtonReleased = true; |
Reiko | 1:9b2455659c7d | 108 | } |
Reiko | 1:9b2455659c7d | 109 | |
mlaane | 2:1ef07b660873 | 110 | void HumanInterface::ballRise() { |
mlaane | 2:1ef07b660873 | 111 | ballState = 1; |
Reiko | 4:0a82202bc5df | 112 | rgbLed2.setColor(RgbLed::MAGENTA); |
mlaane | 2:1ef07b660873 | 113 | } |
mlaane | 2:1ef07b660873 | 114 | |
mlaane | 2:1ef07b660873 | 115 | void HumanInterface::ballFall() { |
Reiko | 4:0a82202bc5df | 116 | ballState = 0; |
Reiko | 4:0a82202bc5df | 117 | rgbLed2.setColor(RgbLed::OFF); |
mlaane | 2:1ef07b660873 | 118 | } |