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