Implements SimpleGUI events from a TouchScreen
Dependents: TouchScreenGUIDemo
TouchScreenEventSource.h@5:e3084e17e8e6, 2016-05-28 (annotated)
- Committer:
- duncanFrance
- Date:
- Sat May 28 14:50:49 2016 +0000
- Revision:
- 5:e3084e17e8e6
- Parent:
- 4:0be0d6a61e90
Removed dependency on GUI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
duncanFrance | 0:b250e56f3514 | 1 | #ifndef SIMPLEGUI_TOUCH_SCREEN_TOUCH_SCREEN_EVENT_SOURCE_H |
duncanFrance | 0:b250e56f3514 | 2 | #define SIMPLEGUI_TOUCH_SCREEN_TOUCH_SCREEN_EVENT_SOURCE_H |
duncanFrance | 0:b250e56f3514 | 3 | |
duncanFrance | 1:6fb3545bddf7 | 4 | #include "SimpleGUI.h" |
duncanFrance | 0:b250e56f3514 | 5 | #include "TouchScreen.h" |
duncanFrance | 0:b250e56f3514 | 6 | |
duncanFrance | 0:b250e56f3514 | 7 | /** |
duncanFrance | 0:b250e56f3514 | 8 | * If the time between a touchStart and touchEnd is less than this value, issue a tap event |
duncanFrance | 0:b250e56f3514 | 9 | **/ |
duncanFrance | 2:0c8196ec23e4 | 10 | #define TAP_TIMEOUT_MICROS 150000 |
duncanFrance | 0:b250e56f3514 | 11 | /** |
duncanFrance | 0:b250e56f3514 | 12 | * If two taps in succession were detected within this time, issue a double-tap event |
duncanFrance | 0:b250e56f3514 | 13 | **/ |
duncanFrance | 2:0c8196ec23e4 | 14 | #define DOUBLE_TAP_TIMEOUT_MICROS 250000 |
duncanFrance | 0:b250e56f3514 | 15 | |
duncanFrance | 0:b250e56f3514 | 16 | // This class takes raw touch screen eents and turns them into events suitable for dispatch |
duncanFrance | 0:b250e56f3514 | 17 | // by the SimpleGUI EventDispatcher |
duncanFrance | 0:b250e56f3514 | 18 | |
duncanFrance | 1:6fb3545bddf7 | 19 | class TouchScreenEventSource : public EventSource |
duncanFrance | 1:6fb3545bddf7 | 20 | { |
duncanFrance | 1:6fb3545bddf7 | 21 | |
duncanFrance | 1:6fb3545bddf7 | 22 | public: |
duncanFrance | 5:e3084e17e8e6 | 23 | TouchScreenEventSource(TouchScreen* touchScreen, EventDispatcher* dispatcher); |
duncanFrance | 1:6fb3545bddf7 | 24 | |
duncanFrance | 1:6fb3545bddf7 | 25 | void touchStartHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 26 | void touchMoveHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 27 | void touchEndHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 28 | |
duncanFrance | 1:6fb3545bddf7 | 29 | private: |
duncanFrance | 1:6fb3545bddf7 | 30 | TouchScreen* _touchScreen; |
duncanFrance | 0:b250e56f3514 | 31 | Timeout _timeout; |
duncanFrance | 1:6fb3545bddf7 | 32 | |
duncanFrance | 1:6fb3545bddf7 | 33 | enum State { |
duncanFrance | 1:6fb3545bddf7 | 34 | Idle, |
duncanFrance | 1:6fb3545bddf7 | 35 | SingleTimer, |
duncanFrance | 1:6fb3545bddf7 | 36 | DoubleTimer |
duncanFrance | 1:6fb3545bddf7 | 37 | }; |
duncanFrance | 1:6fb3545bddf7 | 38 | |
duncanFrance | 1:6fb3545bddf7 | 39 | volatile State _state; |
duncanFrance | 1:6fb3545bddf7 | 40 | |
duncanFrance | 1:6fb3545bddf7 | 41 | void _timeoutHandler(); |
duncanFrance | 0:b250e56f3514 | 42 | }; |
duncanFrance | 0:b250e56f3514 | 43 | |
duncanFrance | 0:b250e56f3514 | 44 | #endif |