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.
TouchPanel.h@1:007113101ef7, 2014-01-28 (annotated)
- Committer:
- MarioPoneder
- Date:
- Tue Jan 28 13:16:36 2014 +0000
- Revision:
- 1:007113101ef7
- Parent:
- 0:e38c94c549f4
good doc
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MarioPoneder | 0:e38c94c549f4 | 1 | #ifndef __TOUCHPANEL_H__ |
| MarioPoneder | 0:e38c94c549f4 | 2 | #define __TOUCHPANEL_H__ |
| MarioPoneder | 0:e38c94c549f4 | 3 | |
| MarioPoneder | 0:e38c94c549f4 | 4 | #include "mbed.h" |
| MarioPoneder | 0:e38c94c549f4 | 5 | #include "math.h" |
| MarioPoneder | 0:e38c94c549f4 | 6 | |
| MarioPoneder | 0:e38c94c549f4 | 7 | /******************************************************************************/ |
| MarioPoneder | 0:e38c94c549f4 | 8 | /****************************** TouchPanel ************************************/ |
| MarioPoneder | 0:e38c94c549f4 | 9 | /******************************************************************************/ |
| MarioPoneder | 0:e38c94c549f4 | 10 | |
| MarioPoneder | 0:e38c94c549f4 | 11 | /* The touch panel is polled in 50ms intervals. */ |
| MarioPoneder | 0:e38c94c549f4 | 12 | #define POLLING_INVERVAL 0.05f |
| MarioPoneder | 0:e38c94c549f4 | 13 | |
| MarioPoneder | 0:e38c94c549f4 | 14 | /* X or Y coordinate if no touch was detected. */ |
| MarioPoneder | 0:e38c94c549f4 | 15 | #define NO_TOUCH_VAL 0xFFFF |
| MarioPoneder | 0:e38c94c549f4 | 16 | |
| MarioPoneder | 0:e38c94c549f4 | 17 | /* If the absolute value of the difference between the values of coherent |
| MarioPoneder | 0:e38c94c549f4 | 18 | * +/- inputs pins does not exceed this value the panel was touched. */ |
| MarioPoneder | 0:e38c94c549f4 | 19 | #define TOUCH_THRESHOLD 0.005f |
| MarioPoneder | 0:e38c94c549f4 | 20 | |
| MarioPoneder | 0:e38c94c549f4 | 21 | /* The width of the TFT display in px. */ |
| MarioPoneder | 0:e38c94c549f4 | 22 | #define WIDTH 320 |
| MarioPoneder | 0:e38c94c549f4 | 23 | /* The height of the TFT display in px. */ |
| MarioPoneder | 0:e38c94c549f4 | 24 | #define HEIGHT 240 |
| MarioPoneder | 0:e38c94c549f4 | 25 | |
| MarioPoneder | 0:e38c94c549f4 | 26 | /* Border calibration constants. */ |
| MarioPoneder | 0:e38c94c549f4 | 27 | #define TOP 0.8f // Y coordinate |
| MarioPoneder | 0:e38c94c549f4 | 28 | #define BOTTOM 0.2f // Y coordindate |
| MarioPoneder | 0:e38c94c549f4 | 29 | #define LEFT 0.12f // X coordinate |
| MarioPoneder | 0:e38c94c549f4 | 30 | #define RIGHT 0.89f // X coordinate |
| MarioPoneder | 0:e38c94c549f4 | 31 | |
| MarioPoneder | 0:e38c94c549f4 | 32 | /***************************************************************************//** |
| MarioPoneder | 1:007113101ef7 | 33 | * @brief TouchPanel driver for the TFT color display MI0283QT-9A (320x240). |
| MarioPoneder | 1:007113101ef7 | 34 | * @author Mario Poneder |
| MarioPoneder | 1:007113101ef7 | 35 | * @date 28/01/2014 |
| MarioPoneder | 0:e38c94c549f4 | 36 | *******************************************************************************/ |
| MarioPoneder | 0:e38c94c549f4 | 37 | class TouchPanel |
| MarioPoneder | 0:e38c94c549f4 | 38 | { |
| MarioPoneder | 1:007113101ef7 | 39 | typedef void (*pTouchCallback_t)(unsigned short, unsigned short); |
| MarioPoneder | 1:007113101ef7 | 40 | |
| MarioPoneder | 0:e38c94c549f4 | 41 | private: |
| MarioPoneder | 0:e38c94c549f4 | 42 | |
| MarioPoneder | 0:e38c94c549f4 | 43 | PinName xPos; // X+ pin |
| MarioPoneder | 0:e38c94c549f4 | 44 | PinName xNeg; // X- pin |
| MarioPoneder | 0:e38c94c549f4 | 45 | PinName yPos; // Y+ pin |
| MarioPoneder | 0:e38c94c549f4 | 46 | PinName yNeg; // Y- pin |
| MarioPoneder | 0:e38c94c549f4 | 47 | |
| MarioPoneder | 0:e38c94c549f4 | 48 | DigitalOut *xPosOut; // X+ out |
| MarioPoneder | 0:e38c94c549f4 | 49 | DigitalOut *xNegOut; // X- out |
| MarioPoneder | 0:e38c94c549f4 | 50 | DigitalOut *yPosOut; // Y+ out |
| MarioPoneder | 0:e38c94c549f4 | 51 | DigitalOut *yNegOut; // Y- out |
| MarioPoneder | 0:e38c94c549f4 | 52 | |
| MarioPoneder | 0:e38c94c549f4 | 53 | AnalogIn *xPosIn; // X+ in |
| MarioPoneder | 0:e38c94c549f4 | 54 | AnalogIn *xNegIn; // X- in |
| MarioPoneder | 0:e38c94c549f4 | 55 | AnalogIn *yPosIn; // Y+ in |
| MarioPoneder | 0:e38c94c549f4 | 56 | AnalogIn *yNegIn; // Y- in |
| MarioPoneder | 0:e38c94c549f4 | 57 | |
| MarioPoneder | 0:e38c94c549f4 | 58 | Ticker pollPanelTicker; // Calls the PollPanel method in specified intervals. |
| MarioPoneder | 0:e38c94c549f4 | 59 | pTouchCallback_t touchCallbackFunction; |
| MarioPoneder | 0:e38c94c549f4 | 60 | bool xy; |
| MarioPoneder | 0:e38c94c549f4 | 61 | |
| MarioPoneder | 0:e38c94c549f4 | 62 | void PrepareYRead(void); |
| MarioPoneder | 0:e38c94c549f4 | 63 | void PrepareXRead(void); |
| MarioPoneder | 0:e38c94c549f4 | 64 | void PollPanel(void); |
| MarioPoneder | 0:e38c94c549f4 | 65 | |
| MarioPoneder | 0:e38c94c549f4 | 66 | public: |
| MarioPoneder | 1:007113101ef7 | 67 | |
| MarioPoneder | 0:e38c94c549f4 | 68 | TouchPanel(PinName xPos, PinName xNeg, PinName yPos, PinName yNeg); |
| MarioPoneder | 0:e38c94c549f4 | 69 | void SetTouchCallbackFunction(pTouchCallback_t touchCallbackFunction); |
| MarioPoneder | 0:e38c94c549f4 | 70 | }; |
| MarioPoneder | 0:e38c94c549f4 | 71 | |
| MarioPoneder | 0:e38c94c549f4 | 72 | #endif /* __TOUCHPANEL_H__ */ |