A debouncing InterruptIn wrapper
Embed:
(wiki syntax)
Show/hide line numbers
ButtonIn.h
00001 /* 00002 ButtonIn is a debouncing InterruptIn class for mbed (http://mbed.org). 00003 00004 Copyright (C) 2012 Erik van Wijk (http://mbed.org/users/evwijk/) 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include "mbed.h" 00021 00022 #ifndef _ButtonIn_ 00023 #define _ButtonIn_ 00024 00025 class ButtonInCallbackInstance; 00026 00027 class ButtonIn { 00028 00029 private: 00030 InterruptIn _button; 00031 Timeout _buttonDownTimeout; 00032 00033 volatile bool _buttonCanPress; 00034 void (*_callback)(void); 00035 ButtonInCallbackInstance *_callbackInstance; 00036 void (ButtonInCallbackInstance::*_callbackMethod)(void); 00037 00038 void click(); 00039 void call(); 00040 void reset(); 00041 00042 00043 public: 00044 // ******************************************************************************** 00045 // * Constructor 00046 // * 00047 // * @param buttonPin The pin which is connected to the button. 00048 // ******************************************************************************** 00049 ButtonIn(PinName buttonPin); 00050 00051 // ******************************************************************************** 00052 // * Attaches the method to be called when the button is pressed. 00053 // * 00054 // * @param method A reference to the method to be called. 00055 // ******************************************************************************** 00056 void attach(void (*method)(void) = 0); 00057 00058 // ******************************************************************************** 00059 // * Attaches the method to be called when the button is pressed. 00060 // * 00061 // * @param instance A reference to the instance of the class containing the 00062 // * method to be called. 00063 // * @param method A reference to the method to be called. 00064 // ******************************************************************************** 00065 template<class T> 00066 void attach(T* instance, void (T::*method)(void)); 00067 00068 00069 // ******************************************************************************** 00070 // * The time in milliseconds in which the button can not be pressed again. 00071 // * 00072 // * @default 20ms 00073 // ******************************************************************************** 00074 int timeout; 00075 }; 00076 00077 #endif
Generated on Wed Jul 13 2022 17:31:24 by 1.7.2