Fork of the 4DGL-uLCD-SE library by Jim Hamblen.

Dependents:   ulcd_demo ulcd_accel internet_clock 4180_Final_Project ... more

Fork of 4DGL-uLCD-SE by jim hamblen

Committer:
4180_1
Date:
Sun Nov 17 04:36:12 2013 +0000
Revision:
2:edae99e4abe7
Parent:
1:8b656995301f
Child:
4:74df7fc26fef
ver 1.01

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