For Telliskivi2 2014
Fork of HumanInterface by
HumanInterface.cpp@5:64a46d67cb6e, 2014-11-23 (annotated)
- Committer:
- Reiko
- Date:
- Sun Nov 23 02:28:04 2014 +0000
- Revision:
- 5:64a46d67cb6e
- Parent:
- 4:0a82202bc5df
Removed ball debounce
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); |
Reiko | 5:64a46d67cb6e | 22 | //inputBall.attach_asserted(this, &HumanInterface::ballRise); |
Reiko | 5:64a46d67cb6e | 23 | //inputBall.attach_deasserted(this, &HumanInterface::ballFall); |
Reiko | 5:64a46d67cb6e | 24 | |
Reiko | 5:64a46d67cb6e | 25 | inputBall.rise(this, &HumanInterface::ballRise); |
Reiko | 5:64a46d67cb6e | 26 | inputBall.fall(this, &HumanInterface::ballFall); |
mlaane | 2:1ef07b660873 | 27 | |
mlaane | 2:1ef07b660873 | 28 | buttonGoal.setSamplesTillAssert(20); |
mlaane | 2:1ef07b660873 | 29 | buttonStart.setSamplesTillAssert(20); |
Reiko | 5:64a46d67cb6e | 30 | //inputBall.setSamplesTillAssert(2); |
mlaane | 2:1ef07b660873 | 31 | |
mlaane | 2:1ef07b660873 | 32 | buttonGoal.setSampleFrequency(1000); |
mlaane | 2:1ef07b660873 | 33 | buttonStart.setSampleFrequency(1000); |
Reiko | 5:64a46d67cb6e | 34 | //inputBall.setSampleFrequency(5000); |
mlaane | 2:1ef07b660873 | 35 | |
Reiko | 0:ccf47494061b | 36 | redBlinking = false; |
Reiko | 4:0a82202bc5df | 37 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 38 | |
Reiko | 0:ccf47494061b | 39 | setGoal(UNSET); |
Reiko | 0:ccf47494061b | 40 | |
Reiko | 0:ccf47494061b | 41 | ledTicker.attach(this, &HumanInterface::blinkLeds, 0.2); |
Reiko | 1:9b2455659c7d | 42 | |
Reiko | 0:ccf47494061b | 43 | } |
Reiko | 0:ccf47494061b | 44 | |
Reiko | 0:ccf47494061b | 45 | void HumanInterface::setError(bool state) { |
Reiko | 0:ccf47494061b | 46 | if (state) { |
Reiko | 0:ccf47494061b | 47 | redBlinking = true; |
Reiko | 4:0a82202bc5df | 48 | rgbLed2.setGreen(false); |
Reiko | 4:0a82202bc5df | 49 | rgbLed2.setColor(RgbLed::RED); |
Reiko | 0:ccf47494061b | 50 | } else { |
Reiko | 0:ccf47494061b | 51 | redBlinking = false; |
Reiko | 4:0a82202bc5df | 52 | rgbLed2.setRed(false); |
Reiko | 0:ccf47494061b | 53 | } |
Reiko | 0:ccf47494061b | 54 | } |
Reiko | 0:ccf47494061b | 55 | |
Reiko | 1:9b2455659c7d | 56 | void HumanInterface::setGo(bool state) { |
Reiko | 1:9b2455659c7d | 57 | if (state) { |
Reiko | 4:0a82202bc5df | 58 | rgbLed2.setColor(RgbLed::GREEN); |
Reiko | 4:0a82202bc5df | 59 | redBlinking = false; |
Reiko | 1:9b2455659c7d | 60 | } else { |
Reiko | 4:0a82202bc5df | 61 | rgbLed2.setGreen(false); |
Reiko | 1:9b2455659c7d | 62 | } |
Reiko | 1:9b2455659c7d | 63 | } |
Reiko | 0:ccf47494061b | 64 | |
Reiko | 0:ccf47494061b | 65 | void HumanInterface::setGoal(Goal goal) { |
Reiko | 0:ccf47494061b | 66 | if (goal == YELLOW) { |
Reiko | 4:0a82202bc5df | 67 | rgbLed1.setColor(RgbLed::YELLOW); |
Reiko | 4:0a82202bc5df | 68 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 69 | } else if (goal == BLUE) { |
Reiko | 4:0a82202bc5df | 70 | rgbLed1.setColor(RgbLed::BLUE); |
Reiko | 4:0a82202bc5df | 71 | goalBlinking = false; |
Reiko | 0:ccf47494061b | 72 | } else if (goal == UNSET) { |
Reiko | 4:0a82202bc5df | 73 | rgbLed1.setColor(RgbLed::YELLOW); |
Reiko | 4:0a82202bc5df | 74 | goalBlinking = true; |
Reiko | 0:ccf47494061b | 75 | } |
Reiko | 0:ccf47494061b | 76 | } |
Reiko | 0:ccf47494061b | 77 | |
Reiko | 0:ccf47494061b | 78 | void HumanInterface::blinkLeds(void) { |
Reiko | 0:ccf47494061b | 79 | if (redBlinking) |
Reiko | 4:0a82202bc5df | 80 | rgbLed2.toggleRed(); |
Reiko | 4:0a82202bc5df | 81 | if (goalBlinking) |
Reiko | 4:0a82202bc5df | 82 | rgbLed1.toggle(); |
Reiko | 0:ccf47494061b | 83 | } |
Reiko | 0:ccf47494061b | 84 | |
mlaane | 2:1ef07b660873 | 85 | |
Reiko | 1:9b2455659c7d | 86 | |
mlaane | 2:1ef07b660873 | 87 | int HumanInterface::getBallState() { |
Reiko | 4:0a82202bc5df | 88 | //int ret = ballState; |
Reiko | 4:0a82202bc5df | 89 | //ballState = 0; |
Reiko | 4:0a82202bc5df | 90 | return ballState; |
Reiko | 1:9b2455659c7d | 91 | } |
Reiko | 1:9b2455659c7d | 92 | |
mlaane | 2:1ef07b660873 | 93 | bool HumanInterface::isGoalChange() { |
mlaane | 2:1ef07b660873 | 94 | bool ret = goalButtonPressed; |
mlaane | 2:1ef07b660873 | 95 | goalButtonPressed = false; |
mlaane | 2:1ef07b660873 | 96 | return ret; |
Reiko | 0:ccf47494061b | 97 | } |
Reiko | 4:0a82202bc5df | 98 | |
mlaane | 2:1ef07b660873 | 99 | bool HumanInterface::isStart() { |
mlaane | 2:1ef07b660873 | 100 | bool ret = startButtonReleased; |
mlaane | 2:1ef07b660873 | 101 | startButtonReleased = false; |
mlaane | 2:1ef07b660873 | 102 | return ret; |
Reiko | 0:ccf47494061b | 103 | } |
Reiko | 0:ccf47494061b | 104 | |
mlaane | 2:1ef07b660873 | 105 | void HumanInterface::goalFall() { |
mlaane | 2:1ef07b660873 | 106 | goalButtonPressed = true; |
Reiko | 0:ccf47494061b | 107 | } |
Reiko | 0:ccf47494061b | 108 | |
mlaane | 2:1ef07b660873 | 109 | void HumanInterface::startRise() { |
mlaane | 2:1ef07b660873 | 110 | startButtonReleased = true; |
Reiko | 1:9b2455659c7d | 111 | } |
Reiko | 1:9b2455659c7d | 112 | |
mlaane | 2:1ef07b660873 | 113 | void HumanInterface::ballRise() { |
mlaane | 2:1ef07b660873 | 114 | ballState = 1; |
Reiko | 4:0a82202bc5df | 115 | rgbLed2.setColor(RgbLed::MAGENTA); |
mlaane | 2:1ef07b660873 | 116 | } |
mlaane | 2:1ef07b660873 | 117 | |
mlaane | 2:1ef07b660873 | 118 | void HumanInterface::ballFall() { |
Reiko | 4:0a82202bc5df | 119 | ballState = 0; |
Reiko | 4:0a82202bc5df | 120 | rgbLed2.setColor(RgbLed::OFF); |
mlaane | 2:1ef07b660873 | 121 | } |