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.
Dependents: TouchScreenCalibrate TouchScreenGUIDemo
Revision 3:8b5fcf3857ac, committed 2016-05-17
- Comitter:
- duncanFrance
- Date:
- Tue May 17 16:28:08 2016 +0000
- Parent:
- 2:e5ea47fb1ede
- Commit message:
- Can now attach instance methods as callback handlers
Changed in this revision
| TouchScreen.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TouchScreen.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r e5ea47fb1ede -r 8b5fcf3857ac TouchScreen.cpp
--- a/TouchScreen.cpp Sun May 08 14:43:16 2016 +0000
+++ b/TouchScreen.cpp Tue May 17 16:28:08 2016 +0000
@@ -28,17 +28,17 @@
void TouchScreen::setTouchStartHandler(TouchCallbackHandler handler)
{
- _touchStartHandler = handler;
+ _touchStartHandler.attach(handler);
}
void TouchScreen::setTouchMoveHandler(TouchCallbackHandler handler)
{
- _touchMoveHandler = handler;
+ _touchMoveHandler.attach(handler);
}
void TouchScreen::setTouchEndHandler(TouchCallbackHandler handler)
{
- _touchEndHandler = handler;
+ _touchEndHandler.attach(handler);
}
void TouchScreen::setMovementTheshold(int thresholdInPixels) {
@@ -116,7 +116,7 @@
_currentPosition = _getPosition();
// Raise an event if we got a valid position
if(_currentPosition.valid && _touchStartHandler) {
- _touchStartHandler(_currentPosition);
+ _touchStartHandler.call(_currentPosition);
}
}
@@ -124,7 +124,7 @@
{
// Raise an event if we got a valid position
if(_currentPosition.valid && _touchEndHandler) {
- _touchEndHandler(_currentPosition);
+ _touchEndHandler.call(_currentPosition);
}
}
@@ -139,7 +139,7 @@
if(_touchMoveHandler && _moved(newPosition, _lastPosition)) {
_lastPosition = _currentPosition;
_currentPosition = newPosition;
- _touchMoveHandler(_currentPosition);
+ _touchMoveHandler.call(_currentPosition);
}
}
diff -r e5ea47fb1ede -r 8b5fcf3857ac TouchScreen.h
--- a/TouchScreen.h Sun May 08 14:43:16 2016 +0000
+++ b/TouchScreen.h Tue May 17 16:28:08 2016 +0000
@@ -66,18 +66,33 @@
* Register a handler which will be called every time a touch is detected on the screen
**/
void setTouchStartHandler(TouchCallbackHandler handler);
-
+
+ template<typename T>
+ void setTouchStartHandler(T* tptr, void (T::*mptr)(TouchPosition)) {
+ _touchStartHandler.attach(tptr, mptr);
+ }
+
/**
* Register a handler which will be called every time a movement greater than a given threshold is detected.
* You can set the threshold with the setMovementThreshold() method
**/
void setTouchMoveHandler(TouchCallbackHandler handler);
+ template<typename T>
+ void setTouchMoveHandler(T* tptr, void (T::*mptr)(TouchPosition)) {
+ _touchMoveHandler.attach(tptr, mptr);
+ }
+
/**
* Register a handler which will be called when a touch stops being detected
**/
void setTouchEndHandler(TouchCallbackHandler handler);
+ template<typename T>
+ void setTouchEndHandler(T* tptr, void (T::*mptr)(TouchPosition)) {
+ _touchEndHandler.attach(tptr, mptr);
+ }
+
/**
* Set the dimensions and orientation of the LCD screen
**/
@@ -136,11 +151,9 @@
TouchPosition _getPosition();
- TouchCallbackHandler _touchStartHandler;
- TouchCallbackHandler _touchMoveHandler;
- TouchCallbackHandler _touchEndHandler;
-
- FunctionPointer _f;
+ FunctionPointerArg1<void,TouchPosition> _touchStartHandler;
+ FunctionPointerArg1<void,TouchPosition> _touchMoveHandler;
+ FunctionPointerArg1<void,TouchPosition> _touchEndHandler;
Thread* _handlerThread;