Check Flag

Dependencies:   mbed

BtnEventM0.h

Committer:
hollegha2
Date:
2015-01-14
Revision:
6:cc64c2ff26b0
Parent:
5:ff46a385e7ec
Child:
7:d6677cae0add

File content as of revision 6:cc64c2ff26b0:



class BtnEventM0
{
public:
    int16_t pressed;

    BtnEventM0(PinName pin) : _isr(pin) {
        pressed=0;
    }

    int CheckFlag() {
        if( pressed ) {
            pressed=0;
            return 1;
        }
        return 0;
    }

    void CheckButton() {
        if( _isr.read() )
            pressed = 1;
    }

    void Init() {
        _isr.rise(this, &BtnEventM0::RisingISR);
    }

    void RisingISR() {
        if( _isr.read() )
            pressed = 1;
    }
protected:
    InterruptIn _isr;
};

/*
class BtnEventM02 : public BtnEventM0
{
public:
    BtnEventM02(PinName pin) : BtnEventM0(pin) {
        _tm.stop();
        _tm.reset();
        _state=1;
    }

    void Init() {
        _isr.rise(this, &BtnEventM02::RisingISR);
    }

    void RisingISR() {
        if( !_isr.read() )
            return;
        pressed = 1;
        _tm.start();
        _state = 2;
    }

    void CheckButton() {
        if( _state==1 )
            return;
        if( _state==2 ) {
            if( !_isr.read() ) {
                _state = 1;
                return;
            }
            if( _tm.read_ms()>500 ) {
                _tm.reset();
                _state = 3;
                pressed = 1;
            }
        } else if( _state==3 ) {
            if( !_isr.read() ) {
                _state = 1;
                return;
            }
            if( _tm.read_ms()>100 ) {
                _tm.reset();
                _state = 3;
                pressed = 1;
            }
        }
    }
private:
    int16_t _state;
    Timer _tm;
};
*/

class AnalogInHL : public AnalogIn {
    public:
        AnalogInHL(PinName pin) : AnalogIn(pin) { }
        int Read()
            { return read_u16()>>6; }
};