Implements SimpleGUI events from a TouchScreen
Dependents: TouchScreenGUIDemo
TouchScreenEventSource.h@0:b250e56f3514, 2016-03-25 (annotated)
- Committer:
- duncanFrance
- Date:
- Fri Mar 25 13:48:33 2016 +0000
- Revision:
- 0:b250e56f3514
- Child:
- 1:6fb3545bddf7
Initial import
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 | 0:b250e56f3514 | 4 | #include "TouchScreen.h" |
duncanFrance | 0:b250e56f3514 | 5 | #include "EventSource.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 | 0:b250e56f3514 | 11 | #define TAP_TIMEOUT_MICROS 100000 |
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 | 0:b250e56f3514 | 15 | #define DOUBLE_TAP_TIMEOUT_MICROS 200000 |
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 | 0:b250e56f3514 | 20 | class TouchScreenEventSource : public EventSource { |
duncanFrance | 0:b250e56f3514 | 21 | |
duncanFrance | 0:b250e56f3514 | 22 | public: |
duncanFrance | 0:b250e56f3514 | 23 | TouchScreenEventSource(); |
duncanFrance | 0:b250e56f3514 | 24 | |
duncanFrance | 0:b250e56f3514 | 25 | virtual setDispatcher(EventDispatcher* dispatcher); |
duncanFrance | 0:b250e56f3514 | 26 | |
duncanFrance | 0:b250e56f3514 | 27 | void touchStartHandler(TouchPosition p); |
duncanFrance | 0:b250e56f3514 | 28 | void touchMoveHandler(TouchPosition p); |
duncanFrance | 0:b250e56f3514 | 29 | void touchEndHandler(TouchPosition p); |
duncanFrance | 0:b250e56f3514 | 30 | |
duncanFrance | 0:b250e56f3514 | 31 | private: |
duncanFrance | 0:b250e56f3514 | 32 | enum State { |
duncanFrance | 0:b250e56f3514 | 33 | Idle, |
duncanFrance | 0:b250e56f3514 | 34 | SingleTimer, |
duncanFrance | 0:b250e56f3514 | 35 | DoubleTimer |
duncanFrance | 0:b250e56f3514 | 36 | }; |
duncanFrance | 0:b250e56f3514 | 37 | |
duncanFrance | 0:b250e56f3514 | 38 | State _state; |
duncanFrance | 0:b250e56f3514 | 39 | Timeout _timeout; |
duncanFrance | 0:b250e56f3514 | 40 | EventDispatcher* _dispatcher; |
duncanFrance | 0:b250e56f3514 | 41 | uint8_t _state; |
duncanFrance | 0:b250e56f3514 | 42 | |
duncanFrance | 0:b250e56f3514 | 43 | }; |
duncanFrance | 0:b250e56f3514 | 44 | |
duncanFrance | 0:b250e56f3514 | 45 | #endif |