Claes Ekengren / Mbed 2 deprecated Measurement_system

Dependencies:   mbed

Committer:
CE
Date:
Thu Jan 06 19:01:44 2011 +0000
Revision:
0:0732b16d9a92
R1A

Who changed what in which revision?

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