Telliskivi 2+ peripherals library

Revision:
0:ccf47494061b
Child:
1:9b2455659c7d
diff -r 000000000000 -r ccf47494061b HumanInterface.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HumanInterface.h	Thu Sep 19 13:13:10 2013 +0000
@@ -0,0 +1,83 @@
+#ifndef HUMANINTERFACE_H
+#define HUMANINTERFACE_H
+
+#include "mbed.h"
+#include "PCA9555.h"
+#include "externalin.h"
+#include "ledout.h"
+#include "Serial.h"
+
+class HumanInterface {
+    FunctionPointer changeCallback;
+    FunctionPointer goalRiseCallback;
+    FunctionPointer startRiseCallback;
+    FunctionPointer ballChangeCallback;
+public:
+    HumanInterface(
+        Serial *pc, PCA9555 *ioExt,
+        unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin,
+        unsigned int goalButtonPin, unsigned int startButtonPin, unsigned int ballSensePin
+    ); 
+    
+    enum Goal {YELLOW, BLUE, UNSET};
+    void setGoal(Goal goal);
+    void setError(bool state);
+    
+    bool getBallState();
+    
+    void change(void (*function)(void));
+    
+    template<typename T>
+    void change(T *object, void (T::*member)(void)) { 
+        changeCallback.attach(object, member); 
+    } 
+    
+    void goalRise(void (*function)(void));
+    
+    template<typename T>
+    void goalRise(T *object, void (T::*member)(void)) { 
+        goalRiseCallback.attach(object, member); 
+    } 
+    
+    void startRise(void (*function)(void));
+    
+    template<typename T>
+    void startRise(T *object, void (T::*member)(void)) { 
+        startRiseCallback.attach(object, member); 
+    } 
+    
+    void ballChange(void (*function)(void));
+    
+    template<typename T>
+    void ballChange(T *object, void (T::*member)(void)) { 
+        ballChangeCallback.attach(object, member); 
+    }
+    
+private:
+    Serial *pc;
+    
+    PCA9555 *extIO;
+
+    ExternalIn goalButton; // 14
+    ExternalIn startButton; // 15
+    ExternalIn ballSense; // 10
+
+    bool goalLastState;
+    bool startLastState;
+    bool ballLastState;
+
+    LedOut redLed;
+    LedOut blueLed;
+    LedOut yellowLed;
+
+    bool redBlinking;
+    bool blueBlinking;
+    bool yellowBlinking;
+
+    Ticker ledTicker;
+    
+    void blinkLeds(void);
+    void extChangedCallback(void);
+};
+
+#endif
\ No newline at end of file