Implements SimpleGUI events from a TouchScreen
Dependents: TouchScreenGUIDemo
TouchScreenEventSource.h@2:0c8196ec23e4, 2016-03-27 (annotated)
- Committer:
- duncanFrance
- Date:
- Sun Mar 27 14:47:27 2016 +0000
- Revision:
- 2:0c8196ec23e4
- Parent:
- 1:6fb3545bddf7
- Child:
- 3:45777fe81448
Increased tap/double-tap delays;
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 | #include "TouchEvents.h" |
duncanFrance | 0:b250e56f3514 | 7 | |
duncanFrance | 0:b250e56f3514 | 8 | /** |
duncanFrance | 0:b250e56f3514 | 9 | * If the time between a touchStart and touchEnd is less than this value, issue a tap event |
duncanFrance | 0:b250e56f3514 | 10 | **/ |
duncanFrance | 2:0c8196ec23e4 | 11 | #define TAP_TIMEOUT_MICROS 150000 |
duncanFrance | 0:b250e56f3514 | 12 | /** |
duncanFrance | 0:b250e56f3514 | 13 | * If two taps in succession were detected within this time, issue a double-tap event |
duncanFrance | 0:b250e56f3514 | 14 | **/ |
duncanFrance | 2:0c8196ec23e4 | 15 | #define DOUBLE_TAP_TIMEOUT_MICROS 250000 |
duncanFrance | 0:b250e56f3514 | 16 | |
duncanFrance | 0:b250e56f3514 | 17 | // This class takes raw touch screen eents and turns them into events suitable for dispatch |
duncanFrance | 0:b250e56f3514 | 18 | // by the SimpleGUI EventDispatcher |
duncanFrance | 0:b250e56f3514 | 19 | |
duncanFrance | 1:6fb3545bddf7 | 20 | class TouchScreenEventSource : public EventSource |
duncanFrance | 1:6fb3545bddf7 | 21 | { |
duncanFrance | 1:6fb3545bddf7 | 22 | |
duncanFrance | 1:6fb3545bddf7 | 23 | public: |
duncanFrance | 1:6fb3545bddf7 | 24 | TouchScreenEventSource(TouchScreen* touchScreen, EventDispatcher* dispatcher); |
duncanFrance | 1:6fb3545bddf7 | 25 | |
duncanFrance | 1:6fb3545bddf7 | 26 | void touchStartHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 27 | void touchMoveHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 28 | void touchEndHandler(TouchPosition p); |
duncanFrance | 1:6fb3545bddf7 | 29 | |
duncanFrance | 1:6fb3545bddf7 | 30 | private: |
duncanFrance | 1:6fb3545bddf7 | 31 | TouchScreen* _touchScreen; |
duncanFrance | 0:b250e56f3514 | 32 | Timeout _timeout; |
duncanFrance | 1:6fb3545bddf7 | 33 | |
duncanFrance | 1:6fb3545bddf7 | 34 | enum State { |
duncanFrance | 1:6fb3545bddf7 | 35 | Idle, |
duncanFrance | 1:6fb3545bddf7 | 36 | SingleTimer, |
duncanFrance | 1:6fb3545bddf7 | 37 | DoubleTimer |
duncanFrance | 1:6fb3545bddf7 | 38 | }; |
duncanFrance | 1:6fb3545bddf7 | 39 | |
duncanFrance | 1:6fb3545bddf7 | 40 | volatile State _state; |
duncanFrance | 1:6fb3545bddf7 | 41 | |
duncanFrance | 1:6fb3545bddf7 | 42 | void _timeoutHandler(); |
duncanFrance | 0:b250e56f3514 | 43 | }; |
duncanFrance | 0:b250e56f3514 | 44 | |
duncanFrance | 0:b250e56f3514 | 45 | #endif |