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.
Diff: Button.cpp
- Revision:
- 1:3385a1ea4a7d
- Parent:
- 0:a39041955963
- Child:
- 3:03aea89f2a5c
--- a/Button.cpp Tue Feb 14 13:00:47 2017 +0000
+++ b/Button.cpp Tue Feb 14 13:22:07 2017 +0000
@@ -18,7 +18,7 @@
if (_prevState == 0) //First
{
_timer.start();
- if (_fireUpDown) _onButtonEvent(BUTTON_DOWN, _pinName);
+ if (_fireUpDown && _onButtonEvent != NULL) _onButtonEvent(BUTTON_DOWN, _pinName);
}
_autoRepeatStarter.detach();
if (_autoRepeatTime > 0) _autoRepeatStarter.attach(Callback<void()>(this, &Button::startAutoRepeat), (_longPressTime / 1000.0f));
@@ -30,8 +30,8 @@
_timer.stop();
_tickerAutoRepeat.detach();
_autoRepeatStarter.detach();
- if (_fireUpDown) _onButtonEvent(BUTTON_UP, _pinName);
- if (_prevState == 1)
+ if (_fireUpDown && _onButtonEvent != NULL) _onButtonEvent(BUTTON_UP, _pinName);
+ if (_prevState == 1 && _onButtonEvent != NULL)
{
if (_timer.read_ms() >= _longPressTime) //Long press
{
@@ -49,10 +49,10 @@
void Button::startAutoRepeat(void)
{
_tickerAutoRepeat.detach();
- if (_autoRepeatTime > 0) _tickerAutoRepeat.attach(Callback<void()>(this, &Button::autoRepeat), _autoRepeatTime);
+ if (_autoRepeatTime > 0) _tickerAutoRepeat.attach(Callback<void()>(this, &Button::autoRepeat), (_autoRepeatTime / 1000.0f));
}
void Button::autoRepeat(void)
{
- _onButtonEvent(BUTTON_PRESS, _pinName);
+ if (_onButtonEvent != NULL) _onButtonEvent(BUTTON_PRESS, _pinName);
}