Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MIP8f_FRDM_sample by
StateSW.cpp
00001 #include "StateSW.h" 00002 #include "mbed.h" 00003 00004 StateSW::StateSW(PinName SWPin) : _SW(SWPin) {} 00005 00006 void StateSW::Enable(int StateNum, int NoiseCancel, int OpenTime) { // _PRSCNT -- unit [times] ,_OPNCNT -- unit [s] 00007 _STATENUM = StateNum; 00008 _REPEAT = NoiseCancel; 00009 _OPNCNT = OpenTime; 00010 _preSW = 1; 00011 _PressCount= 0; 00012 _IfCntOpen = 0; 00013 _IfCntClose= 0; 00014 _IfCntState= 0; 00015 _IfAtTime = 0; 00016 00017 _StateCounter.attach(this, &StateSW::_SeekPress, 0.05); // Ticker[s] 00018 } 00019 00020 int StateSW::State(void){ 00021 return _State; 00022 } 00023 00024 bool StateSW::IfAtTime(void){ 00025 return _IfAtTime; 00026 } 00027 00028 void StateSW::IfCntState(bool IfCntState){ 00029 _IfCntState = IfCntState; 00030 } 00031 00032 void StateSW::IfCntClose(bool IfCntClose){ 00033 _IfCntClose = IfCntClose; 00034 if(_IfCntClose == 0 ){ 00035 _Timer_SW.stop(); 00036 _Timer_SW.reset(); 00037 } 00038 } 00039 void StateSW::IfCntOpen(bool IfCntOpen){ 00040 _IfCntOpen = IfCntOpen; 00041 if(_IfCntOpen == 0 ){ 00042 _Timer_SW.stop(); 00043 _Timer_SW.reset(); 00044 } 00045 } 00046 00047 /* 00048 void StateSW::Reset(void){ 00049 00050 } 00051 bool StateSW::IfOnetime(void){ 00052 if(IfOnetime==1){ 00053 IfOnetime = 0; 00054 return 1; 00055 } 00056 else return 0; 00057 } 00058 */ 00059 void StateSW::_SeekPress(void) { // instead of InterruptIn -- for against noise 00060 if(_preSW != _SW) _PressCount++; 00061 else _PressCount=0; 00062 if(_PressCount > _REPEAT ) { 00063 if(_SW) StateSW::_rise(); 00064 else StateSW::_fall(); 00065 _preSW = _SW; 00066 _PressCount = 0; 00067 } 00068 if(_Timer_SW.read() > _OPNCNT){ 00069 _Timer_SW.stop(); 00070 _Timer_SW.reset(); 00071 _IfAtTime =1; 00072 } 00073 } 00074 00075 void StateSW::_fall(void) { 00076 if(_IfCntOpen == 1 ){ 00077 _Timer_SW.stop(); 00078 _Timer_SW.reset(); 00079 } 00080 if(_IfCntClose== 1 ) _Timer_SW.start(); 00081 } 00082 00083 void StateSW::_rise(void) { 00084 if(_IfCntOpen == 1 ) _Timer_SW.start(); 00085 if(_IfCntClose== 1 ){ 00086 _Timer_SW.stop(); 00087 _Timer_SW.reset(); 00088 } 00089 if(_IfCntState) { 00090 _State++; 00091 _State = _State%_STATENUM; 00092 // IfOnetime=1; 00093 } 00094 } 00095 00096
Generated on Wed Jul 13 2022 02:52:47 by
1.7.2
