For Telliskivi2 2014

Dependents:   Telliskivi2_2014

Fork of HumanInterface by Reiko Randoja

HumanInterface.h

Committer:
Reiko
Date:
2013-11-03
Revision:
1:9b2455659c7d
Parent:
0:ccf47494061b
Child:
2:1ef07b660873

File content as of revision 1:9b2455659c7d:

#ifndef HUMANINTERFACE_H
#define HUMANINTERFACE_H

#include "mbed.h"
#include "PCA9555.h"
#include "externalin.h"
#include "ledout.h"
#include "Serial.h"

class HumanInterface {
    FunctionPointer goalRiseCallback;
    FunctionPointer startRiseCallback;
    FunctionPointer ballRiseCallback;
    FunctionPointer ballFallCallback;
public:
    HumanInterface(
        PCA9555 *ioExt,
        unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin,
        unsigned int greenLedPin, unsigned int orangeLedPin,
        PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin
    ); 
    
    enum Goal {YELLOW, BLUE, UNSET};
    void setGoal(Goal goal);
    void setError(bool state);
    void setGo(bool state);    
    
    bool getBallState();
    
    void goalRised();
    void startRised();
    void ballFalled();
    void ballRised();
    
    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 ballRise(void (*function)(void));
    
    template<typename T>
    void ballRise(T *object, void (T::*member)(void)) { 
        ballRiseCallback.attach(object, member); 
    }
    
    void ballFall(void (*function)(void));
    
    template<typename T>
    void ballFall(T *object, void (T::*member)(void)) { 
        ballFallCallback.attach(object, member); 
    }
    
private:
    Serial *pc;
    
    PCA9555 *extIO;

    InterruptIn interruptBall;
    InterruptIn interruptGoal;
    InterruptIn interruptStart;
    
    bool goalCurrentState;
    bool startCurrentState;
    bool ballCurrentState;
    bool goalLastState;
    bool startLastState;
    bool ballLastState;

    LedOut redLed;
    LedOut blueLed;
    LedOut yellowLed;
    LedOut greenLed;
    LedOut orangeLed;

    bool redBlinking;
    bool blueBlinking;
    bool yellowBlinking;
    bool greenBlinking;
    bool orangeBlinking;

    Ticker ledTicker;
    
    void blinkLeds(void);
};

#endif