push switc
Dependents: NJU6063_HelloWorld
Switch.cpp
00001 #include "mbed.h" 00002 #include "Switch.h" 00003 00004 Switch::Switch( PinName sw0, PinName sw1) 00005 : _sw0(sw0), _sw1(sw1) 00006 { 00007 } 00008 00009 void Switch::begin(void) 00010 { 00011 _sw0.mode(PullUp); 00012 _sw1.mode(PullUp); 00013 _swchecker.attach_us(this, &Switch::swcheck, 4000); 00014 } 00015 00016 void Switch::swcheck(void) 00017 { 00018 sw[0] = _sw0.read(); 00019 sw[1] = _sw1.read(); 00020 for (uint8_t i = 0; i < 2; i++) { 00021 buffer[i] = (buffer[i] << 1) | (0x01 & sw[i]); 00022 if (buffer[i] == 0x00) { 00023 swst[i] |= 0x01; 00024 if ((prev[i] &0x01) != (swst[i] & 0x01)) swst[i] |= 0x10; 00025 } else { 00026 swst[i] &= 0xfe; 00027 } 00028 if (buffer[i] == 0xff) { 00029 swst[i] |= 0x02; 00030 if ((prev[i] &0x02) != (swst[i] & 0x02)) swst[i] |= 0x20; 00031 } else { 00032 swst[i] &= 0xfd; 00033 } 00034 prev[i] = swst[i]; 00035 } 00036 } 00037 00038 uint8_t Switch::negedge(uint8_t no) 00039 { 00040 uint8_t st = 0; 00041 if (swst[no] & 0x10) 00042 st = 1; 00043 return (st); 00044 } 00045 00046 uint8_t Switch::posedge(uint8_t no) 00047 { 00048 uint8_t st = 0; 00049 if (swst[no] & 0x20) 00050 st = 1; 00051 return (st); 00052 } 00053 00054 void Switch::clear(uint8_t no) 00055 { 00056 swst[no] &= 0x0f; 00057 } 00058 00059 uint8_t Switch::level(uint8_t no) 00060 { 00061 uint8_t l; 00062 uint8_t st = swst[no] & 0x0f; 00063 if (st == 0x01) 00064 l = 0; 00065 else if (st == 0x02) 00066 l = 1; 00067 else 00068 l = 0xff; 00069 return (l); 00070 }
Generated on Mon Jul 18 2022 02:20:28 by
1.7.2