Kamil Ondrousek / Mbed 2 deprecated Tinkerbell
Committer:
JLS
Date:
Sun Dec 26 19:53:45 2010 +0000
Revision:
1:1ea2331f9cbe
update

Who changed what in which revision?

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