M0 Board

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BtnEventM0.h Source File

BtnEventM0.h

00001 
00002 
00003 class BtnEventM0
00004 {
00005 public:
00006     int16_t pressed;
00007 
00008     BtnEventM0(PinName pin) : _isr(pin) {
00009         pressed=0;
00010     }
00011 
00012     // Ist eine steigende Flanke aufgetreten ?
00013     int CheckFlag() {
00014         if( pressed ) {
00015             pressed=0;
00016             return 1;
00017         }
00018         return 0;
00019     }
00020 
00021     // 1..Button is pressed  else 0
00022     int CheckButton() {
00023         return _isr.read();
00024     }
00025 
00026     void Init() {
00027         _isr.rise(this, &BtnEventM0::RisingISR);
00028     }
00029 
00030     void RisingISR() {
00031         if( _isr.read() )
00032             pressed = 1;
00033     }
00034 protected:
00035     InterruptIn _isr;
00036 };
00037 
00038 /*
00039 class BtnEventM02 : public BtnEventM0
00040 {
00041 public:
00042     BtnEventM02(PinName pin) : BtnEventM0(pin) {
00043         _tm.stop();
00044         _tm.reset();
00045         _state=1;
00046     }
00047 
00048     void Init() {
00049         _isr.rise(this, &BtnEventM02::RisingISR);
00050     }
00051 
00052     void RisingISR() {
00053         if( !_isr.read() )
00054             return;
00055         pressed = 1;
00056         _tm.start();
00057         _state = 2;
00058     }
00059 
00060     void CheckButton() {
00061         if( _state==1 )
00062             return;
00063         if( _state==2 ) {
00064             if( !_isr.read() ) {
00065                 _state = 1;
00066                 return;
00067             }
00068             if( _tm.read_ms()>500 ) {
00069                 _tm.reset();
00070                 _state = 3;
00071                 pressed = 1;
00072             }
00073         } else if( _state==3 ) {
00074             if( !_isr.read() ) {
00075                 _state = 1;
00076                 return;
00077             }
00078             if( _tm.read_ms()>100 ) {
00079                 _tm.reset();
00080                 _state = 3;
00081                 pressed = 1;
00082             }
00083         }
00084     }
00085 private:
00086     int16_t _state;
00087     Timer _tm;
00088 };
00089 */
00090 
00091 class AnalogInHL : public AnalogIn
00092 {
00093 public:
00094     AnalogInHL(PinName pin) : AnalogIn(pin) { }
00095     int Read() {
00096         return read_u16()>>6;
00097     }
00098 };