Circular limit cycle - 2D nonlinear attractor

Dependencies:   mbed

Committer:
JLS
Date:
Tue Feb 08 21:33:11 2011 +0000
Revision:
0:ba94dffa2c21

        

Who changed what in which revision?

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