Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
SimplifiedTouchListener.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 1:a5258871b33d
Method ramp scrolling improved, and more bitmaps moved to QSPI memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | #include "SimplifiedTouchListener.h" |
jmitc91516 | 1:a5258871b33d | 2 | |
jmitc91516 | 1:a5258871b33d | 3 | |
jmitc91516 | 1:a5258871b33d | 4 | |
jmitc91516 | 1:a5258871b33d | 5 | /* |
jmitc91516 | 1:a5258871b33d | 6 | This class handles the touch panel on the LPC4088. |
jmitc91516 | 1:a5258871b33d | 7 | |
jmitc91516 | 1:a5258871b33d | 8 | Unlike the original TouchListener class, all it does in response to the user touching the screen |
jmitc91516 | 1:a5258871b33d | 9 | is to raise a thread signal, nothing else. |
jmitc91516 | 1:a5258871b33d | 10 | */ |
jmitc91516 | 1:a5258871b33d | 11 | |
jmitc91516 | 1:a5258871b33d | 12 | // Note that SimplifiedTouchListener is a singleton - we do not need or want there to be more than one instance of it |
jmitc91516 | 1:a5258871b33d | 13 | // (there is only one board, and only one touch panel) |
jmitc91516 | 1:a5258871b33d | 14 | SimplifiedTouchListener * SimplifiedTouchListener::theSimplifiedTouchListener = NULL; |
jmitc91516 | 1:a5258871b33d | 15 | |
jmitc91516 | 1:a5258871b33d | 16 | #ifdef GET_TOUCH_COORDS_AT_TOUCH_TIME // defined in header |
jmitc91516 | 1:a5258871b33d | 17 | touch_coordinate_t SimplifiedTouchListener::touchCoords; |
jmitc91516 | 1:a5258871b33d | 18 | #endif // GET_TOUCH_COORDS_AT_TOUCH_TIME |
jmitc91516 | 1:a5258871b33d | 19 | |
jmitc91516 | 1:a5258871b33d | 20 | #ifdef MULTI_TOUCH_TECHNIQUE_5 |
jmitc91516 | 1:a5258871b33d | 21 | Timer SimplifiedTouchListener::touchTimer; |
jmitc91516 | 1:a5258871b33d | 22 | const uint32_t SimplifiedTouchListener::touchIntervalMilliSec = 500; // i.e. 0.5 second |
jmitc91516 | 1:a5258871b33d | 23 | #endif |
jmitc91516 | 1:a5258871b33d | 24 | |
jmitc91516 | 1:a5258871b33d | 25 | |
jmitc91516 | 1:a5258871b33d | 26 | // Singleton class - return the one and only instance, first creating it if necessary |
jmitc91516 | 1:a5258871b33d | 27 | SimplifiedTouchListener *SimplifiedTouchListener::GetInstance(osThreadId newAppThread, TouchPanel* newTouchPanel) |
jmitc91516 | 1:a5258871b33d | 28 | { |
jmitc91516 | 1:a5258871b33d | 29 | if (theSimplifiedTouchListener == NULL) { |
jmitc91516 | 1:a5258871b33d | 30 | theSimplifiedTouchListener = new SimplifiedTouchListener(newAppThread, newTouchPanel); |
jmitc91516 | 1:a5258871b33d | 31 | } |
jmitc91516 | 1:a5258871b33d | 32 | return theSimplifiedTouchListener; |
jmitc91516 | 1:a5258871b33d | 33 | } |
jmitc91516 | 1:a5258871b33d | 34 | |
jmitc91516 | 1:a5258871b33d | 35 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 36 | SimplifiedTouchListener::SimplifiedTouchListener(osThreadId newAppThread, TouchPanel* newTouchPanel) |
jmitc91516 | 1:a5258871b33d | 37 | { |
jmitc91516 | 1:a5258871b33d | 38 | gotTouchEvent = false; |
jmitc91516 | 1:a5258871b33d | 39 | |
jmitc91516 | 1:a5258871b33d | 40 | appThread = newAppThread; |
jmitc91516 | 1:a5258871b33d | 41 | touchPanel = newTouchPanel; |
jmitc91516 | 1:a5258871b33d | 42 | |
jmitc91516 | 1:a5258871b33d | 43 | #define DO_THE_ATTACH |
jmitc91516 | 1:a5258871b33d | 44 | #ifdef DO_THE_ATTACH |
jmitc91516 | 1:a5258871b33d | 45 | functionPointer.attach(&ListenerFunction); |
jmitc91516 | 1:a5258871b33d | 46 | touchPanel->setListener(&functionPointer); |
jmitc91516 | 1:a5258871b33d | 47 | #endif // DO_THE_ATTACH |
jmitc91516 | 1:a5258871b33d | 48 | |
jmitc91516 | 1:a5258871b33d | 49 | #ifdef MULTI_TOUCH_TECHNIQUE_5 |
jmitc91516 | 1:a5258871b33d | 50 | touchTimer.stop(); |
jmitc91516 | 1:a5258871b33d | 51 | touchTimer.reset(); |
jmitc91516 | 1:a5258871b33d | 52 | touchTimer.start(); |
jmitc91516 | 1:a5258871b33d | 53 | #endif |
jmitc91516 | 1:a5258871b33d | 54 | } |
jmitc91516 | 1:a5258871b33d | 55 | |
jmitc91516 | 1:a5258871b33d | 56 | |
jmitc91516 | 1:a5258871b33d | 57 | /* |
jmitc91516 | 1:a5258871b33d | 58 | This is the function that the system invokes whenever it sees that the user has touched the LPC4088 touch panel. |
jmitc91516 | 1:a5258871b33d | 59 | In response, we set a thread signal - nothing else. Whatever is waiting on this thread signal can then decide |
jmitc91516 | 1:a5258871b33d | 60 | how to respond to the touch event. |
jmitc91516 | 1:a5258871b33d | 61 | */ |
jmitc91516 | 1:a5258871b33d | 62 | void SimplifiedTouchListener::ListenerFunction(void) |
jmitc91516 | 1:a5258871b33d | 63 | { |
jmitc91516 | 1:a5258871b33d | 64 | #if defined MULTI_TOUCH_TECHNIQUE_5 |
jmitc91516 | 1:a5258871b33d | 65 | if(touchTimer.read_ms() > touchIntervalMilliSec) { |
jmitc91516 | 1:a5258871b33d | 66 | #endif |
jmitc91516 | 1:a5258871b33d | 67 | if (theSimplifiedTouchListener != NULL) { |
jmitc91516 | 1:a5258871b33d | 68 | theSimplifiedTouchListener->gotTouchEvent = true; |
jmitc91516 | 1:a5258871b33d | 69 | #ifdef GET_TOUCH_COORDS_AT_TOUCH_TIME // Make sure the touch coords match the current touch event |
jmitc91516 | 1:a5258871b33d | 70 | theSimplifiedTouchListener->touchPanel->read(touchCoords); // touchCoords passed by reference (see TouchPanel.h) |
jmitc91516 | 1:a5258871b33d | 71 | #endif // GET_TOUCH_COORDS_AT_TOUCH_TIME |
jmitc91516 | 1:a5258871b33d | 72 | osSignalSet(theSimplifiedTouchListener->appThread, TOUCH_EVENT); |
jmitc91516 | 1:a5258871b33d | 73 | } |
jmitc91516 | 1:a5258871b33d | 74 | #if defined MULTI_TOUCH_TECHNIQUE_5 |
jmitc91516 | 1:a5258871b33d | 75 | touchTimer.stop(); |
jmitc91516 | 1:a5258871b33d | 76 | touchTimer.reset(); |
jmitc91516 | 1:a5258871b33d | 77 | touchTimer.start(); |
jmitc91516 | 1:a5258871b33d | 78 | } |
jmitc91516 | 1:a5258871b33d | 79 | #endif |
jmitc91516 | 1:a5258871b33d | 80 | } |
jmitc91516 | 1:a5258871b33d | 81 | |
jmitc91516 | 1:a5258871b33d | 82 | /* |
jmitc91516 | 1:a5258871b33d | 83 | Tells the caller whether or not we got a touch event. |
jmitc91516 | 1:a5258871b33d | 84 | |
jmitc91516 | 1:a5258871b33d | 85 | Caller may have applied a timeout to his signal_wait, so when signal_wait returns, cannot tell |
jmitc91516 | 1:a5258871b33d | 86 | if it did so because it got the signal or because it timed out. Calling this function will tell him. |
jmitc91516 | 1:a5258871b33d | 87 | |
jmitc91516 | 1:a5258871b33d | 88 | Note that this is a 'once per touch event' call - we clear the 'got touch event' flag in this function. |
jmitc91516 | 1:a5258871b33d | 89 | Until the next touch event, subsequent calls will return false. |
jmitc91516 | 1:a5258871b33d | 90 | |
jmitc91516 | 1:a5258871b33d | 91 | If we got a touch event, we return the coordinates in the arguments provided. |
jmitc91516 | 1:a5258871b33d | 92 | If not, we do nothing to the arguments. |
jmitc91516 | 1:a5258871b33d | 93 | |
jmitc91516 | 1:a5258871b33d | 94 | Args: pointers to variables to contain the X, Y and Z touch coordinates (the touch panel returns all three) |
jmitc91516 | 1:a5258871b33d | 95 | |
jmitc91516 | 1:a5258871b33d | 96 | Return value: true if this is the first call after a touch event, false otherwise. |
jmitc91516 | 1:a5258871b33d | 97 | */ |
jmitc91516 | 1:a5258871b33d | 98 | bool SimplifiedTouchListener::GotTouchEvent(short *x, short *y, short *z) |
jmitc91516 | 1:a5258871b33d | 99 | { |
jmitc91516 | 1:a5258871b33d | 100 | if(gotTouchEvent) { |
jmitc91516 | 1:a5258871b33d | 101 | gotTouchEvent = false; |
jmitc91516 | 1:a5258871b33d | 102 | |
jmitc91516 | 1:a5258871b33d | 103 | #ifndef GET_TOUCH_COORDS_AT_TOUCH_TIME |
jmitc91516 | 1:a5258871b33d | 104 | touch_coordinate_t touchCoords; |
jmitc91516 | 1:a5258871b33d | 105 | touchPanel->read(touchCoords); // touchCoords passed by reference (see TouchPanel.h) |
jmitc91516 | 1:a5258871b33d | 106 | #endif // GET_TOUCH_COORDS_AT_TOUCH_TIME |
jmitc91516 | 1:a5258871b33d | 107 | // #else we have already got the coords, in the touch event listener function |
jmitc91516 | 1:a5258871b33d | 108 | |
jmitc91516 | 1:a5258871b33d | 109 | *x = touchCoords.x; |
jmitc91516 | 1:a5258871b33d | 110 | *y = touchCoords.y; |
jmitc91516 | 1:a5258871b33d | 111 | *z = touchCoords.z; |
jmitc91516 | 1:a5258871b33d | 112 | |
jmitc91516 | 1:a5258871b33d | 113 | return true; |
jmitc91516 | 1:a5258871b33d | 114 | } |
jmitc91516 | 1:a5258871b33d | 115 | |
jmitc91516 | 1:a5258871b33d | 116 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 117 | return false; |
jmitc91516 | 1:a5258871b33d | 118 | } |
jmitc91516 | 1:a5258871b33d | 119 | |
jmitc91516 | 1:a5258871b33d | 120 | |
jmitc91516 | 1:a5258871b33d | 121 | // static TouchListener members |
jmitc91516 | 1:a5258871b33d | 122 | FunctionPointer SimplifiedTouchListener::functionPointer; |
jmitc91516 | 1:a5258871b33d | 123 |