![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
M0 Board
BtnEventM0.h@0:efbd818aa4fe, 2018-01-18 (annotated)
- Committer:
- FlorianMaier
- Date:
- Thu Jan 18 12:08:08 2018 +0000
- Revision:
- 0:efbd818aa4fe
Fahrradleuchte m0Board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
FlorianMaier | 0:efbd818aa4fe | 1 | |
FlorianMaier | 0:efbd818aa4fe | 2 | |
FlorianMaier | 0:efbd818aa4fe | 3 | class BtnEventM0 |
FlorianMaier | 0:efbd818aa4fe | 4 | { |
FlorianMaier | 0:efbd818aa4fe | 5 | public: |
FlorianMaier | 0:efbd818aa4fe | 6 | int16_t pressed; |
FlorianMaier | 0:efbd818aa4fe | 7 | |
FlorianMaier | 0:efbd818aa4fe | 8 | BtnEventM0(PinName pin) : _isr(pin) { |
FlorianMaier | 0:efbd818aa4fe | 9 | pressed=0; |
FlorianMaier | 0:efbd818aa4fe | 10 | } |
FlorianMaier | 0:efbd818aa4fe | 11 | |
FlorianMaier | 0:efbd818aa4fe | 12 | // Ist eine steigende Flanke aufgetreten ? |
FlorianMaier | 0:efbd818aa4fe | 13 | int CheckFlag() { |
FlorianMaier | 0:efbd818aa4fe | 14 | if( pressed ) { |
FlorianMaier | 0:efbd818aa4fe | 15 | pressed=0; |
FlorianMaier | 0:efbd818aa4fe | 16 | return 1; |
FlorianMaier | 0:efbd818aa4fe | 17 | } |
FlorianMaier | 0:efbd818aa4fe | 18 | return 0; |
FlorianMaier | 0:efbd818aa4fe | 19 | } |
FlorianMaier | 0:efbd818aa4fe | 20 | |
FlorianMaier | 0:efbd818aa4fe | 21 | // 1..Button is pressed else 0 |
FlorianMaier | 0:efbd818aa4fe | 22 | int CheckButton() { |
FlorianMaier | 0:efbd818aa4fe | 23 | return _isr.read(); |
FlorianMaier | 0:efbd818aa4fe | 24 | } |
FlorianMaier | 0:efbd818aa4fe | 25 | |
FlorianMaier | 0:efbd818aa4fe | 26 | void Init() { |
FlorianMaier | 0:efbd818aa4fe | 27 | _isr.rise(this, &BtnEventM0::RisingISR); |
FlorianMaier | 0:efbd818aa4fe | 28 | } |
FlorianMaier | 0:efbd818aa4fe | 29 | |
FlorianMaier | 0:efbd818aa4fe | 30 | void RisingISR() { |
FlorianMaier | 0:efbd818aa4fe | 31 | if( _isr.read() ) |
FlorianMaier | 0:efbd818aa4fe | 32 | pressed = 1; |
FlorianMaier | 0:efbd818aa4fe | 33 | } |
FlorianMaier | 0:efbd818aa4fe | 34 | protected: |
FlorianMaier | 0:efbd818aa4fe | 35 | InterruptIn _isr; |
FlorianMaier | 0:efbd818aa4fe | 36 | }; |
FlorianMaier | 0:efbd818aa4fe | 37 | |
FlorianMaier | 0:efbd818aa4fe | 38 | /* |
FlorianMaier | 0:efbd818aa4fe | 39 | class BtnEventM02 : public BtnEventM0 |
FlorianMaier | 0:efbd818aa4fe | 40 | { |
FlorianMaier | 0:efbd818aa4fe | 41 | public: |
FlorianMaier | 0:efbd818aa4fe | 42 | BtnEventM02(PinName pin) : BtnEventM0(pin) { |
FlorianMaier | 0:efbd818aa4fe | 43 | _tm.stop(); |
FlorianMaier | 0:efbd818aa4fe | 44 | _tm.reset(); |
FlorianMaier | 0:efbd818aa4fe | 45 | _state=1; |
FlorianMaier | 0:efbd818aa4fe | 46 | } |
FlorianMaier | 0:efbd818aa4fe | 47 | |
FlorianMaier | 0:efbd818aa4fe | 48 | void Init() { |
FlorianMaier | 0:efbd818aa4fe | 49 | _isr.rise(this, &BtnEventM02::RisingISR); |
FlorianMaier | 0:efbd818aa4fe | 50 | } |
FlorianMaier | 0:efbd818aa4fe | 51 | |
FlorianMaier | 0:efbd818aa4fe | 52 | void RisingISR() { |
FlorianMaier | 0:efbd818aa4fe | 53 | if( !_isr.read() ) |
FlorianMaier | 0:efbd818aa4fe | 54 | return; |
FlorianMaier | 0:efbd818aa4fe | 55 | pressed = 1; |
FlorianMaier | 0:efbd818aa4fe | 56 | _tm.start(); |
FlorianMaier | 0:efbd818aa4fe | 57 | _state = 2; |
FlorianMaier | 0:efbd818aa4fe | 58 | } |
FlorianMaier | 0:efbd818aa4fe | 59 | |
FlorianMaier | 0:efbd818aa4fe | 60 | void CheckButton() { |
FlorianMaier | 0:efbd818aa4fe | 61 | if( _state==1 ) |
FlorianMaier | 0:efbd818aa4fe | 62 | return; |
FlorianMaier | 0:efbd818aa4fe | 63 | if( _state==2 ) { |
FlorianMaier | 0:efbd818aa4fe | 64 | if( !_isr.read() ) { |
FlorianMaier | 0:efbd818aa4fe | 65 | _state = 1; |
FlorianMaier | 0:efbd818aa4fe | 66 | return; |
FlorianMaier | 0:efbd818aa4fe | 67 | } |
FlorianMaier | 0:efbd818aa4fe | 68 | if( _tm.read_ms()>500 ) { |
FlorianMaier | 0:efbd818aa4fe | 69 | _tm.reset(); |
FlorianMaier | 0:efbd818aa4fe | 70 | _state = 3; |
FlorianMaier | 0:efbd818aa4fe | 71 | pressed = 1; |
FlorianMaier | 0:efbd818aa4fe | 72 | } |
FlorianMaier | 0:efbd818aa4fe | 73 | } else if( _state==3 ) { |
FlorianMaier | 0:efbd818aa4fe | 74 | if( !_isr.read() ) { |
FlorianMaier | 0:efbd818aa4fe | 75 | _state = 1; |
FlorianMaier | 0:efbd818aa4fe | 76 | return; |
FlorianMaier | 0:efbd818aa4fe | 77 | } |
FlorianMaier | 0:efbd818aa4fe | 78 | if( _tm.read_ms()>100 ) { |
FlorianMaier | 0:efbd818aa4fe | 79 | _tm.reset(); |
FlorianMaier | 0:efbd818aa4fe | 80 | _state = 3; |
FlorianMaier | 0:efbd818aa4fe | 81 | pressed = 1; |
FlorianMaier | 0:efbd818aa4fe | 82 | } |
FlorianMaier | 0:efbd818aa4fe | 83 | } |
FlorianMaier | 0:efbd818aa4fe | 84 | } |
FlorianMaier | 0:efbd818aa4fe | 85 | private: |
FlorianMaier | 0:efbd818aa4fe | 86 | int16_t _state; |
FlorianMaier | 0:efbd818aa4fe | 87 | Timer _tm; |
FlorianMaier | 0:efbd818aa4fe | 88 | }; |
FlorianMaier | 0:efbd818aa4fe | 89 | */ |
FlorianMaier | 0:efbd818aa4fe | 90 | |
FlorianMaier | 0:efbd818aa4fe | 91 | class AnalogInHL : public AnalogIn |
FlorianMaier | 0:efbd818aa4fe | 92 | { |
FlorianMaier | 0:efbd818aa4fe | 93 | public: |
FlorianMaier | 0:efbd818aa4fe | 94 | AnalogInHL(PinName pin) : AnalogIn(pin) { } |
FlorianMaier | 0:efbd818aa4fe | 95 | int Read() { |
FlorianMaier | 0:efbd818aa4fe | 96 | return read_u16()>>6; |
FlorianMaier | 0:efbd818aa4fe | 97 | } |
FlorianMaier | 0:efbd818aa4fe | 98 | }; |