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