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.
ButtonIn.cpp
- Committer:
- evwijk
- Date:
- 2012-02-06
- Revision:
- 0:2e999fcd4c7b
- Child:
- 1:e806603f0088
File content as of revision 0:2e999fcd4c7b:
#include "ButtonIn.h"
ButtonIn::ButtonIn(PinName buttonPin) :
_button(buttonPin) {
_buttonCanPress = true;
_callback = NULL;
_callbackInstance = NULL;
_callbackMethod = NULL;
_button.rise(this, &ButtonIn::click);
}
void ButtonIn::attach(void (*method)(void)) {
_callback = method;
}
template<class T>
void attach(T* instance, void (T::*method)(void)) {
_callbackInstance = (ButtonInCallbackInstance *)instance;
_callbackMethod = (void (ButtonInCallbackInstance::*)(void))method;
}
void ButtonIn::click() {
if (_buttonCanPress) {
_buttonCanPress = false;
_buttonDownTimeout.attach(this, &ButtonIn::reset, 0.5);
}
}
void ButtonIn::call() {
if (_callback != NULL)
(*_callback)();
else
(_callbackInstance->*_callbackMethod)();
}
void ButtonIn::reset() {
_buttonCanPress = true;
}