Matthaeus Vorraber
/
ButtonEventDemo
Check Flag
Diff: BtnEventM0.h
- Revision:
- 8:e2f768aad0a6
- Parent:
- 7:d6677cae0add
- Child:
- 9:813c361e38fc
--- a/BtnEventM0.h Thu Jan 29 07:03:32 2015 +0000 +++ b/BtnEventM0.h Wed Feb 01 07:16:21 2017 +0000 @@ -1,39 +1,46 @@ + +class BtnEventM0 { + public: + int16_t pressed; + + BtnEventM0(PinName pin) : _isr(pin) + { pressed=0; } + + // Ist eine steigende Flanke aufgetreten ? + int CheckFlag(); + + // 1..Button is pressed else 0 + int CheckButton() + { return _isr.read(); } + + void Init(); + // { _isr.rise(this,&BtnEventM0::RisingISR); } + + void RisingISR(); + + protected: + InterruptIn _isr; +}; + +void BtnEventM0::Init() + { _isr.rise(this,&BtnEventM0::RisingISR); } + +void BtnEventM0::RisingISR() +{ + if( _isr.read() ) + pressed = 1; +} + +int BtnEventM0::CheckFlag() +{ + if( pressed ) + { pressed=0; return 1; } + return 0; +} -class BtnEventM0 -{ -public: - int16_t pressed; - - BtnEventM0(PinName pin) : _isr(pin) { - pressed=0; - } - // Ist eine steigende Flanke aufgetreten ? - int CheckFlag() { - if( pressed ) { - pressed=0; - return 1; - } - return 0; - } - // 1..Button is pressed else 0 - int CheckButton() { - return _isr.read(); - } - - void Init() { - _isr.rise(this, &BtnEventM0::RisingISR); - } - - void RisingISR() { - if( _isr.read() ) - pressed = 1; - } -protected: - InterruptIn _isr; -}; /* class BtnEventM02 : public BtnEventM0 @@ -97,6 +104,24 @@ } }; +class BtnEventM0S { + public: + BtnEventM0S(PinName pin) : _btn(pin) { } + + void Init() {} + + // Ist eine steigende Flanke aufgetreten ? + int CheckFlag() + { + if( _btn ) + { wait_ms(100); return 1; } + else + return 0; + } + + protected: + DigitalIn _btn; +}; @@ -144,3 +169,4 @@ +