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.
TFT_4DGL_Touch.cpp@0:ab96794606df, 2010-12-27 (annotated)
- Committer:
- JLS
- Date:
- Mon Dec 27 20:41:27 2010 +0000
- Revision:
- 0:ab96794606df
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JLS | 0:ab96794606df | 1 | // |
| JLS | 0:ab96794606df | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
| JLS | 0:ab96794606df | 3 | // |
| JLS | 0:ab96794606df | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
| JLS | 0:ab96794606df | 5 | // |
| JLS | 0:ab96794606df | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
| JLS | 0:ab96794606df | 7 | // it under the terms of the GNU General Public License as published by |
| JLS | 0:ab96794606df | 8 | // the Free Software Foundation, either version 3 of the License, or |
| JLS | 0:ab96794606df | 9 | // (at your option) any later version. |
| JLS | 0:ab96794606df | 10 | // |
| JLS | 0:ab96794606df | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
| JLS | 0:ab96794606df | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| JLS | 0:ab96794606df | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| JLS | 0:ab96794606df | 14 | // GNU General Public License for more details. |
| JLS | 0:ab96794606df | 15 | // |
| JLS | 0:ab96794606df | 16 | // You should have received a copy of the GNU General Public License |
| JLS | 0:ab96794606df | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
| JLS | 0:ab96794606df | 18 | |
| JLS | 0:ab96794606df | 19 | #include "mbed.h" |
| JLS | 0:ab96794606df | 20 | #include "TFT_4DGL.h" |
| JLS | 0:ab96794606df | 21 | |
| JLS | 0:ab96794606df | 22 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 23 | void TFT_4DGL :: touch_mode(char mode) { // Send touch mode (WAIT, PRESS, RELEASE or MOVE) |
| JLS | 0:ab96794606df | 24 | |
| JLS | 0:ab96794606df | 25 | char command[2]= ""; |
| JLS | 0:ab96794606df | 26 | |
| JLS | 0:ab96794606df | 27 | command[0] = GETTOUCH; |
| JLS | 0:ab96794606df | 28 | command[1] = mode; |
| JLS | 0:ab96794606df | 29 | |
| JLS | 0:ab96794606df | 30 | writeCOMMAND(command, 2); |
| JLS | 0:ab96794606df | 31 | } |
| JLS | 0:ab96794606df | 32 | |
| JLS | 0:ab96794606df | 33 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 34 | void TFT_4DGL :: get_touch(int *x, int *y) { // Get the touch coordinates |
| JLS | 0:ab96794606df | 35 | |
| JLS | 0:ab96794606df | 36 | char command[2] = ""; |
| JLS | 0:ab96794606df | 37 | |
| JLS | 0:ab96794606df | 38 | command[0] = GETTOUCH; |
| JLS | 0:ab96794606df | 39 | command[1] = GETPOSITION; |
| JLS | 0:ab96794606df | 40 | |
| JLS | 0:ab96794606df | 41 | getTOUCH(command, 2, x, y); |
| JLS | 0:ab96794606df | 42 | } |
| JLS | 0:ab96794606df | 43 | |
| JLS | 0:ab96794606df | 44 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 45 | int TFT_4DGL :: touch_status(void) { // Get the touch screen status |
| JLS | 0:ab96794606df | 46 | |
| JLS | 0:ab96794606df | 47 | char command[2] = ""; |
| JLS | 0:ab96794606df | 48 | |
| JLS | 0:ab96794606df | 49 | command[0] = GETTOUCH; |
| JLS | 0:ab96794606df | 50 | command[1] = STATUS; |
| JLS | 0:ab96794606df | 51 | |
| JLS | 0:ab96794606df | 52 | return getSTATUS(command, 2); |
| JLS | 0:ab96794606df | 53 | } |
| JLS | 0:ab96794606df | 54 | |
| JLS | 0:ab96794606df | 55 | |
| JLS | 0:ab96794606df | 56 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 57 | void TFT_4DGL :: wait_touch(int delay) { // wait until touch within a delay in milliseconds |
| JLS | 0:ab96794606df | 58 | |
| JLS | 0:ab96794606df | 59 | char command[3]= ""; |
| JLS | 0:ab96794606df | 60 | |
| JLS | 0:ab96794606df | 61 | command[0] = WAITTOUCH; |
| JLS | 0:ab96794606df | 62 | |
| JLS | 0:ab96794606df | 63 | command[1] = (delay >> 8) & 0xFF; |
| JLS | 0:ab96794606df | 64 | command[2] = delay & 0xFF; |
| JLS | 0:ab96794606df | 65 | |
| JLS | 0:ab96794606df | 66 | writeCOMMAND(command, 3); |
| JLS | 0:ab96794606df | 67 | } |
| JLS | 0:ab96794606df | 68 | |
| JLS | 0:ab96794606df | 69 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 70 | void TFT_4DGL :: set_touch(int x1, int y1 , int x2, int y2) { // define touch area |
| JLS | 0:ab96794606df | 71 | |
| JLS | 0:ab96794606df | 72 | char command[9]= ""; |
| JLS | 0:ab96794606df | 73 | |
| JLS | 0:ab96794606df | 74 | command[0] = SETTOUCH; |
| JLS | 0:ab96794606df | 75 | |
| JLS | 0:ab96794606df | 76 | command[1] = (x1 >> 8) & 0xFF; |
| JLS | 0:ab96794606df | 77 | command[2] = x1 & 0xFF; |
| JLS | 0:ab96794606df | 78 | |
| JLS | 0:ab96794606df | 79 | command[3] = (y1 >> 8) & 0xFF; |
| JLS | 0:ab96794606df | 80 | command[4] = y1 & 0xFF; |
| JLS | 0:ab96794606df | 81 | |
| JLS | 0:ab96794606df | 82 | command[5] = (x2 >> 8) & 0xFF; |
| JLS | 0:ab96794606df | 83 | command[6] = x2 & 0xFF; |
| JLS | 0:ab96794606df | 84 | |
| JLS | 0:ab96794606df | 85 | command[7] = (y2 >> 8) & 0xFF; |
| JLS | 0:ab96794606df | 86 | command[8] = y2 & 0xFF; |
| JLS | 0:ab96794606df | 87 | |
| JLS | 0:ab96794606df | 88 | writeCOMMAND(command, 9); |
| JLS | 0:ab96794606df | 89 | } |
| JLS | 0:ab96794606df | 90 | |
| JLS | 0:ab96794606df | 91 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 92 | // There is no way to have the uLCD-32PT trigger an interrupt when touched. |
| JLS | 0:ab96794606df | 93 | // This function polls the screen and waits for a touch to regiester |
| JLS | 0:ab96794606df | 94 | //****************************************************************************************************** |
| JLS | 0:ab96794606df | 95 | void TFT_4DGL :: Pause_Until_Touch(int *x, int *y) { // Actually waits for a TouchScreen release! |
| JLS | 0:ab96794606df | 96 | |
| JLS | 0:ab96794606df | 97 | char TouchStatus = 0; //Initalise the TouchStatus as 0 = no touch activity |
| JLS | 0:ab96794606df | 98 | char command[2] = ""; |
| JLS | 0:ab96794606df | 99 | |
| JLS | 0:ab96794606df | 100 | do{ |
| JLS | 0:ab96794606df | 101 | TouchStatus = touch_status(); //Get the touchscreen status |
| JLS | 0:ab96794606df | 102 | wait(0.1); |
| JLS | 0:ab96794606df | 103 | }while (TouchStatus != 2); |
| JLS | 0:ab96794606df | 104 | |
| JLS | 0:ab96794606df | 105 | command[0] = GETTOUCH; |
| JLS | 0:ab96794606df | 106 | command[1] = GETPOSITION; |
| JLS | 0:ab96794606df | 107 | |
| JLS | 0:ab96794606df | 108 | getTOUCH(command, 2, x, y); |
| JLS | 0:ab96794606df | 109 | } |