ajfja

Fork of 4DGL-uLCD-SE by Jonathan Austin

Committer:
anevil14
Date:
Fri May 01 16:49:27 2015 +0000
Revision:
1:df77db998389
No Changes

Who changed what in which revision?

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