uVGA II for display using vga

Dependents:   4DGL

Committer:
pprasad7
Date:
Thu Oct 11 20:12:02 2012 +0000
Revision:
0:6741e7724181
hangman

Who changed what in which revision?

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