For Telliskivi2 2014
Fork of HumanInterface by
HumanInterface.cpp
- Committer:
- Reiko
- Date:
- 2013-11-03
- Revision:
- 1:9b2455659c7d
- Parent:
- 0:ccf47494061b
- Child:
- 2:1ef07b660873
File content as of revision 1:9b2455659c7d:
#include "HumanInterface.h" HumanInterface::HumanInterface (PCA9555 *ioExt, unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin, unsigned int greenLedPin, unsigned int orangeLedPin, PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin): extIO(ioExt), yellowLed(ioExt, yellowLedPin), blueLed(ioExt, blueLedPin), redLed(ioExt, redLedPin), greenLed(ioExt, greenLedPin), orangeLed(ioExt, orangeLedPin), interruptGoal(goalButtonPin), interruptStart(startButtonPin), interruptBall(ballSensePin) { redBlinking = false; blueBlinking = false; yellowBlinking = false; greenBlinking = false; orangeBlinking = false; goalLastState = false; startLastState = false; ballLastState = false; setGoal(UNSET); ledTicker.attach(this, &HumanInterface::blinkLeds, 0.2); interruptGoal.mode(PullUp); interruptStart.mode(PullUp); interruptGoal.rise(this, &HumanInterface::goalRised); interruptStart.rise(this, &HumanInterface::startRised); interruptBall.fall(this, &HumanInterface::ballFalled); interruptBall.rise(this, &HumanInterface::ballRised); } void HumanInterface::setError(bool state) { if (state) { redBlinking = true; } else { redBlinking = false; redLed.clear(); } } void HumanInterface::setGo(bool state) { if (state) { greenLed.set(); } else { greenLed.clear(); } } void HumanInterface::setGoal(Goal goal) { if (goal == YELLOW) { yellowLed.set(); blueLed.clear(); blueBlinking = false; yellowBlinking = false; } else if (goal == BLUE) { yellowLed.clear(); blueLed.set(); blueBlinking = false; yellowBlinking = false; } else if (goal == UNSET) { yellowLed.clear(); blueLed.clear(); blueBlinking = true; yellowBlinking = true; } } void HumanInterface::blinkLeds(void) { if (redBlinking) redLed.toggle(); if (blueBlinking) blueLed.toggle(); if (yellowBlinking) yellowLed.toggle(); if (greenBlinking) greenLed.toggle(); if (orangeBlinking) orangeLed.toggle(); } bool HumanInterface::getBallState() { return ballCurrentState; } void HumanInterface::goalRised() { goalRiseCallback.call(); } void HumanInterface::startRised() { startRiseCallback.call(); } void HumanInterface::ballRised() { ballRiseCallback.call(); } void HumanInterface::ballFalled() { ballFallCallback.call(); } void HumanInterface::goalRise(void (*function)(void)) { goalRiseCallback.attach(function); } void HumanInterface::startRise(void (*function)(void)) { startRiseCallback.attach(function); } void HumanInterface::ballRise(void (*function)(void)) { ballRiseCallback.attach(function); } void HumanInterface::ballFall(void (*function)(void)) { ballFallCallback.attach(function); }