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.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
PinDetect.cpp
00001 /* 00002 by Michael Shimniok 00003 00004 based on PinDetect Copyright (c) 2010 Andy Kirkham 00005 00006 Permission is hereby granted, free of charge, to any person obtaining a copy 00007 of this software and associated documentation files (the "Software"), to deal 00008 in the Software without restriction, including without limitation the rights 00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 copies of the Software, and to permit persons to whom the Software is 00011 furnished to do so, subject to the following conditions: 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 THE SOFTWARE. 00023 */ 00024 00025 #if 0 00026 00027 #include "PinDetect.h" 00028 00029 /** initialise class */ 00030 void PinDetect::init(PinName p, PinMode m) { 00031 _sampleTime = PINDETECT_SAMPLE_PERIOD; 00032 _samplesTillAssert = PINDETECT_ASSERT_COUNT; 00033 _samplesTillHeld = 0; 00034 _samplesTillAssertReload = PINDETECT_ASSERT_COUNT; 00035 _samplesTillHeldReload = PINDETECT_HOLD_COUNT; 00036 _assertValue = PINDETECT_PIN_ASSTERED; 00037 00038 _in = new DigitalIn( p ); 00039 _in->mode( m ); 00040 _prevState = _in->read(); 00041 _ticker = new Ticker; 00042 } 00043 00044 00045 void PinDetect::isr(void) { 00046 /* 00047 int currentState = _in->read(); 00048 00049 if ( currentState != _prevState ) { 00050 if ( _samplesTillAssert == 0 ) { 00051 _prevState = currentState; 00052 _samplesTillHeld = _samplesTillHeldReload; 00053 if ( currentState == _assertValue ) 00054 _callbackAsserted.call(); 00055 else 00056 _callbackDeasserted.call(); 00057 } 00058 else { 00059 _samplesTillAssert--; 00060 } 00061 } 00062 else { 00063 _samplesTillAssert = _samplesTillAssertReload; 00064 } 00065 00066 if ( _samplesTillHeld ) { 00067 if ( _prevState == currentState ) { 00068 _samplesTillHeld--; 00069 if ( _samplesTillHeld == 0 ) { 00070 if ( currentState == _assertValue ) 00071 _callbackAssertedHeld.call(); 00072 else 00073 _callbackDeassertedHeld.call(); 00074 } 00075 } 00076 else { 00077 _samplesTillHeld = 0; 00078 } 00079 } 00080 */ 00081 } 00082 00083 00084 PinDetect::PinDetect(PinName p) { 00085 init( p, PullDown ); 00086 } 00087 00088 PinDetect::PinDetect(PinName p, PinMode m) { 00089 init( p, m ); 00090 } 00091 00092 PinDetect::~PinDetect() { 00093 if ( _ticker ) delete( _ticker ); 00094 if ( _in ) delete( _in ); 00095 } 00096 00097 void PinDetect::setSampleFrequency(int i) { 00098 _sampleTime = i; 00099 _prevState = _in->read(); 00100 //_ticker->attach_us( this, &PinDetect::isr, _sampleTime ); 00101 } 00102 00103 void PinDetect::setAssertValue (int i) { 00104 _assertValue = i & 1; 00105 } 00106 00107 void PinDetect::setSamplesTillAssert(int i) { 00108 _samplesTillAssertReload = i; 00109 } 00110 00111 void PinDetect::setSamplesTillHeld(int i) { 00112 _samplesTillHeldReload = i; 00113 } 00114 00115 void PinDetect::mode(PinMode m) { 00116 _in->mode( m ); 00117 } 00118 00119 void PinDetect::attach_asserted(Callback function) { 00120 _callbackAsserted = function; 00121 } 00122 00123 template<typename T> 00124 void PinDetect::attach_asserted(T *object, void (T::*member)(void)) { 00125 // _callbackAsserted.attach( object, member ); 00126 } 00127 00128 void PinDetect::attach_deasserted(void (*function)(void)) { 00129 // _callbackDeasserted.attach( function ); 00130 } 00131 00132 template<typename T> 00133 void PinDetect::attach_deasserted(T *object, void (T::*member)(void)) { 00134 // _callbackDeasserted.attach( object, member ); 00135 } 00136 00137 void PinDetect::attach_asserted_held(void (*function)(void)) { 00138 // _callbackAssertedHeld.attach( function ); 00139 } 00140 template<typename T> 00141 void PinDetect::attach_asserted_held(T *object, void (T::*member)(void)) { 00142 // _callbackAssertedHeld.attach( object, member ); 00143 } 00144 00145 void PinDetect::attach_deasserted_held(void (*function)(void)) { 00146 // _callbackDeassertedHeld.attach( function ); 00147 } 00148 00149 template<typename T> 00150 void PinDetect::attach_deasserted_held(T *object, void (T::*member)(void)) { 00151 // _callbackDeassertedHeld.attach( object, member ); 00152 } 00153 00154 #endif
Generated on Tue Jul 12 2022 21:36:19 by
1.7.2