Updated serial prints for debugging
Dependents: mbedica_on_yehowshua mbedica
uVGAIII_main.cpp@0:de1ab53f3480, 2014-03-24 (annotated)
- Committer:
- ivygatech
- Date:
- Mon Mar 24 17:35:56 2014 +0000
- Revision:
- 0:de1ab53f3480
- Child:
- 6:58c02c38e75f
Library for uVGAIII
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 |
ivygatech | 0:de1ab53f3480 | 42 | _cmd.baud(9600); |
ivygatech | 0:de1ab53f3480 | 43 | _rst = 1; // put RESET pin to high to start TFT screen |
ivygatech | 0:de1ab53f3480 | 44 | |
ivygatech | 0:de1ab53f3480 | 45 | reset(); |
ivygatech | 0:de1ab53f3480 | 46 | cls(); // clear screen |
ivygatech | 0:de1ab53f3480 | 47 | speversion(); // get SPE version information |
ivygatech | 0:de1ab53f3480 | 48 | pmmcversion(); // get PmmC version information |
ivygatech | 0:de1ab53f3480 | 49 | |
ivygatech | 0:de1ab53f3480 | 50 | current_col = 0; // initial cursor col |
ivygatech | 0:de1ab53f3480 | 51 | current_row = 0; // initial cursor row |
ivygatech | 0:de1ab53f3480 | 52 | current_color = WHITE; // initial text color |
ivygatech | 0:de1ab53f3480 | 53 | current_orientation = IS_LANDSCAPE; // initial screen orientation |
ivygatech | 0:de1ab53f3480 | 54 | |
ivygatech | 0:de1ab53f3480 | 55 | set_font(FONT3); // initial font ( This line can be removed because font has been set to be FONT3 ) |
ivygatech | 0:de1ab53f3480 | 56 | text_opacity(OPAQUE); // initial text opacity ( This line can be removed because text opacity has been set to be OPAQUE ) |
ivygatech | 0:de1ab53f3480 | 57 | } |
ivygatech | 0:de1ab53f3480 | 58 | |
ivygatech | 0:de1ab53f3480 | 59 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 60 | void uVGAIII :: writeBYTE(char c) { // send a BYTE command to screen |
ivygatech | 0:de1ab53f3480 | 61 | |
ivygatech | 0:de1ab53f3480 | 62 | _cmd.putc(c); |
ivygatech | 0:de1ab53f3480 | 63 | wait_ms(1); |
ivygatech | 0:de1ab53f3480 | 64 | |
ivygatech | 0:de1ab53f3480 | 65 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 66 | pc.printf(" Char sent : 0x%02X\n",c); |
ivygatech | 0:de1ab53f3480 | 67 | #endif |
ivygatech | 0:de1ab53f3480 | 68 | |
ivygatech | 0:de1ab53f3480 | 69 | } |
ivygatech | 0:de1ab53f3480 | 70 | |
ivygatech | 0:de1ab53f3480 | 71 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 72 | void uVGAIII :: freeBUFFER(void) { // Clear serial buffer before writing command |
ivygatech | 0:de1ab53f3480 | 73 | |
ivygatech | 0:de1ab53f3480 | 74 | while (_cmd.readable()) _cmd.getc(); // clear buffer garbage |
ivygatech | 0:de1ab53f3480 | 75 | } |
ivygatech | 0:de1ab53f3480 | 76 | |
ivygatech | 0:de1ab53f3480 | 77 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 78 | int uVGAIII :: writeCOMMAND(char *command, int commNum, int respNum) { // send several BYTES making a command and return an answer |
ivygatech | 0:de1ab53f3480 | 79 | |
ivygatech | 0:de1ab53f3480 | 80 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 81 | pc.printf("\n"); |
ivygatech | 0:de1ab53f3480 | 82 | pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); |
ivygatech | 0:de1ab53f3480 | 83 | #endif |
ivygatech | 0:de1ab53f3480 | 84 | int i, resp = 0; |
ivygatech | 0:de1ab53f3480 | 85 | freeBUFFER(); |
ivygatech | 0:de1ab53f3480 | 86 | |
ivygatech | 0:de1ab53f3480 | 87 | for (i = 0; i < commNum; i++) {writeBYTE(command[i]); wait_ms(100);} // send command to serial port |
ivygatech | 0:de1ab53f3480 | 88 | |
ivygatech | 0:de1ab53f3480 | 89 | for (i = 0; i < respNum; i++) { |
ivygatech | 0:de1ab53f3480 | 90 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
ivygatech | 0:de1ab53f3480 | 91 | if (_cmd.readable()) { |
ivygatech | 0:de1ab53f3480 | 92 | resp = _cmd.getc(); // read response if any |
ivygatech | 0:de1ab53f3480 | 93 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 94 | pc.printf("response = 0x%02X\n",resp); |
ivygatech | 0:de1ab53f3480 | 95 | #endif |
ivygatech | 0:de1ab53f3480 | 96 | } |
ivygatech | 0:de1ab53f3480 | 97 | } |
ivygatech | 0:de1ab53f3480 | 98 | return resp; |
ivygatech | 0:de1ab53f3480 | 99 | } |
ivygatech | 0:de1ab53f3480 | 100 | |
ivygatech | 0:de1ab53f3480 | 101 | //************************************************************************** |
ivygatech | 0:de1ab53f3480 | 102 | void uVGAIII :: reset() { // Reset Screen |
ivygatech | 0:de1ab53f3480 | 103 | |
ivygatech | 0:de1ab53f3480 | 104 | _rst = 0; // put RESET pin to low |
ivygatech | 0:de1ab53f3480 | 105 | wait_ms(TEMPO); // wait a few milliseconds for command reception |
ivygatech | 0:de1ab53f3480 | 106 | _rst = 1; // put RESET back to high |
ivygatech | 0:de1ab53f3480 | 107 | wait(3.2); // wait 3s for screen to restart |
ivygatech | 0:de1ab53f3480 | 108 | |
ivygatech | 0:de1ab53f3480 | 109 | freeBUFFER(); // clean buffer from possible garbage |
ivygatech | 0:de1ab53f3480 | 110 | |
ivygatech | 0:de1ab53f3480 | 111 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 112 | pc.printf("Reset completed.\n"); |
ivygatech | 0:de1ab53f3480 | 113 | #endif |
ivygatech | 0:de1ab53f3480 | 114 | } |
ivygatech | 0:de1ab53f3480 | 115 | |
ivygatech | 0:de1ab53f3480 | 116 | //************************************************************************** |
ivygatech | 0:de1ab53f3480 | 117 | void uVGAIII :: speversion() { // get SPE version |
ivygatech | 0:de1ab53f3480 | 118 | char command[2] = ""; |
ivygatech | 0:de1ab53f3480 | 119 | int spe = 0; |
ivygatech | 0:de1ab53f3480 | 120 | command[0] = (SPEVERSION >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 121 | command[1] = SPEVERSION & 0xFF; |
ivygatech | 0:de1ab53f3480 | 122 | |
ivygatech | 0:de1ab53f3480 | 123 | spe = readVERSION(command, 2); |
ivygatech | 0:de1ab53f3480 | 124 | |
ivygatech | 0:de1ab53f3480 | 125 | pc.printf("spe:%d\n",spe); |
ivygatech | 0:de1ab53f3480 | 126 | } |
ivygatech | 0:de1ab53f3480 | 127 | |
ivygatech | 0:de1ab53f3480 | 128 | //************************************************************************** |
ivygatech | 0:de1ab53f3480 | 129 | void uVGAIII :: pmmcversion() { // get PmmC version |
ivygatech | 0:de1ab53f3480 | 130 | char command[2] = ""; |
ivygatech | 0:de1ab53f3480 | 131 | int pmmc = 0; |
ivygatech | 0:de1ab53f3480 | 132 | command[0] = (PMMCVERSION >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 133 | command[1] = PMMCVERSION & 0xFF; |
ivygatech | 0:de1ab53f3480 | 134 | |
ivygatech | 0:de1ab53f3480 | 135 | pmmc = readVERSION(command, 2); |
ivygatech | 0:de1ab53f3480 | 136 | |
ivygatech | 0:de1ab53f3480 | 137 | pc.printf("pmmc:%d\n",pmmc); |
ivygatech | 0:de1ab53f3480 | 138 | } |
ivygatech | 0:de1ab53f3480 | 139 | |
ivygatech | 0:de1ab53f3480 | 140 | //************************************************************************** |
ivygatech | 0:de1ab53f3480 | 141 | void uVGAIII :: baudrate(int speed) { // set screen baud rate |
ivygatech | 0:de1ab53f3480 | 142 | char command[4]= ""; |
ivygatech | 0:de1ab53f3480 | 143 | command[0] = ( BAUDRATE >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 144 | command[1] = BAUDRATE & 0xFF; |
ivygatech | 0:de1ab53f3480 | 145 | switch (speed) { |
ivygatech | 0:de1ab53f3480 | 146 | case 110 : |
ivygatech | 0:de1ab53f3480 | 147 | command[2] = ( BAUD_110 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 148 | command[3] = BAUD_110 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 149 | break; |
ivygatech | 0:de1ab53f3480 | 150 | case 300 : |
ivygatech | 0:de1ab53f3480 | 151 | command[2] = ( BAUD_300 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 152 | command[3] = BAUD_300 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 153 | break; |
ivygatech | 0:de1ab53f3480 | 154 | case 600 : |
ivygatech | 0:de1ab53f3480 | 155 | command[2] = ( BAUD_600 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 156 | command[3] = BAUD_600 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 157 | break; |
ivygatech | 0:de1ab53f3480 | 158 | case 1200 : |
ivygatech | 0:de1ab53f3480 | 159 | command[2] = ( BAUD_1200>> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 160 | command[3] = BAUD_1200 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 161 | break; |
ivygatech | 0:de1ab53f3480 | 162 | case 2400 : |
ivygatech | 0:de1ab53f3480 | 163 | command[2] = ( BAUD_2400 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 164 | command[3] = BAUD_2400 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 165 | break; |
ivygatech | 0:de1ab53f3480 | 166 | case 4800 : |
ivygatech | 0:de1ab53f3480 | 167 | command[2] = ( BAUD_4800 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 168 | command[3] = BAUD_4800 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 169 | break; |
ivygatech | 0:de1ab53f3480 | 170 | case 9600 : |
ivygatech | 0:de1ab53f3480 | 171 | command[2] = ( BAUD_9600 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 172 | command[3] = BAUD_9600 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 173 | break; |
ivygatech | 0:de1ab53f3480 | 174 | case 14400 : |
ivygatech | 0:de1ab53f3480 | 175 | command[2] = ( BAUD_9600 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 176 | command[3] = BAUD_9600 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 177 | break; |
ivygatech | 0:de1ab53f3480 | 178 | case 19200 : |
ivygatech | 0:de1ab53f3480 | 179 | command[2] = ( BAUD_19200 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 180 | command[3] = BAUD_19200 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 181 | break; |
ivygatech | 0:de1ab53f3480 | 182 | case 31250 : |
ivygatech | 0:de1ab53f3480 | 183 | command[2] = ( BAUD_31250 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 184 | command[3] = BAUD_31250 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 185 | break; |
ivygatech | 0:de1ab53f3480 | 186 | case 38400 : |
ivygatech | 0:de1ab53f3480 | 187 | command[2] = ( BAUD_38400 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 188 | command[3] = BAUD_38400 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 189 | break; |
ivygatech | 0:de1ab53f3480 | 190 | case 56000 : |
ivygatech | 0:de1ab53f3480 | 191 | command[2] = ( BAUD_56000 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 192 | command[3] = BAUD_56000 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 193 | break; |
ivygatech | 0:de1ab53f3480 | 194 | case 57600 : |
ivygatech | 0:de1ab53f3480 | 195 | command[2] = ( BAUD_57600 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 196 | command[3] = BAUD_57600 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 197 | break; |
ivygatech | 0:de1ab53f3480 | 198 | case 115200 : |
ivygatech | 0:de1ab53f3480 | 199 | command[2] = ( BAUD_115200 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 200 | command[3] = BAUD_115200 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 201 | break; |
ivygatech | 0:de1ab53f3480 | 202 | case 128000 : |
ivygatech | 0:de1ab53f3480 | 203 | command[2] = ( BAUD_128000 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 204 | command[3] = BAUD_128000 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 205 | break; |
ivygatech | 0:de1ab53f3480 | 206 | case 256000 : |
ivygatech | 0:de1ab53f3480 | 207 | command[2] = ( BAUD_256000 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 208 | command[3] = BAUD_256000 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 209 | break; |
ivygatech | 0:de1ab53f3480 | 210 | default : |
ivygatech | 0:de1ab53f3480 | 211 | command[2] = ( BAUD_9600 >> 8 ) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 212 | command[3] = BAUD_9600 & 0xFF; |
ivygatech | 0:de1ab53f3480 | 213 | speed = 9600; |
ivygatech | 0:de1ab53f3480 | 214 | break; |
ivygatech | 0:de1ab53f3480 | 215 | } |
ivygatech | 0:de1ab53f3480 | 216 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 217 | pc.printf("\n"); |
ivygatech | 0:de1ab53f3480 | 218 | pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); |
ivygatech | 0:de1ab53f3480 | 219 | #endif |
ivygatech | 0:de1ab53f3480 | 220 | int i, resp = 0; |
ivygatech | 0:de1ab53f3480 | 221 | freeBUFFER(); |
ivygatech | 0:de1ab53f3480 | 222 | |
ivygatech | 0:de1ab53f3480 | 223 | for (i = 0; i < 4; i++) writeBYTE(command[i]); // send command to serial port |
ivygatech | 0:de1ab53f3480 | 224 | wait_ms(5); |
ivygatech | 0:de1ab53f3480 | 225 | _cmd.baud(speed); // set mbed to same speed |
ivygatech | 0:de1ab53f3480 | 226 | |
ivygatech | 0:de1ab53f3480 | 227 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
ivygatech | 0:de1ab53f3480 | 228 | if (_cmd.readable()) resp = _cmd.getc(); // read response if any |
ivygatech | 0:de1ab53f3480 | 229 | |
ivygatech | 0:de1ab53f3480 | 230 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 231 | pc.printf("response = 0x%02X\n",resp); |
ivygatech | 0:de1ab53f3480 | 232 | #endif |
ivygatech | 0:de1ab53f3480 | 233 | |
ivygatech | 0:de1ab53f3480 | 234 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 235 | pc.printf("Set baudrate completed.\n"); |
ivygatech | 0:de1ab53f3480 | 236 | #endif |
ivygatech | 0:de1ab53f3480 | 237 | } |
ivygatech | 0:de1ab53f3480 | 238 | |
ivygatech | 0:de1ab53f3480 | 239 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 240 | int uVGAIII :: readVERSION(char *command, int number) { // read screen info and populate data |
ivygatech | 0:de1ab53f3480 | 241 | |
ivygatech | 0:de1ab53f3480 | 242 | int i, temp = 0, resp = 0; |
ivygatech | 0:de1ab53f3480 | 243 | char response[5] = ""; |
ivygatech | 0:de1ab53f3480 | 244 | |
ivygatech | 0:de1ab53f3480 | 245 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 246 | pc.printf("\n"); |
ivygatech | 0:de1ab53f3480 | 247 | pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); |
ivygatech | 0:de1ab53f3480 | 248 | #endif |
ivygatech | 0:de1ab53f3480 | 249 | |
ivygatech | 0:de1ab53f3480 | 250 | freeBUFFER(); |
ivygatech | 0:de1ab53f3480 | 251 | |
ivygatech | 0:de1ab53f3480 | 252 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
ivygatech | 0:de1ab53f3480 | 253 | |
ivygatech | 0:de1ab53f3480 | 254 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
ivygatech | 0:de1ab53f3480 | 255 | |
ivygatech | 0:de1ab53f3480 | 256 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
ivygatech | 0:de1ab53f3480 | 257 | temp = _cmd.getc(); |
ivygatech | 0:de1ab53f3480 | 258 | response[resp] = (char)temp; |
ivygatech | 0:de1ab53f3480 | 259 | pc.printf("response = 0x%02X\n",response[resp]); |
ivygatech | 0:de1ab53f3480 | 260 | resp++; |
ivygatech | 0:de1ab53f3480 | 261 | } |
ivygatech | 0:de1ab53f3480 | 262 | switch (resp) { |
ivygatech | 0:de1ab53f3480 | 263 | case 3 : // if OK populate data and return version |
ivygatech | 0:de1ab53f3480 | 264 | version = int(response[1]) << 8 | response[2]; |
ivygatech | 0:de1ab53f3480 | 265 | break; |
ivygatech | 0:de1ab53f3480 | 266 | default : |
ivygatech | 0:de1ab53f3480 | 267 | version = 0; // return 0 |
ivygatech | 0:de1ab53f3480 | 268 | break; |
ivygatech | 0:de1ab53f3480 | 269 | } |
ivygatech | 0:de1ab53f3480 | 270 | return version; |
ivygatech | 0:de1ab53f3480 | 271 | } |
ivygatech | 0:de1ab53f3480 | 272 | |
ivygatech | 0:de1ab53f3480 | 273 | //**************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 274 | void uVGAIII :: set_volume(char value) { // set sound volume to value |
ivygatech | 0:de1ab53f3480 | 275 | char command[4] = ""; |
ivygatech | 0:de1ab53f3480 | 276 | |
ivygatech | 0:de1ab53f3480 | 277 | command[0] = (SETVOLUME >> 8) & 0xFF; |
ivygatech | 0:de1ab53f3480 | 278 | command[1] = SETVOLUME & 0xFF; |
ivygatech | 0:de1ab53f3480 | 279 | |
ivygatech | 0:de1ab53f3480 | 280 | command[2] = 0; |
ivygatech | 0:de1ab53f3480 | 281 | command[3] = value; |
ivygatech | 0:de1ab53f3480 | 282 | |
ivygatech | 0:de1ab53f3480 | 283 | writeCOMMAND(command, 4, 1); |
ivygatech | 0:de1ab53f3480 | 284 | |
ivygatech | 0:de1ab53f3480 | 285 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 286 | pc.printf("Sound volume completed.\n"); |
ivygatech | 0:de1ab53f3480 | 287 | #endif |
ivygatech | 0:de1ab53f3480 | 288 | } |
ivygatech | 0:de1ab53f3480 | 289 | |
ivygatech | 0:de1ab53f3480 | 290 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 291 | void uVGAIII :: getTOUCH(char *command, int number, int *xy) { // read screen info and populate data |
ivygatech | 0:de1ab53f3480 | 292 | |
ivygatech | 0:de1ab53f3480 | 293 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 294 | pc.printf("\n"); |
ivygatech | 0:de1ab53f3480 | 295 | pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); |
ivygatech | 0:de1ab53f3480 | 296 | #endif |
ivygatech | 0:de1ab53f3480 | 297 | int i, temp = 0, resp = 0; |
ivygatech | 0:de1ab53f3480 | 298 | char response[5] = ""; |
ivygatech | 0:de1ab53f3480 | 299 | |
ivygatech | 0:de1ab53f3480 | 300 | freeBUFFER(); |
ivygatech | 0:de1ab53f3480 | 301 | |
ivygatech | 0:de1ab53f3480 | 302 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
ivygatech | 0:de1ab53f3480 | 303 | |
ivygatech | 0:de1ab53f3480 | 304 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
ivygatech | 0:de1ab53f3480 | 305 | |
ivygatech | 0:de1ab53f3480 | 306 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
ivygatech | 0:de1ab53f3480 | 307 | temp = _cmd.getc(); |
ivygatech | 0:de1ab53f3480 | 308 | response[resp++] = (char)temp; |
ivygatech | 0:de1ab53f3480 | 309 | } |
ivygatech | 0:de1ab53f3480 | 310 | |
ivygatech | 0:de1ab53f3480 | 311 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 312 | pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2]); |
ivygatech | 0:de1ab53f3480 | 313 | #endif |
ivygatech | 0:de1ab53f3480 | 314 | |
ivygatech | 0:de1ab53f3480 | 315 | switch (resp) { |
ivygatech | 0:de1ab53f3480 | 316 | case 3 : // if OK populate data |
ivygatech | 0:de1ab53f3480 | 317 | *xy = ((response[1]<<8)+ response[2]) * (response[1] != 0xFF); |
ivygatech | 0:de1ab53f3480 | 318 | break; |
ivygatech | 0:de1ab53f3480 | 319 | default : |
ivygatech | 0:de1ab53f3480 | 320 | *xy = -1; |
ivygatech | 0:de1ab53f3480 | 321 | break; |
ivygatech | 0:de1ab53f3480 | 322 | } |
ivygatech | 0:de1ab53f3480 | 323 | |
ivygatech | 0:de1ab53f3480 | 324 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 325 | pc.printf(" X or Y : %03d\n", *xy); |
ivygatech | 0:de1ab53f3480 | 326 | #endif |
ivygatech | 0:de1ab53f3480 | 327 | } |
ivygatech | 0:de1ab53f3480 | 328 | |
ivygatech | 0:de1ab53f3480 | 329 | //****************************************************************************************************** |
ivygatech | 0:de1ab53f3480 | 330 | int uVGAIII :: getSTATUS(char *command, int number) { // read screen info and populate data |
ivygatech | 0:de1ab53f3480 | 331 | |
ivygatech | 0:de1ab53f3480 | 332 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 333 | pc.printf("\n"); |
ivygatech | 0:de1ab53f3480 | 334 | pc.printf("New COMMAND : 0x%02X%02X\n", command[0], command[1]); |
ivygatech | 0:de1ab53f3480 | 335 | #endif |
ivygatech | 0:de1ab53f3480 | 336 | |
ivygatech | 0:de1ab53f3480 | 337 | int i, temp = 0, resp = 0; |
ivygatech | 0:de1ab53f3480 | 338 | char response[5] = ""; |
ivygatech | 0:de1ab53f3480 | 339 | |
ivygatech | 0:de1ab53f3480 | 340 | freeBUFFER(); |
ivygatech | 0:de1ab53f3480 | 341 | |
ivygatech | 0:de1ab53f3480 | 342 | for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port |
ivygatech | 0:de1ab53f3480 | 343 | |
ivygatech | 0:de1ab53f3480 | 344 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
ivygatech | 0:de1ab53f3480 | 345 | |
ivygatech | 0:de1ab53f3480 | 346 | while (_cmd.readable() && resp < ARRAY_SIZE(response)) { |
ivygatech | 0:de1ab53f3480 | 347 | temp = _cmd.getc(); |
ivygatech | 0:de1ab53f3480 | 348 | response[resp++] = (char)temp; |
ivygatech | 0:de1ab53f3480 | 349 | } |
ivygatech | 0:de1ab53f3480 | 350 | switch (resp) { |
ivygatech | 0:de1ab53f3480 | 351 | case 3 : |
ivygatech | 0:de1ab53f3480 | 352 | resp = (int)response[2]; // if OK populate data |
ivygatech | 0:de1ab53f3480 | 353 | break; |
ivygatech | 0:de1ab53f3480 | 354 | default : |
ivygatech | 0:de1ab53f3480 | 355 | resp = -1; // else return 0 |
ivygatech | 0:de1ab53f3480 | 356 | break; |
ivygatech | 0:de1ab53f3480 | 357 | } |
ivygatech | 0:de1ab53f3480 | 358 | |
ivygatech | 0:de1ab53f3480 | 359 | #if DEBUGMODE |
ivygatech | 0:de1ab53f3480 | 360 | pc.printf(" Answer received : %d\n", resp); |
ivygatech | 0:de1ab53f3480 | 361 | #endif |
ivygatech | 0:de1ab53f3480 | 362 | |
ivygatech | 0:de1ab53f3480 | 363 | return resp; |
ivygatech | 0:de1ab53f3480 | 364 | } |