A program to display an image on the uLCD-32PT display by 4D Systems

Dependencies:   mbed

Committer:
ms523
Date:
Sun Oct 03 15:47:25 2010 +0000
Revision:
0:fc4f3879f0e1

        

Who changed what in which revision?

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