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 Serial pc(USBTX,USBRX);
ms523 0:fc4f3879f0e1 23 DigitalOut led1(LED1), led2(LED2);
ms523 0:fc4f3879f0e1 24
ms523 0:fc4f3879f0e1 25 //******************************************************************************************************
ms523 0:fc4f3879f0e1 26 TFT_4DGL :: TFT_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), _rst(rst) { // Constructor
ms523 0:fc4f3879f0e1 27
ms523 0:fc4f3879f0e1 28 #if DEBUGMODE
ms523 0:fc4f3879f0e1 29 pc.baud(115200);
ms523 0:fc4f3879f0e1 30
ms523 0:fc4f3879f0e1 31 pc.printf("\n\n\n");
ms523 0:fc4f3879f0e1 32 pc.printf("********************\n\r");
ms523 0:fc4f3879f0e1 33 pc.printf("TFT_4DGL CONSTRUCTOR\n\r");
ms523 0:fc4f3879f0e1 34 pc.printf("********************\n\r");
ms523 0:fc4f3879f0e1 35 #endif
ms523 0:fc4f3879f0e1 36
ms523 0:fc4f3879f0e1 37 _rst = 1; // put RESET pin to high to start TFT screen
ms523 0:fc4f3879f0e1 38
ms523 0:fc4f3879f0e1 39 reset();
ms523 0:fc4f3879f0e1 40 autobaud(); // send autobaud command
ms523 0:fc4f3879f0e1 41 baudrate(256000); // set the initial baudrate to 256kbps - fastest supported by uLCD-32PT
ms523 0:fc4f3879f0e1 42 cls(); // clear screen
ms523 0:fc4f3879f0e1 43
ms523 0:fc4f3879f0e1 44 current_col = 0; // initial cursor col
ms523 0:fc4f3879f0e1 45 current_row = 0; // initial cursor row
ms523 0:fc4f3879f0e1 46 current_color = WHITE; // initial text color
ms523 0:fc4f3879f0e1 47 current_orientation = IS_PORTRAIT; // initial screen orientation
ms523 0:fc4f3879f0e1 48
ms523 0:fc4f3879f0e1 49 set_font(FONT_5X7); // initial font
ms523 0:fc4f3879f0e1 50 text_mode(TRANSPARENT); // initial text mode
ms523 0:fc4f3879f0e1 51 display_control(0x06,0x00); // initial Image control new format
ms523 0:fc4f3879f0e1 52 }
ms523 0:fc4f3879f0e1 53
ms523 0:fc4f3879f0e1 54 //******************************************************************************************************
ms523 0:fc4f3879f0e1 55 void TFT_4DGL :: writeBYTE(char c) { // send a BYTE command to screen
ms523 0:fc4f3879f0e1 56
ms523 0:fc4f3879f0e1 57 _cmd.putc(c);
ms523 0:fc4f3879f0e1 58
ms523 0:fc4f3879f0e1 59 #if DEBUGMODE
ms523 0:fc4f3879f0e1 60 pc.printf(" Char sent : 0x%02X ",c);
ms523 0:fc4f3879f0e1 61 pc.putc(c);
ms523 0:fc4f3879f0e1 62 pc.printf(" \n\r");
ms523 0:fc4f3879f0e1 63 #endif
ms523 0:fc4f3879f0e1 64
ms523 0:fc4f3879f0e1 65 }
ms523 0:fc4f3879f0e1 66
ms523 0:fc4f3879f0e1 67 //******************************************************************************************************
ms523 0:fc4f3879f0e1 68 void TFT_4DGL :: freeBUFFER(void) { // Clear serial buffer before writing command
ms523 0:fc4f3879f0e1 69
ms523 0:fc4f3879f0e1 70 while (_cmd.readable()) _cmd.getc(); // clear buffer garbage
ms523 0:fc4f3879f0e1 71 }
ms523 0:fc4f3879f0e1 72
ms523 0:fc4f3879f0e1 73 //******************************************************************************************************
ms523 0:fc4f3879f0e1 74 int TFT_4DGL :: writeCOMMAND(char *command, int number) { // send several BYTES making a command and return an answer
ms523 0:fc4f3879f0e1 75
ms523 0:fc4f3879f0e1 76 #if DEBUGMODE
ms523 0:fc4f3879f0e1 77 pc.printf("\n\r");
ms523 0:fc4f3879f0e1 78 pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
ms523 0:fc4f3879f0e1 79 #endif
ms523 0:fc4f3879f0e1 80 int i, resp = 0;
ms523 0:fc4f3879f0e1 81 freeBUFFER();
ms523 0:fc4f3879f0e1 82
ms523 0:fc4f3879f0e1 83 for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port
ms523 0:fc4f3879f0e1 84
ms523 0:fc4f3879f0e1 85 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 86 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
ms523 0:fc4f3879f0e1 87 switch (resp) {
ms523 0:fc4f3879f0e1 88 case ACK : // if OK return 1
ms523 0:fc4f3879f0e1 89 resp = 1;
ms523 0:fc4f3879f0e1 90 break;
ms523 0:fc4f3879f0e1 91 case NAK : // if NOK return -1
ms523 0:fc4f3879f0e1 92 resp = -1;
ms523 0:fc4f3879f0e1 93 break;
ms523 0:fc4f3879f0e1 94 default :
ms523 0:fc4f3879f0e1 95 resp = 0; // else return 0
ms523 0:fc4f3879f0e1 96 break;
ms523 0:fc4f3879f0e1 97 }
ms523 0:fc4f3879f0e1 98 #if DEBUGMODE
ms523 0:fc4f3879f0e1 99 pc.printf(" Answer received : %d\n\r",resp);
ms523 0:fc4f3879f0e1 100 #endif
ms523 0:fc4f3879f0e1 101
ms523 0:fc4f3879f0e1 102 return resp;
ms523 0:fc4f3879f0e1 103 }
ms523 0:fc4f3879f0e1 104
ms523 0:fc4f3879f0e1 105 //**************************************************************************
ms523 0:fc4f3879f0e1 106 void TFT_4DGL :: reset() { // Reset Screen
ms523 0:fc4f3879f0e1 107
ms523 0:fc4f3879f0e1 108 _rst = 0; // put RESET pin to low
ms523 0:fc4f3879f0e1 109 wait_ms(TEMPO); // wait a few milliseconds for command reception
ms523 0:fc4f3879f0e1 110 _rst = 1; // put RESET back to high
ms523 0:fc4f3879f0e1 111 wait(3); // wait 3s for screen to restart
ms523 0:fc4f3879f0e1 112
ms523 0:fc4f3879f0e1 113 freeBUFFER(); // clean buffer from possible garbage
ms523 0:fc4f3879f0e1 114 }
ms523 0:fc4f3879f0e1 115
ms523 0:fc4f3879f0e1 116 //**************************************************************************
ms523 0:fc4f3879f0e1 117 void TFT_4DGL :: autobaud() { // send AutoBaud command (9600)
ms523 0:fc4f3879f0e1 118 char command[1] = "";
ms523 0:fc4f3879f0e1 119 command[0] = AUTOBAUD;
ms523 0:fc4f3879f0e1 120 writeCOMMAND(command, 1);
ms523 0:fc4f3879f0e1 121 }
ms523 0:fc4f3879f0e1 122
ms523 0:fc4f3879f0e1 123 //**************************************************************************
ms523 0:fc4f3879f0e1 124 void TFT_4DGL :: cls() { // clear screen
ms523 0:fc4f3879f0e1 125 char command[1] = "";
ms523 0:fc4f3879f0e1 126 command[0] = CLS;
ms523 0:fc4f3879f0e1 127 writeCOMMAND(command, 1);
ms523 0:fc4f3879f0e1 128 }
ms523 0:fc4f3879f0e1 129
ms523 0:fc4f3879f0e1 130 //**************************************************************************
ms523 0:fc4f3879f0e1 131 void TFT_4DGL :: version() { // get API version
ms523 0:fc4f3879f0e1 132 char command[2] = "";
ms523 0:fc4f3879f0e1 133 command[0] = VERSION;
ms523 0:fc4f3879f0e1 134 command[1] = OFF;
ms523 0:fc4f3879f0e1 135 readVERSION(command, 2);
ms523 0:fc4f3879f0e1 136 }
ms523 0:fc4f3879f0e1 137
ms523 0:fc4f3879f0e1 138 //**************************************************************************
ms523 0:fc4f3879f0e1 139 void TFT_4DGL :: baudrate(long speed) { // set screen baud rate
ms523 0:fc4f3879f0e1 140 char command[2]= "";
ms523 0:fc4f3879f0e1 141 command[0] = BAUDRATE;
ms523 0:fc4f3879f0e1 142 switch (speed) {
ms523 0:fc4f3879f0e1 143 case 110 :
ms523 0:fc4f3879f0e1 144 command[1] = BAUD_110;
ms523 0:fc4f3879f0e1 145 break;
ms523 0:fc4f3879f0e1 146 case 300 :
ms523 0:fc4f3879f0e1 147 command[1] = BAUD_300;
ms523 0:fc4f3879f0e1 148 break;
ms523 0:fc4f3879f0e1 149 case 600 :
ms523 0:fc4f3879f0e1 150 command[1] = BAUD_600;
ms523 0:fc4f3879f0e1 151 break;
ms523 0:fc4f3879f0e1 152 case 1200 :
ms523 0:fc4f3879f0e1 153 command[1] = BAUD_1200;
ms523 0:fc4f3879f0e1 154 break;
ms523 0:fc4f3879f0e1 155 case 2400 :
ms523 0:fc4f3879f0e1 156 command[1] = BAUD_2400;
ms523 0:fc4f3879f0e1 157 break;
ms523 0:fc4f3879f0e1 158 case 4800 :
ms523 0:fc4f3879f0e1 159 command[1] = BAUD_4800;
ms523 0:fc4f3879f0e1 160 break;
ms523 0:fc4f3879f0e1 161 case 9600 :
ms523 0:fc4f3879f0e1 162 command[1] = BAUD_9600;
ms523 0:fc4f3879f0e1 163 break;
ms523 0:fc4f3879f0e1 164 case 14400 :
ms523 0:fc4f3879f0e1 165 command[1] = BAUD_14400;
ms523 0:fc4f3879f0e1 166 break;
ms523 0:fc4f3879f0e1 167 case 19200 :
ms523 0:fc4f3879f0e1 168 command[1] = BAUD_19200;
ms523 0:fc4f3879f0e1 169 break;
ms523 0:fc4f3879f0e1 170 case 31250 :
ms523 0:fc4f3879f0e1 171 command[1] = BAUD_31250;
ms523 0:fc4f3879f0e1 172 break;
ms523 0:fc4f3879f0e1 173 case 38400 :
ms523 0:fc4f3879f0e1 174 command[1] = BAUD_38400;
ms523 0:fc4f3879f0e1 175 break;
ms523 0:fc4f3879f0e1 176 case 56000 :
ms523 0:fc4f3879f0e1 177 command[1] = BAUD_56000;
ms523 0:fc4f3879f0e1 178 break;
ms523 0:fc4f3879f0e1 179 case 57600 :
ms523 0:fc4f3879f0e1 180 command[1] = BAUD_57600;
ms523 0:fc4f3879f0e1 181 break;
ms523 0:fc4f3879f0e1 182 case 115200 :
ms523 0:fc4f3879f0e1 183 command[1] = BAUD_115200;
ms523 0:fc4f3879f0e1 184 break;
ms523 0:fc4f3879f0e1 185 case 128000 :
ms523 0:fc4f3879f0e1 186 command[1] = BAUD_128000;
ms523 0:fc4f3879f0e1 187 break;
ms523 0:fc4f3879f0e1 188 case 256000 :
ms523 0:fc4f3879f0e1 189 command[1] = BAUD_256000;
ms523 0:fc4f3879f0e1 190 break;
ms523 0:fc4f3879f0e1 191 default :
ms523 0:fc4f3879f0e1 192 command[1] = BAUD_9600;
ms523 0:fc4f3879f0e1 193 speed = 9600;
ms523 0:fc4f3879f0e1 194 break;
ms523 0:fc4f3879f0e1 195 }
ms523 0:fc4f3879f0e1 196
ms523 0:fc4f3879f0e1 197 #if DEBUGMODE
ms523 0:fc4f3879f0e1 198 pc.printf("\n\r");
ms523 0:fc4f3879f0e1 199 pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
ms523 0:fc4f3879f0e1 200 #endif
ms523 0:fc4f3879f0e1 201
ms523 0:fc4f3879f0e1 202 int i, resp = 0;
ms523 0:fc4f3879f0e1 203 freeBUFFER();
ms523 0:fc4f3879f0e1 204
ms523 0:fc4f3879f0e1 205 if(speed==256000)
ms523 0:fc4f3879f0e1 206 speed=281000; //If baud rate is 256K comm at 281k - as instructed by 4DGL
ms523 0:fc4f3879f0e1 207
ms523 0:fc4f3879f0e1 208 for (i = 0; i <2; i++) writeBYTE(command[i]); // send command to serial port
ms523 0:fc4f3879f0e1 209 _cmd.baud(speed); // set mbed to same speed
ms523 0:fc4f3879f0e1 210
ms523 0:fc4f3879f0e1 211 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 212
ms523 0:fc4f3879f0e1 213 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
ms523 0:fc4f3879f0e1 214 switch (resp) {
ms523 0:fc4f3879f0e1 215 case ACK : // if OK return 1
ms523 0:fc4f3879f0e1 216 resp = 1;
ms523 0:fc4f3879f0e1 217 break;
ms523 0:fc4f3879f0e1 218 case NAK : // if NOK return -1
ms523 0:fc4f3879f0e1 219 resp = -1;
ms523 0:fc4f3879f0e1 220 break;
ms523 0:fc4f3879f0e1 221 default :
ms523 0:fc4f3879f0e1 222 resp = 0; // else return 0
ms523 0:fc4f3879f0e1 223 break;
ms523 0:fc4f3879f0e1 224 }
ms523 0:fc4f3879f0e1 225 #if DEBUGMODE
ms523 0:fc4f3879f0e1 226 pc.printf(" Baudrate reply received : %d\n\r",resp);
ms523 0:fc4f3879f0e1 227 #endif
ms523 0:fc4f3879f0e1 228 }
ms523 0:fc4f3879f0e1 229
ms523 0:fc4f3879f0e1 230 //******************************************************************************************************
ms523 0:fc4f3879f0e1 231 int TFT_4DGL :: readVERSION(char *command, int number) { // read screen info and populate data
ms523 0:fc4f3879f0e1 232
ms523 0:fc4f3879f0e1 233 int i, temp = 0, resp = 0;
ms523 0:fc4f3879f0e1 234 char response[5] = "";
ms523 0:fc4f3879f0e1 235
ms523 0:fc4f3879f0e1 236 freeBUFFER();
ms523 0:fc4f3879f0e1 237
ms523 0:fc4f3879f0e1 238 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
ms523 0:fc4f3879f0e1 239
ms523 0:fc4f3879f0e1 240 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 241
ms523 0:fc4f3879f0e1 242 while (_cmd.readable()) {
ms523 0:fc4f3879f0e1 243 temp = _cmd.getc();
ms523 0:fc4f3879f0e1 244 response[resp++] = (char)temp;
ms523 0:fc4f3879f0e1 245 }
ms523 0:fc4f3879f0e1 246 switch (resp) {
ms523 0:fc4f3879f0e1 247 case 5 : // if OK populate data and return 1
ms523 0:fc4f3879f0e1 248 type = response[0];
ms523 0:fc4f3879f0e1 249 revision = response[1];
ms523 0:fc4f3879f0e1 250 firmware = response[2];
ms523 0:fc4f3879f0e1 251 reserved1 = response[3];
ms523 0:fc4f3879f0e1 252 reserved2 = response[4];
ms523 0:fc4f3879f0e1 253 resp = 1;
ms523 0:fc4f3879f0e1 254 break;
ms523 0:fc4f3879f0e1 255 default :
ms523 0:fc4f3879f0e1 256 resp = 0; // else return 0
ms523 0:fc4f3879f0e1 257 break;
ms523 0:fc4f3879f0e1 258 }
ms523 0:fc4f3879f0e1 259 return resp;
ms523 0:fc4f3879f0e1 260 }
ms523 0:fc4f3879f0e1 261
ms523 0:fc4f3879f0e1 262 //****************************************************************************************************
ms523 0:fc4f3879f0e1 263 void TFT_4DGL :: background_color(int color) { // set screen background color
ms523 0:fc4f3879f0e1 264 char command[3]= ""; // input color is in 24bits like 0xRRGGBB
ms523 0:fc4f3879f0e1 265
ms523 0:fc4f3879f0e1 266 command[0] = BCKGDCOLOR;
ms523 0:fc4f3879f0e1 267
ms523 0:fc4f3879f0e1 268 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
ms523 0:fc4f3879f0e1 269 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
ms523 0:fc4f3879f0e1 270 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
ms523 0:fc4f3879f0e1 271
ms523 0:fc4f3879f0e1 272 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
ms523 0:fc4f3879f0e1 273 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
ms523 0:fc4f3879f0e1 274
ms523 0:fc4f3879f0e1 275 writeCOMMAND(command, 3);
ms523 0:fc4f3879f0e1 276 }
ms523 0:fc4f3879f0e1 277
ms523 0:fc4f3879f0e1 278 //****************************************************************************************************
ms523 0:fc4f3879f0e1 279 void TFT_4DGL :: display_control(char mode, char value) { // set screen mode to value
ms523 0:fc4f3879f0e1 280 char command[3]= "";
ms523 0:fc4f3879f0e1 281
ms523 0:fc4f3879f0e1 282 command[0] = DISPCONTROL;
ms523 0:fc4f3879f0e1 283 command[1] = mode;
ms523 0:fc4f3879f0e1 284 command[2] = value;
ms523 0:fc4f3879f0e1 285
ms523 0:fc4f3879f0e1 286 if (mode == ORIENTATION) {
ms523 0:fc4f3879f0e1 287 switch (value) {
ms523 0:fc4f3879f0e1 288 case LANDSCAPE :
ms523 0:fc4f3879f0e1 289 current_orientation = IS_LANDSCAPE;
ms523 0:fc4f3879f0e1 290 break;
ms523 0:fc4f3879f0e1 291 case LANDSCAPE_R :
ms523 0:fc4f3879f0e1 292 current_orientation = IS_LANDSCAPE;
ms523 0:fc4f3879f0e1 293 break;
ms523 0:fc4f3879f0e1 294 case PORTRAIT :
ms523 0:fc4f3879f0e1 295 current_orientation = IS_PORTRAIT;
ms523 0:fc4f3879f0e1 296 break;
ms523 0:fc4f3879f0e1 297 case PORTRAIT_R :
ms523 0:fc4f3879f0e1 298 current_orientation = IS_PORTRAIT;
ms523 0:fc4f3879f0e1 299 break;
ms523 0:fc4f3879f0e1 300 }
ms523 0:fc4f3879f0e1 301 set_font(current_font);
ms523 0:fc4f3879f0e1 302 }
ms523 0:fc4f3879f0e1 303 writeCOMMAND(command, 3);
ms523 0:fc4f3879f0e1 304
ms523 0:fc4f3879f0e1 305 }
ms523 0:fc4f3879f0e1 306
ms523 0:fc4f3879f0e1 307 //****************************************************************************************************
ms523 0:fc4f3879f0e1 308 void TFT_4DGL :: set_volume(char value) { // set sound volume to value
ms523 0:fc4f3879f0e1 309 char command[2]= "";
ms523 0:fc4f3879f0e1 310
ms523 0:fc4f3879f0e1 311 command[0] = SETVOLUME;
ms523 0:fc4f3879f0e1 312 command[1] = value;
ms523 0:fc4f3879f0e1 313
ms523 0:fc4f3879f0e1 314 writeCOMMAND(command, 2);
ms523 0:fc4f3879f0e1 315 }
ms523 0:fc4f3879f0e1 316
ms523 0:fc4f3879f0e1 317
ms523 0:fc4f3879f0e1 318 //******************************************************************************************************
ms523 0:fc4f3879f0e1 319 void TFT_4DGL :: getTOUCH(char *command, int number, int *x, int *y) { // read screen info and populate data
ms523 0:fc4f3879f0e1 320
ms523 0:fc4f3879f0e1 321 #if DEBUGMODE
ms523 0:fc4f3879f0e1 322 pc.printf("\n\r");
ms523 0:fc4f3879f0e1 323 pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
ms523 0:fc4f3879f0e1 324 #endif
ms523 0:fc4f3879f0e1 325 int i, temp = 0, resp = 0;
ms523 0:fc4f3879f0e1 326 char response[5] = "";
ms523 0:fc4f3879f0e1 327
ms523 0:fc4f3879f0e1 328 freeBUFFER();
ms523 0:fc4f3879f0e1 329
ms523 0:fc4f3879f0e1 330 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
ms523 0:fc4f3879f0e1 331
ms523 0:fc4f3879f0e1 332 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 333
ms523 0:fc4f3879f0e1 334 while (_cmd.readable()) {
ms523 0:fc4f3879f0e1 335 temp = _cmd.getc();
ms523 0:fc4f3879f0e1 336 response[resp++] = (char)temp;
ms523 0:fc4f3879f0e1 337 }
ms523 0:fc4f3879f0e1 338
ms523 0:fc4f3879f0e1 339 #if DEBUGMODE
ms523 0:fc4f3879f0e1 340 pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n\r", resp, response[0], response[1], response[2], response[3]);
ms523 0:fc4f3879f0e1 341 #endif
ms523 0:fc4f3879f0e1 342
ms523 0:fc4f3879f0e1 343 switch (resp) {
ms523 0:fc4f3879f0e1 344 case 4 : // if OK populate data
ms523 0:fc4f3879f0e1 345 *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF);
ms523 0:fc4f3879f0e1 346 *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF);
ms523 0:fc4f3879f0e1 347 break;
ms523 0:fc4f3879f0e1 348 default :
ms523 0:fc4f3879f0e1 349 *x = -1;
ms523 0:fc4f3879f0e1 350 *y = -1;
ms523 0:fc4f3879f0e1 351 break;
ms523 0:fc4f3879f0e1 352 }
ms523 0:fc4f3879f0e1 353
ms523 0:fc4f3879f0e1 354 #if DEBUGMODE
ms523 0:fc4f3879f0e1 355 pc.printf(" X,Y : %03d,%03d\n\r", *x, *y);
ms523 0:fc4f3879f0e1 356 #endif
ms523 0:fc4f3879f0e1 357 }
ms523 0:fc4f3879f0e1 358
ms523 0:fc4f3879f0e1 359 //******************************************************************************************************
ms523 0:fc4f3879f0e1 360 int TFT_4DGL :: getSTATUS(char *command, int number) { // read screen info and populate data
ms523 0:fc4f3879f0e1 361
ms523 0:fc4f3879f0e1 362 #if DEBUGMODE
ms523 0:fc4f3879f0e1 363 pc.printf("\n\r");
ms523 0:fc4f3879f0e1 364 pc.printf("New COMMAND : 0x%02X\n\r", command[0]);
ms523 0:fc4f3879f0e1 365 #endif
ms523 0:fc4f3879f0e1 366
ms523 0:fc4f3879f0e1 367 int i, temp = 0, resp = 0;
ms523 0:fc4f3879f0e1 368 char response[5] = "";
ms523 0:fc4f3879f0e1 369
ms523 0:fc4f3879f0e1 370 freeBUFFER();
ms523 0:fc4f3879f0e1 371
ms523 0:fc4f3879f0e1 372 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
ms523 0:fc4f3879f0e1 373
ms523 0:fc4f3879f0e1 374 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
ms523 0:fc4f3879f0e1 375
ms523 0:fc4f3879f0e1 376 while (_cmd.readable()) {
ms523 0:fc4f3879f0e1 377 temp = _cmd.getc();
ms523 0:fc4f3879f0e1 378 response[resp++] = (char)temp;
ms523 0:fc4f3879f0e1 379 }
ms523 0:fc4f3879f0e1 380 switch (resp) {
ms523 0:fc4f3879f0e1 381 case 4 :
ms523 0:fc4f3879f0e1 382 resp = (int)response[1]; // if OK populate data
ms523 0:fc4f3879f0e1 383 break;
ms523 0:fc4f3879f0e1 384 default :
ms523 0:fc4f3879f0e1 385 resp = -1; // else return 0
ms523 0:fc4f3879f0e1 386 break;
ms523 0:fc4f3879f0e1 387 }
ms523 0:fc4f3879f0e1 388
ms523 0:fc4f3879f0e1 389 #if DEBUGMODE
ms523 0:fc4f3879f0e1 390 pc.printf(" Answer received : %d\n\r", resp);
ms523 0:fc4f3879f0e1 391 #endif
ms523 0:fc4f3879f0e1 392
ms523 0:fc4f3879f0e1 393 return resp;
ms523 0:fc4f3879f0e1 394 }