For Telliskivi2 2014

Dependents:   Telliskivi2_2014

Fork of HumanInterface by Reiko Randoja

Committer:
Reiko
Date:
Thu Sep 19 13:13:10 2013 +0000
Revision:
0:ccf47494061b
Child:
1:9b2455659c7d
Created library for leds and buttons

Who changed what in which revision?

UserRevisionLine numberNew 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 changeCallback;
Reiko 0:ccf47494061b 12 FunctionPointer goalRiseCallback;
Reiko 0:ccf47494061b 13 FunctionPointer startRiseCallback;
Reiko 0:ccf47494061b 14 FunctionPointer ballChangeCallback;
Reiko 0:ccf47494061b 15 public:
Reiko 0:ccf47494061b 16 HumanInterface(
Reiko 0:ccf47494061b 17 Serial *pc, PCA9555 *ioExt,
Reiko 0:ccf47494061b 18 unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin,
Reiko 0:ccf47494061b 19 unsigned int goalButtonPin, unsigned int startButtonPin, unsigned int ballSensePin
Reiko 0:ccf47494061b 20 );
Reiko 0:ccf47494061b 21
Reiko 0:ccf47494061b 22 enum Goal {YELLOW, BLUE, UNSET};
Reiko 0:ccf47494061b 23 void setGoal(Goal goal);
Reiko 0:ccf47494061b 24 void setError(bool state);
Reiko 0:ccf47494061b 25
Reiko 0:ccf47494061b 26 bool getBallState();
Reiko 0:ccf47494061b 27
Reiko 0:ccf47494061b 28 void change(void (*function)(void));
Reiko 0:ccf47494061b 29
Reiko 0:ccf47494061b 30 template<typename T>
Reiko 0:ccf47494061b 31 void change(T *object, void (T::*member)(void)) {
Reiko 0:ccf47494061b 32 changeCallback.attach(object, member);
Reiko 0:ccf47494061b 33 }
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 0:ccf47494061b 49 void ballChange(void (*function)(void));
Reiko 0:ccf47494061b 50
Reiko 0:ccf47494061b 51 template<typename T>
Reiko 0:ccf47494061b 52 void ballChange(T *object, void (T::*member)(void)) {
Reiko 0:ccf47494061b 53 ballChangeCallback.attach(object, member);
Reiko 0:ccf47494061b 54 }
Reiko 0:ccf47494061b 55
Reiko 0:ccf47494061b 56 private:
Reiko 0:ccf47494061b 57 Serial *pc;
Reiko 0:ccf47494061b 58
Reiko 0:ccf47494061b 59 PCA9555 *extIO;
Reiko 0:ccf47494061b 60
Reiko 0:ccf47494061b 61 ExternalIn goalButton; // 14
Reiko 0:ccf47494061b 62 ExternalIn startButton; // 15
Reiko 0:ccf47494061b 63 ExternalIn ballSense; // 10
Reiko 0:ccf47494061b 64
Reiko 0:ccf47494061b 65 bool goalLastState;
Reiko 0:ccf47494061b 66 bool startLastState;
Reiko 0:ccf47494061b 67 bool ballLastState;
Reiko 0:ccf47494061b 68
Reiko 0:ccf47494061b 69 LedOut redLed;
Reiko 0:ccf47494061b 70 LedOut blueLed;
Reiko 0:ccf47494061b 71 LedOut yellowLed;
Reiko 0:ccf47494061b 72
Reiko 0:ccf47494061b 73 bool redBlinking;
Reiko 0:ccf47494061b 74 bool blueBlinking;
Reiko 0:ccf47494061b 75 bool yellowBlinking;
Reiko 0:ccf47494061b 76
Reiko 0:ccf47494061b 77 Ticker ledTicker;
Reiko 0:ccf47494061b 78
Reiko 0:ccf47494061b 79 void blinkLeds(void);
Reiko 0:ccf47494061b 80 void extChangedCallback(void);
Reiko 0:ccf47494061b 81 };
Reiko 0:ccf47494061b 82
Reiko 0:ccf47494061b 83 #endif