MI0283QT Library Program demostration

Dependencies:   mbed MI0283QTlib

Committer:
clemente
Date:
Sat May 26 21:03:21 2012 +0000
Revision:
0:4c87cf4af8b5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
clemente 0:4c87cf4af8b5 1 #include "mbed.h"
clemente 0:4c87cf4af8b5 2 #include "Touchlib.h"
clemente 0:4c87cf4af8b5 3 #include "MI0283QTlib.h"
clemente 0:4c87cf4af8b5 4 #include "SDFileSystem.h"
clemente 0:4c87cf4af8b5 5 //
clemente 0:4c87cf4af8b5 6 #include "info.h"
clemente 0:4c87cf4af8b5 7 //
clemente 0:4c87cf4af8b5 8 #include "crocino.h"
clemente 0:4c87cf4af8b5 9
clemente 0:4c87cf4af8b5 10 unsigned char CheckRectangle (unsigned int X_up, unsigned int Y_up,unsigned int X_size, unsigned int Y_size, unsigned int X_point, unsigned int Y_point );
clemente 0:4c87cf4af8b5 11 void test_touch( void) ;
clemente 0:4c87cf4af8b5 12
clemente 0:4c87cf4af8b5 13 DigitalOut DBG_LED(LED1);
clemente 0:4c87cf4af8b5 14 DigitalOut myled(LED2);
clemente 0:4c87cf4af8b5 15 DigitalOut TS_CS(p15);
clemente 0:4c87cf4af8b5 16 DigitalIn MAKECAL( p30);
clemente 0:4c87cf4af8b5 17
clemente 0:4c87cf4af8b5 18 FILE *fp, *fpf;
clemente 0:4c87cf4af8b5 19
clemente 0:4c87cf4af8b5 20 TOUCHS ts( p11, p12, p13, p15, p29);
clemente 0:4c87cf4af8b5 21 GLCD lcd( p11, p12, p13, p14, p17, p26);
clemente 0:4c87cf4af8b5 22 SDFileSystem sd(p5, p6, p7, p8, "sd");
clemente 0:4c87cf4af8b5 23 //
clemente 0:4c87cf4af8b5 24 unsigned char imageLinebuffer[320*3];
clemente 0:4c87cf4af8b5 25 unsigned char docalibration=0;
clemente 0:4c87cf4af8b5 26
clemente 0:4c87cf4af8b5 27 int main() {
clemente 0:4c87cf4af8b5 28
clemente 0:4c87cf4af8b5 29 _TS_COORD ts_coord[3];
clemente 0:4c87cf4af8b5 30 TS_CS=1;
clemente 0:4c87cf4af8b5 31
clemente 0:4c87cf4af8b5 32 // I use the pin30 to force a calibration.
clemente 0:4c87cf4af8b5 33 MAKECAL.mode( PullUp);
clemente 0:4c87cf4af8b5 34
clemente 0:4c87cf4af8b5 35 // is there an sdcard?
clemente 0:4c87cf4af8b5 36 fp = fopen("/sd/mbed.txt", "w");
clemente 0:4c87cf4af8b5 37 if ( fp == NULL) {
clemente 0:4c87cf4af8b5 38 printf("Error opening file\r\n");
clemente 0:4c87cf4af8b5 39 DBG_LED=1;
clemente 0:4c87cf4af8b5 40 while(1);
clemente 0:4c87cf4af8b5 41 }
clemente 0:4c87cf4af8b5 42 fprintf( fp, "File mbed\n");
clemente 0:4c87cf4af8b5 43 fclose( fp);
clemente 0:4c87cf4af8b5 44
clemente 0:4c87cf4af8b5 45 // lcd init
clemente 0:4c87cf4af8b5 46 lcd.lcd_init();
clemente 0:4c87cf4af8b5 47 lcd.backlightoff();
clemente 0:4c87cf4af8b5 48 // some setup..
clemente 0:4c87cf4af8b5 49 lcd.lcd_setfontsmall();
clemente 0:4c87cf4af8b5 50 lcd.lcd_clear( LCD_WHITE);
clemente 0:4c87cf4af8b5 51 lcd.backlighton();
clemente 0:4c87cf4af8b5 52
clemente 0:4c87cf4af8b5 53 // splash screen...
clemente 0:4c87cf4af8b5 54 fp = fopen("/sd/images/mi0283qt.RGB", "rb");
clemente 0:4c87cf4af8b5 55 if ( fp != NULL) {
clemente 0:4c87cf4af8b5 56 lcd.lcd_drawimage( "/sd/images/mi0283qt.RGB");
clemente 0:4c87cf4af8b5 57 fclose( fp);
clemente 0:4c87cf4af8b5 58 wait(3);
clemente 0:4c87cf4af8b5 59 }
clemente 0:4c87cf4af8b5 60
clemente 0:4c87cf4af8b5 61 //
clemente 0:4c87cf4af8b5 62 lcd.lcd_clear( LCD_BLACK);
clemente 0:4c87cf4af8b5 63 // touch init...
clemente 0:4c87cf4af8b5 64 ts.init();
clemente 0:4c87cf4af8b5 65
clemente 0:4c87cf4af8b5 66 // 1. we check if there is a saved file with the calibration data...
clemente 0:4c87cf4af8b5 67 fp = fopen("/sd/ts_mtx.bin", "rb");
clemente 0:4c87cf4af8b5 68 if ( fp == NULL) {
clemente 0:4c87cf4af8b5 69 // not found...
clemente 0:4c87cf4af8b5 70 printf("ts_mtx.bin is not present.\r\n");
clemente 0:4c87cf4af8b5 71 // next we must start the calibration process...
clemente 0:4c87cf4af8b5 72 docalibration=1;
clemente 0:4c87cf4af8b5 73 } else {
clemente 0:4c87cf4af8b5 74 printf("ts_mtx.bin exist\r\n");
clemente 0:4c87cf4af8b5 75 unsigned char *pmatrix;
clemente 0:4c87cf4af8b5 76 /* we allocate memory to hold the saved caibration data. */
clemente 0:4c87cf4af8b5 77 pmatrix=(unsigned char*)malloc( ts.gettsmatrixsize());
clemente 0:4c87cf4af8b5 78 if( pmatrix==NULL) {
clemente 0:4c87cf4af8b5 79 printf("Error allocating memory\r\n");
clemente 0:4c87cf4af8b5 80 DBG_LED=1;
clemente 0:4c87cf4af8b5 81 while(1);
clemente 0:4c87cf4af8b5 82 }
clemente 0:4c87cf4af8b5 83 /* read the calibration data. */
clemente 0:4c87cf4af8b5 84 int mtxsize=fread( pmatrix, 1, ts.gettsmatrixsize(), fp);
clemente 0:4c87cf4af8b5 85 fclose( fp);
clemente 0:4c87cf4af8b5 86 printf("matrix_read: %d\r\n", mtxsize);
clemente 0:4c87cf4af8b5 87 if ( mtxsize != ts.gettsmatrixsize()) {
clemente 0:4c87cf4af8b5 88 printf("error reading the calibration data... force the calibration.\r\n");
clemente 0:4c87cf4af8b5 89 /* error reading the calibration data... force the calibration.*/
clemente 0:4c87cf4af8b5 90 docalibration=1;
clemente 0:4c87cf4af8b5 91 free( pmatrix);
clemente 0:4c87cf4af8b5 92 } else {
clemente 0:4c87cf4af8b5 93 /* set the calibration data. */
clemente 0:4c87cf4af8b5 94 ts.settsmatrix( pmatrix);
clemente 0:4c87cf4af8b5 95 docalibration=0;
clemente 0:4c87cf4af8b5 96 free( pmatrix);
clemente 0:4c87cf4af8b5 97 }
clemente 0:4c87cf4af8b5 98 }
clemente 0:4c87cf4af8b5 99 //
clemente 0:4c87cf4af8b5 100 while( docalibration || MAKECAL==0) {
clemente 0:4c87cf4af8b5 101
clemente 0:4c87cf4af8b5 102 printf("Starting the calibration...\r\n");
clemente 0:4c87cf4af8b5 103 wait( 1);
clemente 0:4c87cf4af8b5 104
clemente 0:4c87cf4af8b5 105 /* reset the calibration flag. */
clemente 0:4c87cf4af8b5 106 ts.ts_val.calibration_done=0;
clemente 0:4c87cf4af8b5 107 lcd.lcd_drawstr( "TouchScreen Calibration... [1/3]", 0, 0, lcd.lcd_RGB( 0, 255, 0));
clemente 0:4c87cf4af8b5 108 lcd.lcd_drawicon( &crocino[0], ts.getcrocino_x(0),ts.getcrocino_y(0), ts.crocino_size());
clemente 0:4c87cf4af8b5 109
clemente 0:4c87cf4af8b5 110 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 111 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 112 ts.do_tap();
clemente 0:4c87cf4af8b5 113 }
clemente 0:4c87cf4af8b5 114 //
clemente 0:4c87cf4af8b5 115 lcd.lcd_clear( ts.getcrocino_x(0),ts.getcrocino_y(0), ts.crocino_size(), ts.crocino_size(), LCD_BLACK );
clemente 0:4c87cf4af8b5 116 //
clemente 0:4c87cf4af8b5 117 ts_coord[0].x=ts.ts_val.coord.x; ts_coord[0].y=ts.ts_val.coord.y;
clemente 0:4c87cf4af8b5 118 //
clemente 0:4c87cf4af8b5 119 wait( 0.5);
clemente 0:4c87cf4af8b5 120 lcd.lcd_drawstr( "TouchScreen Calibration... [2/3]", 0, 0, lcd.lcd_RGB( 0, 255, 0));
clemente 0:4c87cf4af8b5 121 lcd.lcd_drawicon( &crocino[0], ts.getcrocino_x(1),ts.getcrocino_y(1), ts.crocino_size());
clemente 0:4c87cf4af8b5 122
clemente 0:4c87cf4af8b5 123 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 124 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 125 ts.do_tap();
clemente 0:4c87cf4af8b5 126 }
clemente 0:4c87cf4af8b5 127 //
clemente 0:4c87cf4af8b5 128 lcd.lcd_clear( ts.getcrocino_x(1),ts.getcrocino_y(1), ts.crocino_size(), ts.crocino_size(), LCD_BLACK );
clemente 0:4c87cf4af8b5 129 //
clemente 0:4c87cf4af8b5 130 ts_coord[1].x=ts.ts_val.coord.x; ts_coord[1].y=ts.ts_val.coord.y;
clemente 0:4c87cf4af8b5 131 //
clemente 0:4c87cf4af8b5 132 wait( 0.5);
clemente 0:4c87cf4af8b5 133 lcd.lcd_drawstr( "TouchScreen Calibration... [3/3]", 0, 0, lcd.lcd_RGB( 0, 255, 0));
clemente 0:4c87cf4af8b5 134 lcd.lcd_drawicon( &crocino[0], ts.getcrocino_x(2),ts.getcrocino_y(2), ts.crocino_size());
clemente 0:4c87cf4af8b5 135
clemente 0:4c87cf4af8b5 136 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 137 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 138 ts.do_tap();
clemente 0:4c87cf4af8b5 139 }
clemente 0:4c87cf4af8b5 140 //
clemente 0:4c87cf4af8b5 141 lcd.lcd_clear( ts.getcrocino_x(2),ts.getcrocino_y(2), ts.crocino_size(), ts.crocino_size(), LCD_BLACK );
clemente 0:4c87cf4af8b5 142 //
clemente 0:4c87cf4af8b5 143 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 144 ts_coord[2].x=ts.ts_val.coord.x; ts_coord[2].y=ts.ts_val.coord.y;
clemente 0:4c87cf4af8b5 145 //
clemente 0:4c87cf4af8b5 146 lcd.lcd_clear( LCD_BLACK);
clemente 0:4c87cf4af8b5 147 if ( ts.setcalibration( &ts_coord[0])) {
clemente 0:4c87cf4af8b5 148 lcd.lcd_drawstr( "TouchScreen Calibration... Done!", 0, 0, lcd.lcd_RGB( 0, 255, 0));
clemente 0:4c87cf4af8b5 149 wait( 3);
clemente 0:4c87cf4af8b5 150 /* save the file with the calibration data. */
clemente 0:4c87cf4af8b5 151 fp = fopen("/sd/ts_mtx.bin", "wb");
clemente 0:4c87cf4af8b5 152 if ( fp == NULL) {
clemente 0:4c87cf4af8b5 153 printf("Error opening file\r\n");
clemente 0:4c87cf4af8b5 154 DBG_LED=1;
clemente 0:4c87cf4af8b5 155 while(1);
clemente 0:4c87cf4af8b5 156 }
clemente 0:4c87cf4af8b5 157 /* we allocate memory to get the calibration data to save. */
clemente 0:4c87cf4af8b5 158 unsigned char *pmatrix;
clemente 0:4c87cf4af8b5 159 pmatrix=(unsigned char*)malloc( ts.gettsmatrixsize());
clemente 0:4c87cf4af8b5 160 if( pmatrix==NULL) {
clemente 0:4c87cf4af8b5 161 printf("Error allocating memory\r\n");
clemente 0:4c87cf4af8b5 162 DBG_LED=1;
clemente 0:4c87cf4af8b5 163 while(1);
clemente 0:4c87cf4af8b5 164 }
clemente 0:4c87cf4af8b5 165 /* get the calibration data. */
clemente 0:4c87cf4af8b5 166 ts.gettsmatrix( pmatrix);
clemente 0:4c87cf4af8b5 167 /* save the data to the file. */
clemente 0:4c87cf4af8b5 168 int mtxsize=fwrite( pmatrix, 1, ts.gettsmatrixsize(), fp);
clemente 0:4c87cf4af8b5 169 fflush( fp);
clemente 0:4c87cf4af8b5 170 fclose( fp);
clemente 0:4c87cf4af8b5 171 printf("matrix_size: %d\r\n", mtxsize);
clemente 0:4c87cf4af8b5 172 /* */
clemente 0:4c87cf4af8b5 173 if ( mtxsize != ts.gettsmatrixsize()) {
clemente 0:4c87cf4af8b5 174 printf("Error writing calibration data \r\n");
clemente 0:4c87cf4af8b5 175 docalibration=1;
clemente 0:4c87cf4af8b5 176 free( pmatrix);
clemente 0:4c87cf4af8b5 177 } else {
clemente 0:4c87cf4af8b5 178 printf("ts_mtx.bin saved\r\n");
clemente 0:4c87cf4af8b5 179 /* exit from the calibration loop.*/
clemente 0:4c87cf4af8b5 180 docalibration=0;
clemente 0:4c87cf4af8b5 181 free( pmatrix);
clemente 0:4c87cf4af8b5 182 }
clemente 0:4c87cf4af8b5 183 } else {
clemente 0:4c87cf4af8b5 184 lcd.lcd_drawstr( "TouchScreen Calibration... ERROR!", 0, 0, lcd.lcd_RGB( 0, 255, 0));
clemente 0:4c87cf4af8b5 185 wait( 3);
clemente 0:4c87cf4af8b5 186 lcd.lcd_clear( LCD_BLACK);
clemente 0:4c87cf4af8b5 187 docalibration=1;
clemente 0:4c87cf4af8b5 188 }
clemente 0:4c87cf4af8b5 189 }
clemente 0:4c87cf4af8b5 190
clemente 0:4c87cf4af8b5 191 char fnm[20];
clemente 0:4c87cf4af8b5 192 int x_img=160, y_img=120;
clemente 0:4c87cf4af8b5 193 unsigned char idx_pos=0;
clemente 0:4c87cf4af8b5 194 char fname[4][64];
clemente 0:4c87cf4af8b5 195 unsigned int idxf=20;
clemente 0:4c87cf4af8b5 196 //
clemente 0:4c87cf4af8b5 197 unsigned int changeImage=1;
clemente 0:4c87cf4af8b5 198 unsigned int linepos=0;
clemente 0:4c87cf4af8b5 199 unsigned int filepos=0;
clemente 0:4c87cf4af8b5 200 unsigned int size;
clemente 0:4c87cf4af8b5 201 unsigned int redraw_quad;
clemente 0:4c87cf4af8b5 202
clemente 0:4c87cf4af8b5 203 while( 1) {
clemente 0:4c87cf4af8b5 204 // loop
clemente 0:4c87cf4af8b5 205 idx_pos=0;
clemente 0:4c87cf4af8b5 206 while( 1) {
clemente 0:4c87cf4af8b5 207 // open the image files stored as NNNN.rgb
clemente 0:4c87cf4af8b5 208 sprintf( fnm, "/sd/images/%04d.rgb\0", idxf);
clemente 0:4c87cf4af8b5 209 while( (fpf=fopen( (char *)fnm, "r")) == NULL) {
clemente 0:4c87cf4af8b5 210 DBG_LED=1;
clemente 0:4c87cf4af8b5 211 printf( "Errore su file: %s\r\n", (char *)fnm);
clemente 0:4c87cf4af8b5 212 if ( fpf)
clemente 0:4c87cf4af8b5 213 fclose( fpf);
clemente 0:4c87cf4af8b5 214 //
clemente 0:4c87cf4af8b5 215 idxf++;
clemente 0:4c87cf4af8b5 216 if ( idxf > 1700) // a huge images repository!
clemente 0:4c87cf4af8b5 217 idxf=0;
clemente 0:4c87cf4af8b5 218 //
clemente 0:4c87cf4af8b5 219 sprintf( fnm, "/sd/images/%04d.rgb\0", idxf);
clemente 0:4c87cf4af8b5 220 }
clemente 0:4c87cf4af8b5 221 //
clemente 0:4c87cf4af8b5 222 strcpy( &fname[idx_pos][0], fnm);
clemente 0:4c87cf4af8b5 223 idxf++;
clemente 0:4c87cf4af8b5 224 printf("Image: %s, idx_pos: %d, fname: %s\r\n", fnm, idx_pos, &fname[idx_pos][0]);
clemente 0:4c87cf4af8b5 225 //
clemente 0:4c87cf4af8b5 226 linepos=0;
clemente 0:4c87cf4af8b5 227 while( feof( fpf)==0) {
clemente 0:4c87cf4af8b5 228 // calculate the position inside the file to read the image...
clemente 0:4c87cf4af8b5 229 filepos=( sizeof(imageLinebuffer)/sizeof(imageLinebuffer[0]) ) * linepos * SCALE_160x120;
clemente 0:4c87cf4af8b5 230 fseek( fpf, filepos, SEEK_SET );
clemente 0:4c87cf4af8b5 231 // read the entire line...
clemente 0:4c87cf4af8b5 232 size=fread( &imageLinebuffer[0], sizeof(imageLinebuffer[0]), sizeof(imageLinebuffer)/sizeof(imageLinebuffer[0]), fpf);
clemente 0:4c87cf4af8b5 233 // and draw it...
clemente 0:4c87cf4af8b5 234 lcd.lcd_drawimagebyline( &imageLinebuffer[0], linepos, x_img*(idx_pos&0x1), y_img*((idx_pos>>1)&0x1), SCALE_160x120);
clemente 0:4c87cf4af8b5 235 linepos++;
clemente 0:4c87cf4af8b5 236 }
clemente 0:4c87cf4af8b5 237 // close the file...
clemente 0:4c87cf4af8b5 238 fclose( fpf);
clemente 0:4c87cf4af8b5 239 printf("x_img= %d, y_img= %d\r\n", x_img*(idx_pos&0x1), y_img*((idx_pos>>1)&0x1));
clemente 0:4c87cf4af8b5 240 // change the image position inside the quad
clemente 0:4c87cf4af8b5 241 idx_pos++;
clemente 0:4c87cf4af8b5 242 idx_pos%=4;
clemente 0:4c87cf4af8b5 243 // check if the screen is full with 4 images...
clemente 0:4c87cf4af8b5 244 if ( idx_pos==0)
clemente 0:4c87cf4af8b5 245 break;
clemente 0:4c87cf4af8b5 246 }
clemente 0:4c87cf4af8b5 247 //
clemente 0:4c87cf4af8b5 248 // at this point there are 4 images draw on the screen.
clemente 0:4c87cf4af8b5 249 // just wait the user to press the TS.
clemente 0:4c87cf4af8b5 250 //
clemente 0:4c87cf4af8b5 251 idx_pos=0;
clemente 0:4c87cf4af8b5 252 redraw_quad=0;
clemente 0:4c87cf4af8b5 253 while( redraw_quad==0) {
clemente 0:4c87cf4af8b5 254 // just loop waiting for a tap...
clemente 0:4c87cf4af8b5 255 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 256 ts.do_tap();
clemente 0:4c87cf4af8b5 257 }
clemente 0:4c87cf4af8b5 258 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 259 // first check if the user tap on the bottom left
clemente 0:4c87cf4af8b5 260 if ( CheckRectangle( 0, 180, 80, 60, ts.ts_val.coord.x, ts.ts_val.coord.y) ) {
clemente 0:4c87cf4af8b5 261 // tap on left. Change the image index to go back.
clemente 0:4c87cf4af8b5 262 idxf-=8;
clemente 0:4c87cf4af8b5 263 break;
clemente 0:4c87cf4af8b5 264 }
clemente 0:4c87cf4af8b5 265 // ...or bottom right.
clemente 0:4c87cf4af8b5 266 if ( CheckRectangle( 240, 180, 80, 60, ts.ts_val.coord.x, ts.ts_val.coord.y) ) {
clemente 0:4c87cf4af8b5 267 // tap on right. Nothing to change, the index image is pointing the next four images.
clemente 0:4c87cf4af8b5 268 break;
clemente 0:4c87cf4af8b5 269 }
clemente 0:4c87cf4af8b5 270 // ...or upper right.
clemente 0:4c87cf4af8b5 271 if ( CheckRectangle( 240, 0, 80, 60, ts.ts_val.coord.x, ts.ts_val.coord.y) ) {
clemente 0:4c87cf4af8b5 272 // tap on upper right. Lets movies...
clemente 0:4c87cf4af8b5 273
clemente 0:4c87cf4af8b5 274 // more big movie (160x120 pixel)
clemente 0:4c87cf4af8b5 275 lcd.lcd_clear( LCD_WHITE);
clemente 0:4c87cf4af8b5 276 if ( lcd.lcd_drawmoviebuff( "/sd/movies2/unicolcd.bin", 160-80, 120-60) == 0) {
clemente 0:4c87cf4af8b5 277 printf("Errore apertura file\r\n");
clemente 0:4c87cf4af8b5 278 DBG_LED=1;
clemente 0:4c87cf4af8b5 279 }
clemente 0:4c87cf4af8b5 280
clemente 0:4c87cf4af8b5 281 wait( 1);
clemente 0:4c87cf4af8b5 282 // small movie (80x60 pixel) at 15fs.
clemente 0:4c87cf4af8b5 283 if ( lcd.lcd_drawmovie( "/sd/movies1/unico.bin", 160-40, 120-30) == 0) {
clemente 0:4c87cf4af8b5 284 printf("Errore apertura file\r\n");
clemente 0:4c87cf4af8b5 285 DBG_LED=1;
clemente 0:4c87cf4af8b5 286 }
clemente 0:4c87cf4af8b5 287
clemente 0:4c87cf4af8b5 288 #if 0
clemente 0:4c87cf4af8b5 289 //
clemente 0:4c87cf4af8b5 290 // But now I can't continue! Please reset! :-)
clemente 0:4c87cf4af8b5 291 // There is a bug in my code that, after the play of the big movie
clemente 0:4c87cf4af8b5 292 // the screen area remain like the area of the movie. The LCD does not receive more area command.
clemente 0:4c87cf4af8b5 293 // Sometimes it works sometimes not...
clemente 0:4c87cf4af8b5 294 //
clemente 0:4c87cf4af8b5 295 while( 1);
clemente 0:4c87cf4af8b5 296 #endif
clemente 0:4c87cf4af8b5 297 }
clemente 0:4c87cf4af8b5 298 // ...or upper left.
clemente 0:4c87cf4af8b5 299 if ( CheckRectangle( 0, 0, 80, 60, ts.ts_val.coord.x, ts.ts_val.coord.y) ) {
clemente 0:4c87cf4af8b5 300 // tap on upper left. Display the TS test...
clemente 0:4c87cf4af8b5 301 test_touch();
clemente 0:4c87cf4af8b5 302 idxf-=4;
clemente 0:4c87cf4af8b5 303 break;
clemente 0:4c87cf4af8b5 304 }
clemente 0:4c87cf4af8b5 305 // at this point we check which image is tapped
clemente 0:4c87cf4af8b5 306 idx_pos=0;
clemente 0:4c87cf4af8b5 307 while( idx_pos < 4) {
clemente 0:4c87cf4af8b5 308 // we use the same index methodology to calculate the coordinate of the area tapped...
clemente 0:4c87cf4af8b5 309 if ( CheckRectangle( x_img*(idx_pos&0x1), y_img*((idx_pos>>1)&0x1), 160, 120, ts.ts_val.coord.x, ts.ts_val.coord.y) ) {
clemente 0:4c87cf4af8b5 310 // an image is selected so draw it at full screen
clemente 0:4c87cf4af8b5 311 lcd.lcd_drawimagebuff( &fname[idx_pos][0]);
clemente 0:4c87cf4af8b5 312 // wait for a tap to exit.
clemente 0:4c87cf4af8b5 313 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 314 ts.do_tap();
clemente 0:4c87cf4af8b5 315 }
clemente 0:4c87cf4af8b5 316 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 317 // let stop the waiting loop to redraw the quad screen.
clemente 0:4c87cf4af8b5 318 redraw_quad=1;
clemente 0:4c87cf4af8b5 319 // change the image index to redraw the same images.
clemente 0:4c87cf4af8b5 320 idxf-=4;
clemente 0:4c87cf4af8b5 321 // exit the loop
clemente 0:4c87cf4af8b5 322 break;
clemente 0:4c87cf4af8b5 323 }
clemente 0:4c87cf4af8b5 324 //
clemente 0:4c87cf4af8b5 325 idx_pos++;
clemente 0:4c87cf4af8b5 326 }
clemente 0:4c87cf4af8b5 327 idx_pos=0;
clemente 0:4c87cf4af8b5 328 }
clemente 0:4c87cf4af8b5 329 }
clemente 0:4c87cf4af8b5 330
clemente 0:4c87cf4af8b5 331 }
clemente 0:4c87cf4af8b5 332
clemente 0:4c87cf4af8b5 333 void test_touch( void)
clemente 0:4c87cf4af8b5 334 {
clemente 0:4c87cf4af8b5 335
clemente 0:4c87cf4af8b5 336 // test the TS capability...
clemente 0:4c87cf4af8b5 337 // Please connect a serial cable to see the result...
clemente 0:4c87cf4af8b5 338 //
clemente 0:4c87cf4af8b5 339 lcd.lcd_clear( LCD_WHITE);
clemente 0:4c87cf4af8b5 340 lcd.lcd_setbackgroundcolor( LCD_WHITE);
clemente 0:4c87cf4af8b5 341 // four icons on the left.
clemente 0:4c87cf4af8b5 342 lcd.lcd_drawicon( (unsigned char*)&info[0], 0, 24, 48); // icona 1
clemente 0:4c87cf4af8b5 343 lcd.lcd_drawicon( (unsigned char*)&info[0], 0, 24+48, 48); // icona 2
clemente 0:4c87cf4af8b5 344 lcd.lcd_drawicon( (unsigned char*)&info[0], 0, 24+48+48, 48); // icona 3
clemente 0:4c87cf4af8b5 345 lcd.lcd_drawicon( (unsigned char*)&info[0], 0, 24+48+48+48, 48); // icona 4
clemente 0:4c87cf4af8b5 346 // two icons at the bottom.
clemente 0:4c87cf4af8b5 347 lcd.lcd_drawicon( (unsigned char*)&info[0], 136, 192, 48); // icona 5
clemente 0:4c87cf4af8b5 348 lcd.lcd_drawicon( (unsigned char*)&info[0], 136+48, 192, 48); // icona 6
clemente 0:4c87cf4af8b5 349 //
clemente 0:4c87cf4af8b5 350 lcd.lcd_drawstr("Tap here to exit", 220, 20, LCD_BLACK);
clemente 0:4c87cf4af8b5 351 // loop forever...
clemente 0:4c87cf4af8b5 352 while( 1)
clemente 0:4c87cf4af8b5 353 {
clemente 0:4c87cf4af8b5 354 //
clemente 0:4c87cf4af8b5 355 printf("Starting the loop...\n\r");
clemente 0:4c87cf4af8b5 356 while( !ts.ts_val.touched) {
clemente 0:4c87cf4af8b5 357 ts.do_tap();
clemente 0:4c87cf4af8b5 358 }
clemente 0:4c87cf4af8b5 359 ts.ts_val.touched=0;
clemente 0:4c87cf4af8b5 360 //
clemente 0:4c87cf4af8b5 361 lcd.lcd_drawstr("Out!!! ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 362 //
clemente 0:4c87cf4af8b5 363 if ( CheckRectangle( 0, 24, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 364 lcd.lcd_drawstr("Icona 1 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 365 if ( CheckRectangle( 0, 24+48, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 366 lcd.lcd_drawstr("Icona 2 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 367 if ( CheckRectangle( 0, 24+48+48, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 368 lcd.lcd_drawstr("Icona 3 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 369 if ( CheckRectangle( 0, 24+48+48+48, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 370 lcd.lcd_drawstr("Icona 4 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 371 if ( CheckRectangle( 136, 192, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 372 lcd.lcd_drawstr("Icona 5 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 373 if ( CheckRectangle( 136+48, 192, 48, 48, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 374 lcd.lcd_drawstr("Icona 6 ", 240, 10, LCD_BLACK);
clemente 0:4c87cf4af8b5 375
clemente 0:4c87cf4af8b5 376 // ...or upper right to exit.
clemente 0:4c87cf4af8b5 377 if ( CheckRectangle( 240, 0, 80, 60, ts.ts_val.coord.x, ts.ts_val.coord.y) )
clemente 0:4c87cf4af8b5 378 break;
clemente 0:4c87cf4af8b5 379
clemente 0:4c87cf4af8b5 380 printf("X:%5d\tY:%5d\tZ:%d\r\n", ts.ts_val.coord.x, ts.ts_val.coord.y, ts.ts_val.coord.z);
clemente 0:4c87cf4af8b5 381 wait_ms( 250);
clemente 0:4c87cf4af8b5 382 }
clemente 0:4c87cf4af8b5 383
clemente 0:4c87cf4af8b5 384 }
clemente 0:4c87cf4af8b5 385
clemente 0:4c87cf4af8b5 386 /*************************************************************************
clemente 0:4c87cf4af8b5 387 * Function Name: CheckRectangle
clemente 0:4c87cf4af8b5 388 * Parameters: Int32U X_up, Int32U Y_up - rectangle coordinate
clemente 0:4c87cf4af8b5 389 * Int32U X_size, Int32U Y_size - rectangle size
clemente 0:4c87cf4af8b5 390 * Int32U X_poin, Int32U Y_point - point coordinate
clemente 0:4c87cf4af8b5 391 *
clemente 0:4c87cf4af8b5 392 * Return: Boolean
clemente 0:4c87cf4af8b5 393 * TRUE - the point is inside from the rectangle
clemente 0:4c87cf4af8b5 394 * FALSE - the point is outside from the rectangle
clemente 0:4c87cf4af8b5 395 *
clemente 0:4c87cf4af8b5 396 * Description: Check whether the coordinate of point is inside from a rectangle
clemente 0:4c87cf4af8b5 397 *
clemente 0:4c87cf4af8b5 398 *************************************************************************/
clemente 0:4c87cf4af8b5 399 unsigned char CheckRectangle (unsigned int X_up, unsigned int Y_up, unsigned int X_size, unsigned int Y_size, unsigned int X_point, unsigned int Y_point )
clemente 0:4c87cf4af8b5 400 {
clemente 0:4c87cf4af8b5 401 if((X_up <= X_point) && (X_point <= X_up+X_size) &&
clemente 0:4c87cf4af8b5 402 (Y_up <= Y_point) && (Y_point <= Y_up+Y_size))
clemente 0:4c87cf4af8b5 403 {
clemente 0:4c87cf4af8b5 404 return ( 1);
clemente 0:4c87cf4af8b5 405 }
clemente 0:4c87cf4af8b5 406 return ( 0);
clemente 0:4c87cf4af8b5 407 }