Alexander Leber
/
m0_Test
lalalala
Embed:
(wiki syntax)
Show/hide line numbers
BtnEventM0.h
00001 00002 // V4.0 00003 00004 class BtnEventM0 { 00005 public: 00006 int16_t pressed; 00007 00008 BtnEventM0(PinName pin) : _isr(pin) 00009 { pressed=0; } 00010 00011 // Ist eine steigende Flanke aufgetreten ? 00012 int CheckFlag(); 00013 00014 // 1..Button is pressed else 0 00015 int CheckButton() 00016 { return _isr.read(); } 00017 00018 void Init(); 00019 // { _isr.rise(this,&BtnEventM0::RisingISR); } 00020 00021 void RisingISR(); 00022 00023 protected: 00024 InterruptIn _isr; 00025 }; 00026 00027 void BtnEventM0::Init() 00028 { _isr.rise(this,&BtnEventM0::RisingISR); } 00029 00030 void BtnEventM0::RisingISR() 00031 { 00032 if( _isr.read() ) 00033 pressed = 1; 00034 } 00035 00036 int BtnEventM0::CheckFlag() 00037 { 00038 if( pressed ) 00039 { pressed=0; return 1; } 00040 return 0; 00041 } 00042 00043 00044 00045 00046 00047 /* 00048 class BtnEventM02 : public BtnEventM0 00049 { 00050 public: 00051 BtnEventM02(PinName pin) : BtnEventM0(pin) { 00052 _tm.stop(); 00053 _tm.reset(); 00054 _state=1; 00055 } 00056 00057 void Init() { 00058 _isr.rise(this, &BtnEventM02::RisingISR); 00059 } 00060 00061 void RisingISR() { 00062 if( !_isr.read() ) 00063 return; 00064 pressed = 1; 00065 _tm.start(); 00066 _state = 2; 00067 } 00068 00069 void CheckButton() { 00070 if( _state==1 ) 00071 return; 00072 if( _state==2 ) { 00073 if( !_isr.read() ) { 00074 _state = 1; 00075 return; 00076 } 00077 if( _tm.read_ms()>500 ) { 00078 _tm.reset(); 00079 _state = 3; 00080 pressed = 1; 00081 } 00082 } else if( _state==3 ) { 00083 if( !_isr.read() ) { 00084 _state = 1; 00085 return; 00086 } 00087 if( _tm.read_ms()>100 ) { 00088 _tm.reset(); 00089 _state = 3; 00090 pressed = 1; 00091 } 00092 } 00093 } 00094 private: 00095 int16_t _state; 00096 Timer _tm; 00097 }; 00098 */ 00099 00100 class AnalogInHL : public AnalogIn 00101 { 00102 public: 00103 AnalogInHL(PinName pin) : AnalogIn(pin) { } 00104 int Read() { 00105 return read_u16()>>6; 00106 } 00107 }; 00108 00109 class BtnEventM0S { 00110 public: 00111 BtnEventM0S(PinName pin) : _btn(pin) { } 00112 00113 void Init() {} 00114 00115 // Ist eine steigende Flanke aufgetreten ? 00116 int CheckFlag() 00117 { 00118 if( _btn ) 00119 { wait_ms(100); return 1; } 00120 else 00121 return 0; 00122 } 00123 00124 protected: 00125 DigitalIn _btn; 00126 };
Generated on Tue Aug 9 2022 17:22:05 by 1.7.2