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