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