Telliskivi 2+ peripherals library

Revision:
2:1ef07b660873
Parent:
1:9b2455659c7d
Child:
3:92390ebe4903
--- a/HumanInterface.cpp	Sun Nov 03 11:40:06 2013 +0000
+++ b/HumanInterface.cpp	Mon Nov 04 21:23:17 2013 +0000
@@ -1,33 +1,46 @@
 #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),
+    extIO(ioExt), redLed(ioExt, redLedPin), blueLed(ioExt, blueLedPin), yellowLed(ioExt, yellowLedPin),
     greenLed(ioExt, greenLedPin), orangeLed(ioExt, orangeLedPin),
-    interruptGoal(goalButtonPin), interruptStart(startButtonPin), interruptBall(ballSensePin) { 
+    /*interruptGoal(goalButtonPin), interruptStart(startButtonPin), interruptBall(ballSensePin)*/
+    buttonGoal(goalButtonPin), buttonStart(startButtonPin), inputBall(ballSensePin)
+    {
+        goalButtonPressed = false;
+        startButtonReleased = false;
+        ballState = 0;
+        
+        buttonGoal.mode(PullUp);
+        buttonStart.mode(PullUp);
+        
+        buttonGoal.attach_deasserted(this, &HumanInterface::goalFall);
+        buttonStart.attach_asserted(this, &HumanInterface::startRise);
+        inputBall.attach_asserted(this, &HumanInterface::ballRise);
+        inputBall.attach_deasserted(this, &HumanInterface::ballFall);
+        
+        buttonGoal.setSamplesTillAssert(20);
+        buttonStart.setSamplesTillAssert(20);
+        inputBall.setSamplesTillAssert(4);
+        
+        buttonGoal.setSampleFrequency(1000);
+        buttonStart.setSampleFrequency(1000);
+        inputBall.setSampleFrequency(1000);
+        
+        
         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) {
@@ -79,38 +92,38 @@
         orangeLed.toggle();
 }
 
-bool HumanInterface::getBallState() {
-    return ballCurrentState;
-}
+
 
-void HumanInterface::goalRised() {
-    goalRiseCallback.call();
-}
-
-void HumanInterface::startRised() {
-    startRiseCallback.call();
-}
-
-void HumanInterface::ballRised() {
-    ballRiseCallback.call();
+int HumanInterface::getBallState() {
+    int ret = ballState;
+    ballState = 0;
+    return ret;
 }
 
-void HumanInterface::ballFalled() {
-    ballFallCallback.call();
+bool HumanInterface::isGoalChange() {
+    bool ret = goalButtonPressed;
+    goalButtonPressed = false;
+    return ret;
 }
-
-void HumanInterface::goalRise(void (*function)(void)) { 
-    goalRiseCallback.attach(function);
+bool HumanInterface::isStart() {
+    bool ret = startButtonReleased;
+    startButtonReleased = false;
+    return ret;
 }
 
-void HumanInterface::startRise(void (*function)(void)) { 
-    startRiseCallback.attach(function);
+
+void HumanInterface::goalFall() {
+    goalButtonPressed = true;
 }
 
-void HumanInterface::ballRise(void (*function)(void)) { 
-    ballRiseCallback.attach(function);
+void HumanInterface::startRise() {
+    startButtonReleased = true;
 }
 
-void HumanInterface::ballFall(void (*function)(void)) { 
-    ballFallCallback.attach(function);
-}
\ No newline at end of file
+void HumanInterface::ballRise() {
+    ballState = 1;
+}
+
+void HumanInterface::ballFall() {
+    ballState = -1;
+}