4DGL-uLCD-SE with removed color defines

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
4180_1
Date:
Wed Nov 20 03:25:53 2013 +0000
Revision:
4:74df7fc26fef
Parent:
2:edae99e4abe7
Child:
5:8936798c19a3
ver1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 1:8b656995301f 1 //
4180_1 2:edae99e4abe7 2 // uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2
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 2:edae99e4abe7 56 current_hf = 1;
4180_1 2:edae99e4abe7 57 current_wf = 1;
4180_1 2:edae99e4abe7 58 set_font(FONT_7X8); // initial font
4180_1 1:8b656995301f 59 // text_mode(OPAQUE); // initial texr mode
4180_1 1:8b656995301f 60 }
4180_1 1:8b656995301f 61
4180_1 1:8b656995301f 62 //******************************************************************************************************
4180_1 1:8b656995301f 63 void uLCD_4DGL :: writeBYTE(char c) // send a BYTE command to screen
4180_1 1:8b656995301f 64 {
4180_1 1:8b656995301f 65
4180_1 1:8b656995301f 66 _cmd.putc(c);
4180_1 4:74df7fc26fef 67 wait_ms(1); //mbed is too fast for LCD at high baud rates in long commands
4180_1 1:8b656995301f 68
4180_1 1:8b656995301f 69 #if DEBUGMODE
4180_1 1:8b656995301f 70 pc.printf(" Char sent : 0x%02X\n",c);
4180_1 1:8b656995301f 71 #endif
4180_1 1:8b656995301f 72
4180_1 1:8b656995301f 73 }
4180_1 1:8b656995301f 74
4180_1 1:8b656995301f 75 //******************************************************************************************************
4180_1 4:74df7fc26fef 76 void uLCD_4DGL :: writeBYTEfast(char c) // send a BYTE command to screen
4180_1 4:74df7fc26fef 77 {
4180_1 4:74df7fc26fef 78
4180_1 4:74df7fc26fef 79 _cmd.putc(c);
4180_1 4:74df7fc26fef 80 //wait_ms(0.0); //mbed is too fast for LCD at high baud rates - but not in some commands
4180_1 4:74df7fc26fef 81
4180_1 4:74df7fc26fef 82 #if DEBUGMODE
4180_1 4:74df7fc26fef 83 pc.printf(" Char sent : 0x%02X\n",c);
4180_1 4:74df7fc26fef 84 #endif
4180_1 4:74df7fc26fef 85
4180_1 4:74df7fc26fef 86 }
4180_1 4:74df7fc26fef 87 //******************************************************************************************************
4180_1 1:8b656995301f 88 void uLCD_4DGL :: freeBUFFER(void) // Clear serial buffer before writing command
4180_1 1:8b656995301f 89 {
4180_1 1:8b656995301f 90
4180_1 1:8b656995301f 91 while (_cmd.readable()) _cmd.getc(); // clear buffer garbage
4180_1 1:8b656995301f 92 }
4180_1 1:8b656995301f 93
4180_1 1:8b656995301f 94 //******************************************************************************************************
4180_1 1:8b656995301f 95 int uLCD_4DGL :: writeCOMMAND(char *command, int number) // send several BYTES making a command and return an answer
4180_1 1:8b656995301f 96 {
4180_1 1:8b656995301f 97
4180_1 1:8b656995301f 98 #if DEBUGMODE
4180_1 1:8b656995301f 99 pc.printf("\n");
4180_1 1:8b656995301f 100 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 101 #endif
4180_1 1:8b656995301f 102 int i, resp = 0;
4180_1 1:8b656995301f 103 freeBUFFER();
4180_1 1:8b656995301f 104 writeBYTE(0xFF);
4180_1 4:74df7fc26fef 105 for (i = 0; i < number; i++) {
4180_1 4:74df7fc26fef 106 if (i<16)
4180_1 4:74df7fc26fef 107 writeBYTEfast(command[i]); // send command to serial port
4180_1 4:74df7fc26fef 108 else
4180_1 4:74df7fc26fef 109 writeBYTE(command[i]); // send command to serial port but slower
4180_1 4:74df7fc26fef 110 }
4180_1 1:8b656995301f 111 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 112 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 113 switch (resp) {
4180_1 1:8b656995301f 114 case ACK : // if OK return 1
4180_1 1:8b656995301f 115 resp = 1;
4180_1 1:8b656995301f 116 break;
4180_1 1:8b656995301f 117 case NAK : // if NOK return -1
4180_1 1:8b656995301f 118 resp = -1;
4180_1 1:8b656995301f 119 break;
4180_1 1:8b656995301f 120 default :
4180_1 1:8b656995301f 121 resp = 0; // else return 0
4180_1 1:8b656995301f 122 break;
4180_1 1:8b656995301f 123 }
4180_1 1:8b656995301f 124 #if DEBUGMODE
4180_1 1:8b656995301f 125 pc.printf(" Answer received : %d\n",resp);
4180_1 1:8b656995301f 126 #endif
4180_1 1:8b656995301f 127
4180_1 1:8b656995301f 128 return resp;
4180_1 1:8b656995301f 129 }
4180_1 1:8b656995301f 130
4180_1 1:8b656995301f 131 //**************************************************************************
4180_1 1:8b656995301f 132 void uLCD_4DGL :: reset() // Reset Screen
4180_1 1:8b656995301f 133 {
4180_1 1:8b656995301f 134
4180_1 1:8b656995301f 135 _rst = 0; // put RESET pin to low
4180_1 1:8b656995301f 136 wait_ms(TEMPO); // wait a few milliseconds for command reception
4180_1 1:8b656995301f 137 _rst = 1; // put RESET back to high
4180_1 1:8b656995301f 138 wait(3); // wait 3s for screen to restart
4180_1 1:8b656995301f 139
4180_1 1:8b656995301f 140 freeBUFFER(); // clean buffer from possible garbage
4180_1 1:8b656995301f 141 }
4180_1 1:8b656995301f 142 //******************************************************************************************************
4180_1 1:8b656995301f 143 int uLCD_4DGL :: writeCOMMANDnull(char *command, int number) // send several BYTES making a command and return an answer
4180_1 1:8b656995301f 144 {
4180_1 1:8b656995301f 145
4180_1 1:8b656995301f 146 #if DEBUGMODE
4180_1 1:8b656995301f 147 pc.printf("\n");
4180_1 1:8b656995301f 148 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 149 #endif
4180_1 1:8b656995301f 150 int i, resp = 0;
4180_1 1:8b656995301f 151 freeBUFFER();
4180_1 2:edae99e4abe7 152 writeBYTE(0x00); //command has a null prefix byte
4180_1 4:74df7fc26fef 153 for (i = 0; i < number; i++) {
4180_1 4:74df7fc26fef 154 if (i<16)
4180_1 4:74df7fc26fef 155 writeBYTEfast(command[i]); // send command to serial port
4180_1 4:74df7fc26fef 156 else
4180_1 4:74df7fc26fef 157 writeBYTE(command[i]); // send command to serial port
4180_1 4:74df7fc26fef 158 }
4180_1 1:8b656995301f 159 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 160 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 161 switch (resp) {
4180_1 1:8b656995301f 162 case ACK : // if OK return 1
4180_1 1:8b656995301f 163 resp = 1;
4180_1 1:8b656995301f 164 break;
4180_1 1:8b656995301f 165 case NAK : // if NOK return -1
4180_1 1:8b656995301f 166 resp = -1;
4180_1 1:8b656995301f 167 break;
4180_1 1:8b656995301f 168 default :
4180_1 1:8b656995301f 169 resp = 0; // else return 0
4180_1 1:8b656995301f 170 break;
4180_1 1:8b656995301f 171 }
4180_1 1:8b656995301f 172 #if DEBUGMODE
4180_1 1:8b656995301f 173 pc.printf(" Answer received : %d\n",resp);
4180_1 1:8b656995301f 174 #endif
4180_1 1:8b656995301f 175
4180_1 1:8b656995301f 176 return resp;
4180_1 1:8b656995301f 177 }
4180_1 1:8b656995301f 178
4180_1 1:8b656995301f 179
4180_1 1:8b656995301f 180 //**************************************************************************
4180_1 1:8b656995301f 181 void uLCD_4DGL :: autobaud() // send AutoBaud command (9600)
4180_1 1:8b656995301f 182 {
4180_1 1:8b656995301f 183 writeBYTE(AUTOBAUD);
4180_1 1:8b656995301f 184 char command[1] = "";
4180_1 1:8b656995301f 185 command[0] = AUTOBAUD;
4180_1 1:8b656995301f 186 writeCOMMAND(command, 1);
4180_1 1:8b656995301f 187 }
4180_1 1:8b656995301f 188
4180_1 1:8b656995301f 189 //**************************************************************************
4180_1 1:8b656995301f 190 void uLCD_4DGL :: cls() // clear screen
4180_1 1:8b656995301f 191 {
4180_1 1:8b656995301f 192 char command[1] = "";
4180_1 1:8b656995301f 193
4180_1 1:8b656995301f 194 command[0] = CLS;
4180_1 1:8b656995301f 195 writeCOMMAND(command, 1);
4180_1 2:edae99e4abe7 196 current_hf = 1;
4180_1 2:edae99e4abe7 197 current_wf = 1;
4180_1 2:edae99e4abe7 198 set_font(FONT_7X8); // initial font
4180_1 1:8b656995301f 199 }
4180_1 1:8b656995301f 200
4180_1 1:8b656995301f 201 //**************************************************************************
4180_1 1:8b656995301f 202 void uLCD_4DGL :: version() // get API version
4180_1 1:8b656995301f 203 {
4180_1 1:8b656995301f 204 char command[2] = "";
4180_1 1:8b656995301f 205 command[0] = VERSION;
4180_1 1:8b656995301f 206 command[1] = OFF;
4180_1 1:8b656995301f 207 readVERSION(command, 2);
4180_1 1:8b656995301f 208 }
4180_1 1:8b656995301f 209
4180_1 1:8b656995301f 210 //**************************************************************************
4180_1 1:8b656995301f 211 void uLCD_4DGL :: baudrate(int speed) // set screen baud rate
4180_1 1:8b656995301f 212 {
4180_1 1:8b656995301f 213 char command[3]= "";
4180_1 1:8b656995301f 214 writeBYTE(0x00);
4180_1 1:8b656995301f 215 command[0] = BAUDRATE;
4180_1 1:8b656995301f 216 command[1] = 0;
4180_1 1:8b656995301f 217 int newbaud = BAUD_9600;
4180_1 1:8b656995301f 218 switch (speed) {
4180_1 1:8b656995301f 219 case 110 :
4180_1 1:8b656995301f 220 newbaud = BAUD_110;
4180_1 1:8b656995301f 221 break;
4180_1 1:8b656995301f 222 case 300 :
4180_1 1:8b656995301f 223 newbaud = BAUD_300;
4180_1 1:8b656995301f 224 break;
4180_1 1:8b656995301f 225 case 600 :
4180_1 1:8b656995301f 226 newbaud = BAUD_600;
4180_1 1:8b656995301f 227 break;
4180_1 1:8b656995301f 228 case 1200 :
4180_1 1:8b656995301f 229 newbaud = BAUD_1200;
4180_1 1:8b656995301f 230 break;
4180_1 1:8b656995301f 231 case 2400 :
4180_1 1:8b656995301f 232 newbaud = BAUD_2400;
4180_1 1:8b656995301f 233 break;
4180_1 1:8b656995301f 234 case 4800 :
4180_1 1:8b656995301f 235 newbaud = BAUD_4800;
4180_1 1:8b656995301f 236 break;
4180_1 1:8b656995301f 237 case 9600 :
4180_1 4:74df7fc26fef 238 newbaud = BAUD_9600;
4180_1 1:8b656995301f 239 break;
4180_1 1:8b656995301f 240 case 14400 :
4180_1 1:8b656995301f 241 newbaud = BAUD_14400;
4180_1 1:8b656995301f 242 break;
4180_1 1:8b656995301f 243 case 19200 :
4180_1 1:8b656995301f 244 newbaud = BAUD_19200;
4180_1 1:8b656995301f 245 break;
4180_1 1:8b656995301f 246 case 31250 :
4180_1 1:8b656995301f 247 newbaud = BAUD_31250;
4180_1 1:8b656995301f 248 break;
4180_1 1:8b656995301f 249 case 38400 :
4180_1 1:8b656995301f 250 newbaud = BAUD_38400;
4180_1 1:8b656995301f 251 break;
4180_1 1:8b656995301f 252 case 56000 :
4180_1 1:8b656995301f 253 newbaud = BAUD_56000;
4180_1 1:8b656995301f 254 break;
4180_1 1:8b656995301f 255 case 57600 :
4180_1 1:8b656995301f 256 newbaud = BAUD_57600;
4180_1 1:8b656995301f 257 break;
4180_1 1:8b656995301f 258 case 115200 :
4180_1 1:8b656995301f 259 newbaud = BAUD_115200;
4180_1 1:8b656995301f 260 break;
4180_1 1:8b656995301f 261 case 128000 :
4180_1 1:8b656995301f 262 newbaud = BAUD_128000;
4180_1 1:8b656995301f 263 break;
4180_1 1:8b656995301f 264 case 256000 :
4180_1 1:8b656995301f 265 newbaud = BAUD_256000;
4180_1 1:8b656995301f 266 break;
4180_1 1:8b656995301f 267 default :
4180_1 1:8b656995301f 268 newbaud = BAUD_9600;
4180_1 1:8b656995301f 269 speed = 9600;
4180_1 1:8b656995301f 270 break;
4180_1 1:8b656995301f 271 }
4180_1 1:8b656995301f 272
4180_1 1:8b656995301f 273 int i, resp = 0;
4180_1 1:8b656995301f 274
4180_1 1:8b656995301f 275 freeBUFFER();
4180_1 1:8b656995301f 276 command[1] = char(newbaud >>8);
4180_1 1:8b656995301f 277 command[2] = char(newbaud % 256);
4180_1 1:8b656995301f 278 for (i = 0; i <3; i++) writeBYTE(command[i]); // send command to serial port
4180_1 1:8b656995301f 279 _cmd.baud(speed); // set mbed to same speed
4180_1 1:8b656995301f 280
4180_1 1:8b656995301f 281 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 282
4180_1 1:8b656995301f 283 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
4180_1 1:8b656995301f 284 switch (resp) {
4180_1 1:8b656995301f 285 case ACK : // if OK return 1
4180_1 1:8b656995301f 286 resp = 1;
4180_1 1:8b656995301f 287 break;
4180_1 1:8b656995301f 288 case NAK : // if NOK return -1
4180_1 1:8b656995301f 289 resp = -1;
4180_1 1:8b656995301f 290 break;
4180_1 1:8b656995301f 291 default :
4180_1 1:8b656995301f 292 resp = 0; // else return 0
4180_1 1:8b656995301f 293 break;
4180_1 1:8b656995301f 294 }
4180_1 1:8b656995301f 295 }
4180_1 1:8b656995301f 296
4180_1 1:8b656995301f 297 //******************************************************************************************************
4180_1 1:8b656995301f 298 int uLCD_4DGL :: readVERSION(char *command, int number) // read screen info and populate data
4180_1 1:8b656995301f 299 {
4180_1 1:8b656995301f 300
4180_1 1:8b656995301f 301 int i, temp = 0, resp = 0;
4180_1 1:8b656995301f 302 char response[5] = "";
4180_1 1:8b656995301f 303
4180_1 1:8b656995301f 304 freeBUFFER();
4180_1 1:8b656995301f 305
4180_1 1:8b656995301f 306 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
4180_1 1:8b656995301f 307
4180_1 1:8b656995301f 308 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 309
4180_1 1:8b656995301f 310 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
4180_1 1:8b656995301f 311 temp = _cmd.getc();
4180_1 1:8b656995301f 312 response[resp++] = (char)temp;
4180_1 1:8b656995301f 313 }
4180_1 1:8b656995301f 314 switch (resp) {
4180_1 1:8b656995301f 315 case 5 : // if OK populate data and return 1
4180_1 1:8b656995301f 316 type = response[0];
4180_1 1:8b656995301f 317 revision = response[1];
4180_1 1:8b656995301f 318 firmware = response[2];
4180_1 1:8b656995301f 319 reserved1 = response[3];
4180_1 1:8b656995301f 320 reserved2 = response[4];
4180_1 1:8b656995301f 321 resp = 1;
4180_1 1:8b656995301f 322 break;
4180_1 1:8b656995301f 323 default :
4180_1 1:8b656995301f 324 resp = 0; // else return 0
4180_1 1:8b656995301f 325 break;
4180_1 1:8b656995301f 326 }
4180_1 1:8b656995301f 327 return resp;
4180_1 1:8b656995301f 328 }
4180_1 1:8b656995301f 329
4180_1 1:8b656995301f 330 //****************************************************************************************************
4180_1 1:8b656995301f 331 void uLCD_4DGL :: background_color(int color) // set screen background color
4180_1 1:8b656995301f 332 {
4180_1 1:8b656995301f 333 char command[3]= ""; // input color is in 24bits like 0xRRGGBB
4180_1 1:8b656995301f 334
4180_1 1:8b656995301f 335 command[0] = BCKGDCOLOR;
4180_1 1:8b656995301f 336
4180_1 1:8b656995301f 337 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 1:8b656995301f 338 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 1:8b656995301f 339 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 1:8b656995301f 340
4180_1 1:8b656995301f 341 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 1:8b656995301f 342 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 1:8b656995301f 343
4180_1 1:8b656995301f 344 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 345 }
4180_1 1:8b656995301f 346
4180_1 1:8b656995301f 347 //****************************************************************************************************
4180_1 2:edae99e4abe7 348 void uLCD_4DGL :: textbackground_color(int color) // set screen background color
4180_1 2:edae99e4abe7 349 {
4180_1 2:edae99e4abe7 350 char command[3]= ""; // input color is in 24bits like 0xRRGGBB
4180_1 2:edae99e4abe7 351
4180_1 2:edae99e4abe7 352 command[0] = TXTBCKGDCOLOR;
4180_1 2:edae99e4abe7 353
4180_1 2:edae99e4abe7 354 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
4180_1 2:edae99e4abe7 355 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
4180_1 2:edae99e4abe7 356 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
4180_1 2:edae99e4abe7 357
4180_1 2:edae99e4abe7 358 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
4180_1 2:edae99e4abe7 359 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
4180_1 2:edae99e4abe7 360
4180_1 2:edae99e4abe7 361 writeCOMMAND(command, 3);
4180_1 2:edae99e4abe7 362 }
4180_1 2:edae99e4abe7 363
4180_1 2:edae99e4abe7 364 //****************************************************************************************************
4180_1 1:8b656995301f 365 void uLCD_4DGL :: display_control(char mode, char value) // set screen mode to value
4180_1 1:8b656995301f 366 {
4180_1 1:8b656995301f 367 char command[3]= "";
4180_1 1:8b656995301f 368
4180_1 1:8b656995301f 369 command[0] = DISPCONTROL;
4180_1 1:8b656995301f 370 command[1] = mode;
4180_1 1:8b656995301f 371 command[2] = value;
4180_1 1:8b656995301f 372
4180_1 1:8b656995301f 373 if (mode == ORIENTATION) {
4180_1 1:8b656995301f 374 switch (value) {
4180_1 1:8b656995301f 375 case LANDSCAPE :
4180_1 1:8b656995301f 376 current_orientation = IS_LANDSCAPE;
4180_1 1:8b656995301f 377 break;
4180_1 1:8b656995301f 378 case LANDSCAPE_R :
4180_1 1:8b656995301f 379 current_orientation = IS_LANDSCAPE;
4180_1 1:8b656995301f 380 break;
4180_1 1:8b656995301f 381 case PORTRAIT :
4180_1 1:8b656995301f 382 current_orientation = IS_PORTRAIT;
4180_1 1:8b656995301f 383 break;
4180_1 1:8b656995301f 384 case PORTRAIT_R :
4180_1 1:8b656995301f 385 current_orientation = IS_PORTRAIT;
4180_1 1:8b656995301f 386 break;
4180_1 1:8b656995301f 387 }
4180_1 1:8b656995301f 388 }
4180_1 1:8b656995301f 389 writeCOMMAND(command, 3);
4180_1 1:8b656995301f 390 set_font(current_font);
4180_1 1:8b656995301f 391 }
4180_1 1:8b656995301f 392
4180_1 1:8b656995301f 393 //****************************************************************************************************
4180_1 1:8b656995301f 394 void uLCD_4DGL :: set_volume(char value) // set sound volume to value
4180_1 1:8b656995301f 395 {
4180_1 1:8b656995301f 396 char command[2]= "";
4180_1 1:8b656995301f 397
4180_1 1:8b656995301f 398 command[0] = SETVOLUME;
4180_1 1:8b656995301f 399 command[1] = value;
4180_1 1:8b656995301f 400
4180_1 1:8b656995301f 401 writeCOMMAND(command, 2);
4180_1 1:8b656995301f 402 }
4180_1 1:8b656995301f 403
4180_1 1:8b656995301f 404
4180_1 1:8b656995301f 405 //******************************************************************************************************
4180_1 1:8b656995301f 406 void uLCD_4DGL :: getTOUCH(char *command, int number, int *x, int *y) // read screen info and populate data
4180_1 1:8b656995301f 407 {
4180_1 1:8b656995301f 408
4180_1 1:8b656995301f 409 #if DEBUGMODE
4180_1 1:8b656995301f 410 pc.printf("\n");
4180_1 1:8b656995301f 411 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 412 #endif
4180_1 1:8b656995301f 413 int i, temp = 0, resp = 0;
4180_1 1:8b656995301f 414 char response[5] = "";
4180_1 1:8b656995301f 415
4180_1 1:8b656995301f 416 freeBUFFER();
4180_1 1:8b656995301f 417
4180_1 1:8b656995301f 418 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
4180_1 1:8b656995301f 419
4180_1 1:8b656995301f 420 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 421
4180_1 1:8b656995301f 422 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
4180_1 1:8b656995301f 423 temp = _cmd.getc();
4180_1 1:8b656995301f 424 response[resp++] = (char)temp;
4180_1 1:8b656995301f 425 }
4180_1 1:8b656995301f 426
4180_1 1:8b656995301f 427 #if DEBUGMODE
4180_1 1:8b656995301f 428 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 429 #endif
4180_1 1:8b656995301f 430
4180_1 1:8b656995301f 431 switch (resp) {
4180_1 1:8b656995301f 432 case 4 : // if OK populate data
4180_1 1:8b656995301f 433 *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF);
4180_1 1:8b656995301f 434 *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF);
4180_1 1:8b656995301f 435 break;
4180_1 1:8b656995301f 436 default :
4180_1 1:8b656995301f 437 *x = -1;
4180_1 1:8b656995301f 438 *y = -1;
4180_1 1:8b656995301f 439 break;
4180_1 1:8b656995301f 440 }
4180_1 1:8b656995301f 441
4180_1 1:8b656995301f 442 #if DEBUGMODE
4180_1 1:8b656995301f 443 pc.printf(" X,Y : %03d,%03d\n", *x, *y);
4180_1 1:8b656995301f 444 #endif
4180_1 1:8b656995301f 445 }
4180_1 1:8b656995301f 446
4180_1 1:8b656995301f 447 //******************************************************************************************************
4180_1 1:8b656995301f 448 int uLCD_4DGL :: getSTATUS(char *command, int number) // read screen info and populate data
4180_1 1:8b656995301f 449 {
4180_1 1:8b656995301f 450
4180_1 1:8b656995301f 451 #if DEBUGMODE
4180_1 1:8b656995301f 452 pc.printf("\n");
4180_1 1:8b656995301f 453 pc.printf("New COMMAND : 0x%02X\n", command[0]);
4180_1 1:8b656995301f 454 #endif
4180_1 1:8b656995301f 455
4180_1 1:8b656995301f 456 int i, temp = 0, resp = 0;
4180_1 1:8b656995301f 457 char response[5] = "";
4180_1 1:8b656995301f 458
4180_1 1:8b656995301f 459 freeBUFFER();
4180_1 1:8b656995301f 460
4180_1 1:8b656995301f 461 for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port
4180_1 1:8b656995301f 462
4180_1 1:8b656995301f 463 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
4180_1 1:8b656995301f 464
4180_1 1:8b656995301f 465 while (_cmd.readable() && resp < ARRAY_SIZE(response)) {
4180_1 1:8b656995301f 466 temp = _cmd.getc();
4180_1 1:8b656995301f 467 response[resp++] = (char)temp;
4180_1 1:8b656995301f 468 }
4180_1 1:8b656995301f 469 switch (resp) {
4180_1 1:8b656995301f 470 case 4 :
4180_1 1:8b656995301f 471 resp = (int)response[1]; // if OK populate data
4180_1 1:8b656995301f 472 break;
4180_1 1:8b656995301f 473 default :
4180_1 1:8b656995301f 474 resp = -1; // else return 0
4180_1 1:8b656995301f 475 break;
4180_1 1:8b656995301f 476 }
4180_1 1:8b656995301f 477
4180_1 1:8b656995301f 478 #if DEBUGMODE
4180_1 1:8b656995301f 479 pc.printf(" Answer received : %d\n", resp);
4180_1 1:8b656995301f 480 #endif
4180_1 1:8b656995301f 481
4180_1 1:8b656995301f 482 return resp;
4180_1 2:edae99e4abe7 483 }