Dependents: Telecommande_prologue
TFT_4DGL_Graphics.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 | |
projetremote | 0:277186c9dd25 | 23 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 24 | void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) |
projetremote | 0:277186c9dd25 | 25 | char command[9]= ""; |
projetremote | 0:277186c9dd25 | 26 | |
projetremote | 0:277186c9dd25 | 27 | command[0] = CIRCLE; |
projetremote | 0:277186c9dd25 | 28 | |
projetremote | 0:277186c9dd25 | 29 | command[1] = (x >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 30 | command[2] = x & 0xFF; |
projetremote | 0:277186c9dd25 | 31 | |
projetremote | 0:277186c9dd25 | 32 | command[3] = (y >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 33 | command[4] = y & 0xFF; |
projetremote | 0:277186c9dd25 | 34 | |
projetremote | 0:277186c9dd25 | 35 | command[5] = (radius >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 36 | command[6] = radius & 0xFF; |
projetremote | 0:277186c9dd25 | 37 | |
projetremote | 0:277186c9dd25 | 38 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 39 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 40 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 41 | |
projetremote | 0:277186c9dd25 | 42 | command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 43 | command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 44 | |
projetremote | 0:277186c9dd25 | 45 | writeCOMMAND(command, 9); |
projetremote | 0:277186c9dd25 | 46 | } |
projetremote | 0:277186c9dd25 | 47 | |
projetremote | 0:277186c9dd25 | 48 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 49 | void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle |
projetremote | 0:277186c9dd25 | 50 | char command[15]= ""; |
projetremote | 0:277186c9dd25 | 51 | |
projetremote | 0:277186c9dd25 | 52 | command[0] = TRIANGLE; |
projetremote | 0:277186c9dd25 | 53 | |
projetremote | 0:277186c9dd25 | 54 | command[1] = (x1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 55 | command[2] = x1 & 0xFF; |
projetremote | 0:277186c9dd25 | 56 | |
projetremote | 0:277186c9dd25 | 57 | command[3] = (y1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 58 | command[4] = y1 & 0xFF; |
projetremote | 0:277186c9dd25 | 59 | |
projetremote | 0:277186c9dd25 | 60 | command[5] = (x2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 61 | command[6] = x2 & 0xFF; |
projetremote | 0:277186c9dd25 | 62 | |
projetremote | 0:277186c9dd25 | 63 | command[7] = (y2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 64 | command[8] = y2 & 0xFF; |
projetremote | 0:277186c9dd25 | 65 | |
projetremote | 0:277186c9dd25 | 66 | command[9] = (x3 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 67 | command[10] = x3 & 0xFF; |
projetremote | 0:277186c9dd25 | 68 | |
projetremote | 0:277186c9dd25 | 69 | command[11] = (y3 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 70 | command[12] = y3 & 0xFF; |
projetremote | 0:277186c9dd25 | 71 | |
projetremote | 0:277186c9dd25 | 72 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 73 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 74 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 75 | |
projetremote | 0:277186c9dd25 | 76 | command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 77 | command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 78 | |
projetremote | 0:277186c9dd25 | 79 | writeCOMMAND(command, 15); |
projetremote | 0:277186c9dd25 | 80 | } |
projetremote | 0:277186c9dd25 | 81 | |
projetremote | 0:277186c9dd25 | 82 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 83 | void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line |
projetremote | 0:277186c9dd25 | 84 | char command[11]= ""; |
projetremote | 0:277186c9dd25 | 85 | |
projetremote | 0:277186c9dd25 | 86 | command[0] = LINE; |
projetremote | 0:277186c9dd25 | 87 | |
projetremote | 0:277186c9dd25 | 88 | command[1] = (x1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 89 | command[2] = x1 & 0xFF; |
projetremote | 0:277186c9dd25 | 90 | |
projetremote | 0:277186c9dd25 | 91 | command[3] = (y1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 92 | command[4] = y1 & 0xFF; |
projetremote | 0:277186c9dd25 | 93 | |
projetremote | 0:277186c9dd25 | 94 | command[5] = (x2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 95 | command[6] = x2 & 0xFF; |
projetremote | 0:277186c9dd25 | 96 | |
projetremote | 0:277186c9dd25 | 97 | command[7] = (y2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 98 | command[8] = y2 & 0xFF; |
projetremote | 0:277186c9dd25 | 99 | |
projetremote | 0:277186c9dd25 | 100 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 101 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 102 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 103 | |
projetremote | 0:277186c9dd25 | 104 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 105 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 106 | |
projetremote | 0:277186c9dd25 | 107 | writeCOMMAND(command, 11); |
projetremote | 0:277186c9dd25 | 108 | } |
projetremote | 0:277186c9dd25 | 109 | |
projetremote | 0:277186c9dd25 | 110 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 111 | void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle |
projetremote | 0:277186c9dd25 | 112 | char command[11]= ""; |
projetremote | 0:277186c9dd25 | 113 | |
projetremote | 0:277186c9dd25 | 114 | command[0] = RECTANGLE; |
projetremote | 0:277186c9dd25 | 115 | |
projetremote | 0:277186c9dd25 | 116 | command[1] = (x1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 117 | command[2] = x1 & 0xFF; |
projetremote | 0:277186c9dd25 | 118 | |
projetremote | 0:277186c9dd25 | 119 | command[3] = (y1 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 120 | command[4] = y1 & 0xFF; |
projetremote | 0:277186c9dd25 | 121 | |
projetremote | 0:277186c9dd25 | 122 | command[5] = (x2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 123 | command[6] = x2 & 0xFF; |
projetremote | 0:277186c9dd25 | 124 | |
projetremote | 0:277186c9dd25 | 125 | command[7] = (y2 >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 126 | command[8] = y2 & 0xFF; |
projetremote | 0:277186c9dd25 | 127 | |
projetremote | 0:277186c9dd25 | 128 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 129 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 130 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 131 | |
projetremote | 0:277186c9dd25 | 132 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 133 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 134 | |
projetremote | 0:277186c9dd25 | 135 | writeCOMMAND(command, 11); |
projetremote | 0:277186c9dd25 | 136 | } |
projetremote | 0:277186c9dd25 | 137 | |
projetremote | 0:277186c9dd25 | 138 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 139 | void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse |
projetremote | 0:277186c9dd25 | 140 | char command[11]= ""; |
projetremote | 0:277186c9dd25 | 141 | |
projetremote | 0:277186c9dd25 | 142 | command[0] = ELLIPSE; |
projetremote | 0:277186c9dd25 | 143 | |
projetremote | 0:277186c9dd25 | 144 | command[1] = (x >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 145 | command[2] = x & 0xFF; |
projetremote | 0:277186c9dd25 | 146 | |
projetremote | 0:277186c9dd25 | 147 | command[3] = (y >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 148 | command[4] = y & 0xFF; |
projetremote | 0:277186c9dd25 | 149 | |
projetremote | 0:277186c9dd25 | 150 | command[5] = (radius_x >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 151 | command[6] = radius_x & 0xFF; |
projetremote | 0:277186c9dd25 | 152 | |
projetremote | 0:277186c9dd25 | 153 | command[7] = (radius_y >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 154 | command[8] = radius_y & 0xFF; |
projetremote | 0:277186c9dd25 | 155 | |
projetremote | 0:277186c9dd25 | 156 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 157 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 158 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 159 | |
projetremote | 0:277186c9dd25 | 160 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 161 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 162 | |
projetremote | 0:277186c9dd25 | 163 | writeCOMMAND(command, 11); |
projetremote | 0:277186c9dd25 | 164 | } |
projetremote | 0:277186c9dd25 | 165 | |
projetremote | 0:277186c9dd25 | 166 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 167 | void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel |
projetremote | 0:277186c9dd25 | 168 | char command[7]= ""; |
projetremote | 0:277186c9dd25 | 169 | |
projetremote | 0:277186c9dd25 | 170 | command[0] = PIXEL; |
projetremote | 0:277186c9dd25 | 171 | |
projetremote | 0:277186c9dd25 | 172 | command[1] = (x >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 173 | command[2] = x & 0xFF; |
projetremote | 0:277186c9dd25 | 174 | |
projetremote | 0:277186c9dd25 | 175 | command[3] = (y >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 176 | command[4] = y & 0xFF; |
projetremote | 0:277186c9dd25 | 177 | |
projetremote | 0:277186c9dd25 | 178 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
projetremote | 0:277186c9dd25 | 179 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
projetremote | 0:277186c9dd25 | 180 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
projetremote | 0:277186c9dd25 | 181 | |
projetremote | 0:277186c9dd25 | 182 | command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
projetremote | 0:277186c9dd25 | 183 | command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
projetremote | 0:277186c9dd25 | 184 | |
projetremote | 0:277186c9dd25 | 185 | writeCOMMAND(command, 7); |
projetremote | 0:277186c9dd25 | 186 | } |
projetremote | 0:277186c9dd25 | 187 | |
projetremote | 0:277186c9dd25 | 188 | //****************************************************************************************************** |
projetremote | 0:277186c9dd25 | 189 | int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data |
projetremote | 0:277186c9dd25 | 190 | |
projetremote | 0:277186c9dd25 | 191 | char command[5]= ""; |
projetremote | 0:277186c9dd25 | 192 | |
projetremote | 0:277186c9dd25 | 193 | command[0] = READPIXEL; |
projetremote | 0:277186c9dd25 | 194 | |
projetremote | 0:277186c9dd25 | 195 | command[1] = (x >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 196 | command[2] = x & 0xFF; |
projetremote | 0:277186c9dd25 | 197 | |
projetremote | 0:277186c9dd25 | 198 | command[3] = (y >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 199 | command[4] = y & 0xFF; |
projetremote | 0:277186c9dd25 | 200 | |
projetremote | 0:277186c9dd25 | 201 | int i, temp = 0, color = 0, resp = 0; |
projetremote | 0:277186c9dd25 | 202 | char response[2] = ""; |
projetremote | 0:277186c9dd25 | 203 | |
projetremote | 0:277186c9dd25 | 204 | freeBUFFER(); |
projetremote | 0:277186c9dd25 | 205 | |
projetremote | 0:277186c9dd25 | 206 | for (i = 0; i < 5; i++) { // send all chars to serial port |
projetremote | 0:277186c9dd25 | 207 | writeBYTE(command[i]); |
projetremote | 0:277186c9dd25 | 208 | } |
projetremote | 0:277186c9dd25 | 209 | |
projetremote | 0:277186c9dd25 | 210 | while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer |
projetremote | 0:277186c9dd25 | 211 | |
projetremote | 0:277186c9dd25 | 212 | while (_cmd.readable()) { |
projetremote | 0:277186c9dd25 | 213 | temp = _cmd.getc(); |
projetremote | 0:277186c9dd25 | 214 | response[resp++] = (char)temp; |
projetremote | 0:277186c9dd25 | 215 | } |
projetremote | 0:277186c9dd25 | 216 | |
projetremote | 0:277186c9dd25 | 217 | color = ((response[0] << 8) + response[1]); |
projetremote | 0:277186c9dd25 | 218 | |
projetremote | 0:277186c9dd25 | 219 | return color; // WARNING : this is 16bits color, not 24bits... need to be fixed |
projetremote | 0:277186c9dd25 | 220 | } |
projetremote | 0:277186c9dd25 | 221 | |
projetremote | 0:277186c9dd25 | 222 | //****************************************************************************************************** |
projetremote | 0:277186c9dd25 | 223 | void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { |
projetremote | 0:277186c9dd25 | 224 | |
projetremote | 0:277186c9dd25 | 225 | char command[13]= ""; |
projetremote | 0:277186c9dd25 | 226 | |
projetremote | 0:277186c9dd25 | 227 | command[0] = SCREENCOPY; |
projetremote | 0:277186c9dd25 | 228 | |
projetremote | 0:277186c9dd25 | 229 | command[1] = (xs >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 230 | command[2] = xs & 0xFF; |
projetremote | 0:277186c9dd25 | 231 | |
projetremote | 0:277186c9dd25 | 232 | command[3] = (ys >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 233 | command[4] = ys & 0xFF; |
projetremote | 0:277186c9dd25 | 234 | |
projetremote | 0:277186c9dd25 | 235 | command[5] = (xd >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 236 | command[6] = xd & 0xFF; |
projetremote | 0:277186c9dd25 | 237 | |
projetremote | 0:277186c9dd25 | 238 | command[7] = (yd >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 239 | command[8] = yd & 0xFF; |
projetremote | 0:277186c9dd25 | 240 | |
projetremote | 0:277186c9dd25 | 241 | command[9] = (width >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 242 | command[10] = width & 0xFF; |
projetremote | 0:277186c9dd25 | 243 | |
projetremote | 0:277186c9dd25 | 244 | command[11] = (height >> 8) & 0xFF; |
projetremote | 0:277186c9dd25 | 245 | command[12] = height & 0xFF; |
projetremote | 0:277186c9dd25 | 246 | writeCOMMAND(command, 13); |
projetremote | 0:277186c9dd25 | 247 | } |
projetremote | 0:277186c9dd25 | 248 | |
projetremote | 0:277186c9dd25 | 249 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 250 | void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME |
projetremote | 0:277186c9dd25 | 251 | char command[2]= ""; |
projetremote | 0:277186c9dd25 | 252 | |
projetremote | 0:277186c9dd25 | 253 | command[0] = PENSIZE; |
projetremote | 0:277186c9dd25 | 254 | command[1] = mode; |
projetremote | 0:277186c9dd25 | 255 | |
projetremote | 0:277186c9dd25 | 256 | writeCOMMAND(command, 2); |
projetremote | 0:277186c9dd25 | 257 | } |
projetremote | 0:277186c9dd25 | 258 | |
projetremote | 0:277186c9dd25 | 259 | void TFT_4DGL :: SD_Card_Wav(char *Filename) { |
projetremote | 0:277186c9dd25 | 260 | char command[21]= ""; |
projetremote | 0:277186c9dd25 | 261 | int Lgt=0; |
projetremote | 0:277186c9dd25 | 262 | |
projetremote | 0:277186c9dd25 | 263 | command[0] = 0x40; //ext_cmd |
projetremote | 0:277186c9dd25 | 264 | command[1] = 0x6C; //Play Audio |
projetremote | 0:277186c9dd25 | 265 | command[2] = 0x01; //Option 0x00=Return at end, 0x01=Return now, 0x02=Stop, 0x03=Pause, 0x04=Resume, 0x05=Loop. |
projetremote | 0:277186c9dd25 | 266 | for(int i=0;Filename[i]!=0x00;i++){ |
projetremote | 0:277186c9dd25 | 267 | command[i+3] = Filename[i]; |
projetremote | 0:277186c9dd25 | 268 | Lgt = i; |
projetremote | 0:277186c9dd25 | 269 | } |
projetremote | 0:277186c9dd25 | 270 | command[Lgt+4] = 0x2E; //. |
projetremote | 0:277186c9dd25 | 271 | command[Lgt+5] = 0x77; //w |
projetremote | 0:277186c9dd25 | 272 | command[Lgt+6] = 0x61; //a |
projetremote | 0:277186c9dd25 | 273 | command[Lgt+7] = 0x76; //v |
projetremote | 0:277186c9dd25 | 274 | command[Lgt+8] = 0x00; //terminator |
projetremote | 0:277186c9dd25 | 275 | |
projetremote | 0:277186c9dd25 | 276 | writeCOMMAND(command, Lgt+9); |
projetremote | 0:277186c9dd25 | 277 | } |
projetremote | 0:277186c9dd25 | 278 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 279 | // This sets the volume for the speaker on the uLCD-32PT |
projetremote | 0:277186c9dd25 | 280 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 281 | void TFT_4DGL :: Set_Volume(char vol) { |
projetremote | 0:277186c9dd25 | 282 | |
projetremote | 0:277186c9dd25 | 283 | char command[2]= ""; |
projetremote | 0:277186c9dd25 | 284 | command[0] = 0x76; //cmd |
projetremote | 0:277186c9dd25 | 285 | command[1] = vol; //set volume |
projetremote | 0:277186c9dd25 | 286 | |
projetremote | 0:277186c9dd25 | 287 | writeCOMMAND(command, 2); |
projetremote | 0:277186c9dd25 | 288 | } |
projetremote | 0:277186c9dd25 | 289 | |
projetremote | 0:277186c9dd25 | 290 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 291 | // This displays an image on the screen that is stored on the FAT partition of an uSD Card |
projetremote | 0:277186c9dd25 | 292 | // Sent Filename, X-pos, Y-pos, Sector Address - Display from the RAW partition is quicker |
projetremote | 0:277186c9dd25 | 293 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 294 | void TFT_4DGL :: uSD_FAT_Image(char *Filename, int x, int y, long s) { |
projetremote | 0:277186c9dd25 | 295 | char X_MSB, X_LSB, Y_MSB, Y_LSB, S0, S1, S2, S3; |
projetremote | 0:277186c9dd25 | 296 | char command[25]= ""; |
projetremote | 0:277186c9dd25 | 297 | int Lgt=0; |
projetremote | 0:277186c9dd25 | 298 | |
projetremote | 0:277186c9dd25 | 299 | X_LSB = x&0x00FF; |
projetremote | 0:277186c9dd25 | 300 | X_MSB = (x >> 8); |
projetremote | 0:277186c9dd25 | 301 | Y_LSB = y&0x00FF; |
projetremote | 0:277186c9dd25 | 302 | Y_MSB = (y >> 8); |
projetremote | 0:277186c9dd25 | 303 | |
projetremote | 0:277186c9dd25 | 304 | S0 = (s >> 20)&0x000000FF; |
projetremote | 0:277186c9dd25 | 305 | S1 = (s >> 16)&0x0000FF; |
projetremote | 0:277186c9dd25 | 306 | S2 = (s >> 8)&0x0000FF; |
projetremote | 0:277186c9dd25 | 307 | S3 = s&0x0000FF;; |
projetremote | 0:277186c9dd25 | 308 | |
projetremote | 0:277186c9dd25 | 309 | command[0] = '@'; //ext_cmd |
projetremote | 0:277186c9dd25 | 310 | command[1] = 'm'; //FAT Image |
projetremote | 0:277186c9dd25 | 311 | for(int i=0;Filename[i]!=0x00;i++){ |
projetremote | 0:277186c9dd25 | 312 | command[i+2] = Filename[i]; |
projetremote | 0:277186c9dd25 | 313 | Lgt = i; |
projetremote | 0:277186c9dd25 | 314 | } |
projetremote | 0:277186c9dd25 | 315 | command[Lgt+3] = '.'; //. |
projetremote | 0:277186c9dd25 | 316 | command[Lgt+4] = 'G'; //G |
projetremote | 0:277186c9dd25 | 317 | command[Lgt+5] = 'C'; //C |
projetremote | 0:277186c9dd25 | 318 | command[Lgt+6] = 'I'; //I |
projetremote | 0:277186c9dd25 | 319 | command[Lgt+7] = 0x00; //Terminator |
projetremote | 0:277186c9dd25 | 320 | command[Lgt+8] = X_MSB; //X-Position MSB |
projetremote | 0:277186c9dd25 | 321 | command[Lgt+9] = X_LSB; //X-Position LSB |
projetremote | 0:277186c9dd25 | 322 | command[Lgt+10] = Y_MSB; //Y-Position MSB |
projetremote | 0:277186c9dd25 | 323 | command[Lgt+11] = Y_LSB; //Y-Position LSB |
projetremote | 0:277186c9dd25 | 324 | command[Lgt+12] = S0; //Sector Address 4 bytes |
projetremote | 0:277186c9dd25 | 325 | command[Lgt+13] = S1; |
projetremote | 0:277186c9dd25 | 326 | command[Lgt+14] = S2; |
projetremote | 0:277186c9dd25 | 327 | command[Lgt+15] = S3; |
projetremote | 0:277186c9dd25 | 328 | |
projetremote | 0:277186c9dd25 | 329 | writeCOMMAND(command, Lgt+16); |
projetremote | 0:277186c9dd25 | 330 | } |
projetremote | 0:277186c9dd25 | 331 | |
projetremote | 0:277186c9dd25 | 332 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 333 | // This displays an image on the screen in the NEW FORMAT |
projetremote | 0:277186c9dd25 | 334 | // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display images |
projetremote | 0:277186c9dd25 | 335 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 336 | void TFT_4DGL :: uSD_Image(int x, int y, long s) { |
projetremote | 0:277186c9dd25 | 337 | char S1, S2, S3; |
projetremote | 0:277186c9dd25 | 338 | char X_MSB, X_LSB, Y_MSB, Y_LSB; |
projetremote | 0:277186c9dd25 | 339 | char command[9]= ""; |
projetremote | 0:277186c9dd25 | 340 | |
projetremote | 0:277186c9dd25 | 341 | X_LSB = x&0x00FF; //Work out the x position |
projetremote | 0:277186c9dd25 | 342 | X_MSB = (x >> 8); |
projetremote | 0:277186c9dd25 | 343 | Y_LSB = y&0x00FF; //Work out the y position |
projetremote | 0:277186c9dd25 | 344 | Y_MSB = (y >> 8); |
projetremote | 0:277186c9dd25 | 345 | |
projetremote | 0:277186c9dd25 | 346 | S1 = (s >> 16)&0x0000FF; //Work out the sector address |
projetremote | 0:277186c9dd25 | 347 | S2 = (s >> 8)&0x0000FF; |
projetremote | 0:277186c9dd25 | 348 | S3 = s&0x0000FF; |
projetremote | 0:277186c9dd25 | 349 | |
projetremote | 0:277186c9dd25 | 350 | command[0] = 0x40; //ext_cmd |
projetremote | 0:277186c9dd25 | 351 | command[1] = 0x49; //Display image |
projetremote | 0:277186c9dd25 | 352 | command[2] = X_MSB; //X position - 2 bytes |
projetremote | 0:277186c9dd25 | 353 | command[3] = X_LSB; |
projetremote | 0:277186c9dd25 | 354 | command[4] = Y_MSB; //Y position - 2 bytes |
projetremote | 0:277186c9dd25 | 355 | command[5] = Y_LSB; |
projetremote | 0:277186c9dd25 | 356 | command[6] = S1; //Sector address - 3 bytes |
projetremote | 0:277186c9dd25 | 357 | command[7] = S2; |
projetremote | 0:277186c9dd25 | 358 | command[8] = S3; |
projetremote | 0:277186c9dd25 | 359 | |
projetremote | 0:277186c9dd25 | 360 | writeCOMMAND(command, 9); |
projetremote | 0:277186c9dd25 | 361 | } |
projetremote | 0:277186c9dd25 | 362 | |
projetremote | 0:277186c9dd25 | 363 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 364 | // This displays an video on the screen in the NEW FORMAT |
projetremote | 0:277186c9dd25 | 365 | // Sent X-pos, Y-pos, Sector Address - This is the recommended way to display video |
projetremote | 0:277186c9dd25 | 366 | //**************************************************************************************************** |
projetremote | 0:277186c9dd25 | 367 | void TFT_4DGL :: uSD_Video(int x, int y, long s) { |
projetremote | 0:277186c9dd25 | 368 | char S1, S2, S3; |
projetremote | 0:277186c9dd25 | 369 | char X_MSB, X_LSB, Y_MSB, Y_LSB; |
projetremote | 0:277186c9dd25 | 370 | char command[10]= ""; |
projetremote | 0:277186c9dd25 | 371 | |
projetremote | 0:277186c9dd25 | 372 | X_LSB = x&0x00FF; |
projetremote | 0:277186c9dd25 | 373 | X_MSB = (x >> 8); |
projetremote | 0:277186c9dd25 | 374 | Y_LSB = y&0x00FF; |
projetremote | 0:277186c9dd25 | 375 | Y_MSB = (y >> 8); |
projetremote | 0:277186c9dd25 | 376 | |
projetremote | 0:277186c9dd25 | 377 | S1 = (s >> 16)&0x0000FF; |
projetremote | 0:277186c9dd25 | 378 | S2 = (s >> 8)&0x0000FF; |
projetremote | 0:277186c9dd25 | 379 | S3 = s&0x0000FF; |
projetremote | 0:277186c9dd25 | 380 | |
projetremote | 0:277186c9dd25 | 381 | command[0] = 0x40; //ext_cmd |
projetremote | 0:277186c9dd25 | 382 | command[1] = 0x56; //Display video |
projetremote | 0:277186c9dd25 | 383 | command[2] = X_MSB; //X position - 2 bytes |
projetremote | 0:277186c9dd25 | 384 | command[3] = X_LSB; |
projetremote | 0:277186c9dd25 | 385 | command[4] = Y_MSB; //Y position - 2 bytes |
projetremote | 0:277186c9dd25 | 386 | command[5] = Y_LSB; |
projetremote | 0:277186c9dd25 | 387 | command[6] = 0x00; //delay between frames |
projetremote | 0:277186c9dd25 | 388 | command[7] = S1; //Sector address - 3 bytes |
projetremote | 0:277186c9dd25 | 389 | command[8] = S2; |
projetremote | 0:277186c9dd25 | 390 | command[9] = S3; |
projetremote | 0:277186c9dd25 | 391 | |
projetremote | 0:277186c9dd25 | 392 | writeCOMMAND(command, 10); |
projetremote | 0:277186c9dd25 | 393 | } |