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