Telliskivi 2+ peripherals library
HumanInterface.h@1:9b2455659c7d, 2013-11-03 (annotated)
- Committer:
- Reiko
- Date:
- Sun Nov 03 11:40:06 2013 +0000
- Revision:
- 1:9b2455659c7d
- Parent:
- 0:ccf47494061b
- Child:
- 2:1ef07b660873
Changed to use buttons and ball detector connected to mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reiko | 0:ccf47494061b | 1 | #ifndef HUMANINTERFACE_H |
Reiko | 0:ccf47494061b | 2 | #define HUMANINTERFACE_H |
Reiko | 0:ccf47494061b | 3 | |
Reiko | 0:ccf47494061b | 4 | #include "mbed.h" |
Reiko | 0:ccf47494061b | 5 | #include "PCA9555.h" |
Reiko | 0:ccf47494061b | 6 | #include "externalin.h" |
Reiko | 0:ccf47494061b | 7 | #include "ledout.h" |
Reiko | 0:ccf47494061b | 8 | #include "Serial.h" |
Reiko | 0:ccf47494061b | 9 | |
Reiko | 0:ccf47494061b | 10 | class HumanInterface { |
Reiko | 0:ccf47494061b | 11 | FunctionPointer goalRiseCallback; |
Reiko | 0:ccf47494061b | 12 | FunctionPointer startRiseCallback; |
Reiko | 1:9b2455659c7d | 13 | FunctionPointer ballRiseCallback; |
Reiko | 1:9b2455659c7d | 14 | FunctionPointer ballFallCallback; |
Reiko | 0:ccf47494061b | 15 | public: |
Reiko | 0:ccf47494061b | 16 | HumanInterface( |
Reiko | 1:9b2455659c7d | 17 | PCA9555 *ioExt, |
Reiko | 0:ccf47494061b | 18 | unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin, |
Reiko | 1:9b2455659c7d | 19 | unsigned int greenLedPin, unsigned int orangeLedPin, |
Reiko | 1:9b2455659c7d | 20 | PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin |
Reiko | 0:ccf47494061b | 21 | ); |
Reiko | 0:ccf47494061b | 22 | |
Reiko | 0:ccf47494061b | 23 | enum Goal {YELLOW, BLUE, UNSET}; |
Reiko | 0:ccf47494061b | 24 | void setGoal(Goal goal); |
Reiko | 0:ccf47494061b | 25 | void setError(bool state); |
Reiko | 1:9b2455659c7d | 26 | void setGo(bool state); |
Reiko | 0:ccf47494061b | 27 | |
Reiko | 0:ccf47494061b | 28 | bool getBallState(); |
Reiko | 0:ccf47494061b | 29 | |
Reiko | 1:9b2455659c7d | 30 | void goalRised(); |
Reiko | 1:9b2455659c7d | 31 | void startRised(); |
Reiko | 1:9b2455659c7d | 32 | void ballFalled(); |
Reiko | 1:9b2455659c7d | 33 | void ballRised(); |
Reiko | 0:ccf47494061b | 34 | |
Reiko | 0:ccf47494061b | 35 | void goalRise(void (*function)(void)); |
Reiko | 0:ccf47494061b | 36 | |
Reiko | 0:ccf47494061b | 37 | template<typename T> |
Reiko | 0:ccf47494061b | 38 | void goalRise(T *object, void (T::*member)(void)) { |
Reiko | 0:ccf47494061b | 39 | goalRiseCallback.attach(object, member); |
Reiko | 0:ccf47494061b | 40 | } |
Reiko | 0:ccf47494061b | 41 | |
Reiko | 0:ccf47494061b | 42 | void startRise(void (*function)(void)); |
Reiko | 0:ccf47494061b | 43 | |
Reiko | 0:ccf47494061b | 44 | template<typename T> |
Reiko | 0:ccf47494061b | 45 | void startRise(T *object, void (T::*member)(void)) { |
Reiko | 0:ccf47494061b | 46 | startRiseCallback.attach(object, member); |
Reiko | 0:ccf47494061b | 47 | } |
Reiko | 0:ccf47494061b | 48 | |
Reiko | 1:9b2455659c7d | 49 | void ballRise(void (*function)(void)); |
Reiko | 0:ccf47494061b | 50 | |
Reiko | 0:ccf47494061b | 51 | template<typename T> |
Reiko | 1:9b2455659c7d | 52 | void ballRise(T *object, void (T::*member)(void)) { |
Reiko | 1:9b2455659c7d | 53 | ballRiseCallback.attach(object, member); |
Reiko | 1:9b2455659c7d | 54 | } |
Reiko | 1:9b2455659c7d | 55 | |
Reiko | 1:9b2455659c7d | 56 | void ballFall(void (*function)(void)); |
Reiko | 1:9b2455659c7d | 57 | |
Reiko | 1:9b2455659c7d | 58 | template<typename T> |
Reiko | 1:9b2455659c7d | 59 | void ballFall(T *object, void (T::*member)(void)) { |
Reiko | 1:9b2455659c7d | 60 | ballFallCallback.attach(object, member); |
Reiko | 0:ccf47494061b | 61 | } |
Reiko | 0:ccf47494061b | 62 | |
Reiko | 0:ccf47494061b | 63 | private: |
Reiko | 0:ccf47494061b | 64 | Serial *pc; |
Reiko | 0:ccf47494061b | 65 | |
Reiko | 0:ccf47494061b | 66 | PCA9555 *extIO; |
Reiko | 0:ccf47494061b | 67 | |
Reiko | 1:9b2455659c7d | 68 | InterruptIn interruptBall; |
Reiko | 1:9b2455659c7d | 69 | InterruptIn interruptGoal; |
Reiko | 1:9b2455659c7d | 70 | InterruptIn interruptStart; |
Reiko | 1:9b2455659c7d | 71 | |
Reiko | 1:9b2455659c7d | 72 | bool goalCurrentState; |
Reiko | 1:9b2455659c7d | 73 | bool startCurrentState; |
Reiko | 1:9b2455659c7d | 74 | bool ballCurrentState; |
Reiko | 0:ccf47494061b | 75 | bool goalLastState; |
Reiko | 0:ccf47494061b | 76 | bool startLastState; |
Reiko | 0:ccf47494061b | 77 | bool ballLastState; |
Reiko | 0:ccf47494061b | 78 | |
Reiko | 0:ccf47494061b | 79 | LedOut redLed; |
Reiko | 0:ccf47494061b | 80 | LedOut blueLed; |
Reiko | 0:ccf47494061b | 81 | LedOut yellowLed; |
Reiko | 1:9b2455659c7d | 82 | LedOut greenLed; |
Reiko | 1:9b2455659c7d | 83 | LedOut orangeLed; |
Reiko | 0:ccf47494061b | 84 | |
Reiko | 0:ccf47494061b | 85 | bool redBlinking; |
Reiko | 0:ccf47494061b | 86 | bool blueBlinking; |
Reiko | 0:ccf47494061b | 87 | bool yellowBlinking; |
Reiko | 1:9b2455659c7d | 88 | bool greenBlinking; |
Reiko | 1:9b2455659c7d | 89 | bool orangeBlinking; |
Reiko | 0:ccf47494061b | 90 | |
Reiko | 0:ccf47494061b | 91 | Ticker ledTicker; |
Reiko | 0:ccf47494061b | 92 | |
Reiko | 0:ccf47494061b | 93 | void blinkLeds(void); |
Reiko | 0:ccf47494061b | 94 | }; |
Reiko | 0:ccf47494061b | 95 | |
Reiko | 0:ccf47494061b | 96 | #endif |