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