![](/media/cache/profiles/38fcf18b093fdaa9016a4b84255dfcaf.jpg.50x50_q85.jpg)
Lalala
BtnEventM0.h@1:eddde0361c0a, 2018-02-05 (annotated)
- Committer:
- DoTTi
- Date:
- Mon Feb 05 18:22:34 2018 +0000
- Revision:
- 1:eddde0361c0a
- Parent:
- 0:425c87a33e63
Lalala
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martinale | 0:425c87a33e63 | 1 | |
martinale | 0:425c87a33e63 | 2 | // V4.0 |
martinale | 0:425c87a33e63 | 3 | |
martinale | 0:425c87a33e63 | 4 | class BtnEventM0 { |
martinale | 0:425c87a33e63 | 5 | public: |
martinale | 0:425c87a33e63 | 6 | int16_t pressed; |
martinale | 0:425c87a33e63 | 7 | |
martinale | 0:425c87a33e63 | 8 | BtnEventM0(PinName pin) : _isr(pin) |
martinale | 0:425c87a33e63 | 9 | { pressed=0; } |
martinale | 0:425c87a33e63 | 10 | |
martinale | 0:425c87a33e63 | 11 | // Ist eine steigende Flanke aufgetreten ? |
martinale | 0:425c87a33e63 | 12 | int CheckFlag(); |
martinale | 0:425c87a33e63 | 13 | |
martinale | 0:425c87a33e63 | 14 | // 1..Button is pressed else 0 |
martinale | 0:425c87a33e63 | 15 | int CheckButton() |
martinale | 0:425c87a33e63 | 16 | { return _isr.read(); } |
martinale | 0:425c87a33e63 | 17 | |
martinale | 0:425c87a33e63 | 18 | void Init(); |
martinale | 0:425c87a33e63 | 19 | // { _isr.rise(this,&BtnEventM0::RisingISR); } |
martinale | 0:425c87a33e63 | 20 | |
martinale | 0:425c87a33e63 | 21 | void RisingISR(); |
martinale | 0:425c87a33e63 | 22 | |
martinale | 0:425c87a33e63 | 23 | protected: |
martinale | 0:425c87a33e63 | 24 | InterruptIn _isr; |
martinale | 0:425c87a33e63 | 25 | }; |
martinale | 0:425c87a33e63 | 26 | |
martinale | 0:425c87a33e63 | 27 | void BtnEventM0::Init() |
martinale | 0:425c87a33e63 | 28 | { _isr.rise(this,&BtnEventM0::RisingISR); } |
martinale | 0:425c87a33e63 | 29 | |
martinale | 0:425c87a33e63 | 30 | void BtnEventM0::RisingISR() |
martinale | 0:425c87a33e63 | 31 | { |
martinale | 0:425c87a33e63 | 32 | if( _isr.read() ) |
martinale | 0:425c87a33e63 | 33 | pressed = 1; |
martinale | 0:425c87a33e63 | 34 | } |
martinale | 0:425c87a33e63 | 35 | |
martinale | 0:425c87a33e63 | 36 | int BtnEventM0::CheckFlag() |
martinale | 0:425c87a33e63 | 37 | { |
martinale | 0:425c87a33e63 | 38 | if( pressed ) |
martinale | 0:425c87a33e63 | 39 | { pressed=0; return 1; } |
martinale | 0:425c87a33e63 | 40 | return 0; |
martinale | 0:425c87a33e63 | 41 | } |
martinale | 0:425c87a33e63 | 42 | |
martinale | 0:425c87a33e63 | 43 | |
martinale | 0:425c87a33e63 | 44 | |
martinale | 0:425c87a33e63 | 45 | |
martinale | 0:425c87a33e63 | 46 | |
martinale | 0:425c87a33e63 | 47 | /* |
martinale | 0:425c87a33e63 | 48 | class BtnEventM02 : public BtnEventM0 |
martinale | 0:425c87a33e63 | 49 | { |
martinale | 0:425c87a33e63 | 50 | public: |
martinale | 0:425c87a33e63 | 51 | BtnEventM02(PinName pin) : BtnEventM0(pin) { |
martinale | 0:425c87a33e63 | 52 | _tm.stop(); |
martinale | 0:425c87a33e63 | 53 | _tm.reset(); |
martinale | 0:425c87a33e63 | 54 | _state=1; |
martinale | 0:425c87a33e63 | 55 | } |
martinale | 0:425c87a33e63 | 56 | |
martinale | 0:425c87a33e63 | 57 | void Init() { |
martinale | 0:425c87a33e63 | 58 | _isr.rise(this, &BtnEventM02::RisingISR); |
martinale | 0:425c87a33e63 | 59 | } |
martinale | 0:425c87a33e63 | 60 | |
martinale | 0:425c87a33e63 | 61 | void RisingISR() { |
martinale | 0:425c87a33e63 | 62 | if( !_isr.read() ) |
martinale | 0:425c87a33e63 | 63 | return; |
martinale | 0:425c87a33e63 | 64 | pressed = 1; |
martinale | 0:425c87a33e63 | 65 | _tm.start(); |
martinale | 0:425c87a33e63 | 66 | _state = 2; |
martinale | 0:425c87a33e63 | 67 | } |
martinale | 0:425c87a33e63 | 68 | |
martinale | 0:425c87a33e63 | 69 | void CheckButton() { |
martinale | 0:425c87a33e63 | 70 | if( _state==1 ) |
martinale | 0:425c87a33e63 | 71 | return; |
martinale | 0:425c87a33e63 | 72 | if( _state==2 ) { |
martinale | 0:425c87a33e63 | 73 | if( !_isr.read() ) { |
martinale | 0:425c87a33e63 | 74 | _state = 1; |
martinale | 0:425c87a33e63 | 75 | return; |
martinale | 0:425c87a33e63 | 76 | } |
martinale | 0:425c87a33e63 | 77 | if( _tm.read_ms()>500 ) { |
martinale | 0:425c87a33e63 | 78 | _tm.reset(); |
martinale | 0:425c87a33e63 | 79 | _state = 3; |
martinale | 0:425c87a33e63 | 80 | pressed = 1; |
martinale | 0:425c87a33e63 | 81 | } |
martinale | 0:425c87a33e63 | 82 | } else if( _state==3 ) { |
martinale | 0:425c87a33e63 | 83 | if( !_isr.read() ) { |
martinale | 0:425c87a33e63 | 84 | _state = 1; |
martinale | 0:425c87a33e63 | 85 | return; |
martinale | 0:425c87a33e63 | 86 | } |
martinale | 0:425c87a33e63 | 87 | if( _tm.read_ms()>100 ) { |
martinale | 0:425c87a33e63 | 88 | _tm.reset(); |
martinale | 0:425c87a33e63 | 89 | _state = 3; |
martinale | 0:425c87a33e63 | 90 | pressed = 1; |
martinale | 0:425c87a33e63 | 91 | } |
martinale | 0:425c87a33e63 | 92 | } |
martinale | 0:425c87a33e63 | 93 | } |
martinale | 0:425c87a33e63 | 94 | private: |
martinale | 0:425c87a33e63 | 95 | int16_t _state; |
martinale | 0:425c87a33e63 | 96 | Timer _tm; |
martinale | 0:425c87a33e63 | 97 | }; |
martinale | 0:425c87a33e63 | 98 | */ |
martinale | 0:425c87a33e63 | 99 | |
martinale | 0:425c87a33e63 | 100 | class AnalogInHL : public AnalogIn |
martinale | 0:425c87a33e63 | 101 | { |
martinale | 0:425c87a33e63 | 102 | public: |
martinale | 0:425c87a33e63 | 103 | AnalogInHL(PinName pin) : AnalogIn(pin) { } |
martinale | 0:425c87a33e63 | 104 | int Read() { |
martinale | 0:425c87a33e63 | 105 | return read_u16()>>6; |
martinale | 0:425c87a33e63 | 106 | } |
martinale | 0:425c87a33e63 | 107 | }; |
martinale | 0:425c87a33e63 | 108 | |
martinale | 0:425c87a33e63 | 109 | class BtnEventM0S { |
martinale | 0:425c87a33e63 | 110 | public: |
martinale | 0:425c87a33e63 | 111 | BtnEventM0S(PinName pin) : _btn(pin) { } |
martinale | 0:425c87a33e63 | 112 | |
martinale | 0:425c87a33e63 | 113 | void Init() {} |
martinale | 0:425c87a33e63 | 114 | |
martinale | 0:425c87a33e63 | 115 | // Ist eine steigende Flanke aufgetreten ? |
martinale | 0:425c87a33e63 | 116 | int CheckFlag() |
martinale | 0:425c87a33e63 | 117 | { |
martinale | 0:425c87a33e63 | 118 | if( _btn ) |
martinale | 0:425c87a33e63 | 119 | { wait_ms(100); return 1; } |
martinale | 0:425c87a33e63 | 120 | else |
martinale | 0:425c87a33e63 | 121 | return 0; |
martinale | 0:425c87a33e63 | 122 | } |
martinale | 0:425c87a33e63 | 123 | |
martinale | 0:425c87a33e63 | 124 | protected: |
martinale | 0:425c87a33e63 | 125 | DigitalIn _btn; |
martinale | 0:425c87a33e63 | 126 | }; |