flip tile

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
4180_1
Date:
Mon Nov 11 01:22:41 2013 +0000
Revision:
1:8b656995301f
Child:
2:edae99e4abe7
ver 1.0 uLCD144-G2 demo

Who changed what in which revision?

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