seed

Dependencies:   SPI_TFT_ILI9341

Fork of SeeedStudioTFTv2 by Components

Revision:
14:304b55ac904b
Parent:
10:b55a7f8d1145
Child:
15:23288c15e11d
--- a/SeeedStudioTFTv2.cpp	Tue May 06 18:12:49 2014 +0000
+++ b/SeeedStudioTFTv2.cpp	Mon Apr 18 06:59:46 2016 +0000
@@ -12,44 +12,26 @@
  * THE SOFTWARE.
  */
 
-
+ 
 #include "mbed.h"
 #include "SeeedStudioTFTv2.h"
 
 SeeedStudioTFTv2::SeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
                                    PinName mosi, PinName miso, PinName sclk,
-                                   PinName csTft, PinName dcTft, PinName blTft,
-                                   PinName csSd):
-#ifdef USE_SDCARD
-    SDFileSystem(mosi,miso,sclk,csSd, "sdc"),
-#endif
-    SPI_TFT_ILI9341(mosi,miso,sclk,csTft,NC,dcTft, "tft"),
-    bl(blTft)
+                                   PinName csTft, PinName rstTft, PinName dcTft):
+    SPI_TFT_ILI9341(mosi,miso,sclk,csTft,rstTft,dcTft, "tft")
 {
-#ifndef USE_SDCARD
-    // sd card
-    DigitalOut cs(csSd);
-    cs = 1;
-#endif
-    // backlight
-    bl = 1;
-    font = NULL;
     // touch screen pins
     _xp = xp;
     _yp = yp;
     _xm = xm;
     _ym = ym;
     // default touch calibration
-    // orientation     //      0      1      2      3
-    x_off = 108000;  //  17252  16605 108755 108000
-    y_off =  22000;  //  22330 105819  97167  22000
-    pp_tx =   -291;  //    378    289   -390   -291
-    pp_ty =    356;  //    261   -355   -239    356
-}
-
-void SeeedStudioTFTv2::setBacklight(bool enabled)
-{
-    bl = enabled;
+    // orientation  //      0      1      2      3
+    x_off =  16605 ;  //  17252  16605 108755 108000
+    y_off =  105819 ;  //  22330 105819  97167  22000
+    pp_tx =   289;  //    378    289   -390   -291
+    pp_ty =    -355;  //    261   -355   -239    356
 }
 
 int SeeedStudioTFTv2::readTouch(PinName p, PinName m, PinName a, PinName i)
@@ -102,6 +84,7 @@
     } else {
         touch = YES;
     }
+    //debug
     //locate(0,50);
     //printf("x: %6i y: %6i",p.x,p.y);
     return touch;
@@ -183,6 +166,8 @@
     while (getTouch(p) != NO)
         /*nothing*/;
     cls();
+    
+    Ecrire_Calibration(x_off, y_off, pp_tx, pp_ty);
 }
 
 point SeeedStudioTFTv2::toPixel(point p)
@@ -206,3 +191,36 @@
     p = toPixel(p);
     return touch == YES;
 }
+
+void SeeedStudioTFTv2::Ecrire_Calibration(unsigned short x_off, unsigned short y_off, unsigned short pp_tx, unsigned short pp_ty)
+{
+    FILE* fichier = fopen("/local/calib.txt", "w");
+    
+    fprintf(fichier,"%d %d %d %d", x_off, y_off, pp_tx, pp_ty);
+    
+    fclose(fichier);    
+}
+
+void SeeedStudioTFTv2::Lire_Calibration(void)
+{
+    FILE* fichier = fopen("/local/calib.txt", "r");
+
+    fscanf(fichier,"%d %d %d %d", &x_off, &y_off, &pp_tx, &pp_ty);
+    
+    fclose(fichier);
+     
+}
+void SeeedStudioTFTv2::CheckCalibTXT(void)
+{
+    FILE* fpi = fopen("/local/calib.txt", "r");
+
+    if (fpi == NULL) 
+    {
+        calibrate();          // calibrate the touch
+    } 
+    else
+    {
+        fclose(fpi);
+        Lire_Calibration();
+    }
+}
\ No newline at end of file