Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Revision:
23:cd03f9c3395e
Parent:
22:a43df3905863
Child:
25:ddf0ec209f03
--- a/utility.cpp	Mon Mar 11 06:23:00 2013 +0000
+++ b/utility.cpp	Thu Mar 14 04:41:11 2013 +0000
@@ -73,7 +73,7 @@
         msgChanged[indexLastMsg[canRXmsg.id]]=changed;
     }
     lastMsg[indexLastMsg[canRXmsg.id]]=canRXmsg; //Store in table
-    if(mType==1&&canRXmsg.id==0x7bb){ // is battery data?  Need to store all responses
+    if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data?  Need to store all responses
         if(canRXmsg.data[0]<0x20){
             if(canRXmsg.data[3]==2){//cellpair data
                 bdi=0;
@@ -130,7 +130,7 @@
     data[0]=0x30; //change to request next line message
     data[1]=0x01;
     data[2]=0x00;
-    for(i=0;i<27;i++){
+    for(i=0;i<29;i++){
         wait_ms(16); //wait 16ms
         can1.write(CANMessage(0x79b, data, 8));
     }
@@ -147,7 +147,7 @@
     data[0]=0x30; //change to request next line message
     data[1]=0x01;
     data[2]=0x00;
-    for(i=0;i<2;i++){
+    for(i=0;i<3;i++){
         wait_ms(16); //wait 16ms
         can1.write(CANMessage(0x79b, data, 8));
     }
@@ -184,3 +184,50 @@
     unsigned short val = Y*rows/240;
     return val;
 }
+
+void saveConfig(){
+    FILE *cfile;
+    cfile = fopen("/local/config.txt", "w");
+    fprintf(cfile,"format 1\r\n");
+    fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
+    fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
+    fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
+    fprintf(cfile,"y0_pp %d\r\n",tt.y0_pp);
+    fprintf(cfile,"x1_off %d\r\n",tt.x1_off);
+    fprintf(cfile,"y1_off %d\r\n",tt.y1_off);
+    fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp);
+    fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp);
+    fprintf(cfile,"x_mid %d\r\n",tt.x_mid);
+    fclose(cfile);
+}
+
+ void readConfig(){
+    FILE *cfile;
+    int ff;
+    char sTemp[40];
+    cfile = fopen("/local/config.txt", "r");
+    if (cfile==NULL){ // if doesn't exist --> create
+        sprintf(sTemp,"No config file found.\n");
+        logMsg(sTemp);
+        sprintf(sTemp,"Calibrating touch screen.\n");
+        logMsg(sTemp);
+        //tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);// bypass calibration using my values
+        tt.calibrate();   // run touchscreen calibration routine
+        saveConfig();
+    } else {
+        sprintf(sTemp,"Reading config file.\n");
+        logMsg(sTemp);
+        //tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);// bypass calibration using my values
+        fscanf(cfile, "format %c\r\n", &ff ) ;
+        fscanf(cfile, "x0_off %d\r\n", &tt.x0_off ) ;
+        fscanf(cfile, "y0_off %d\r\n", &tt.y0_off ) ;
+        fscanf(cfile, "x0_pp %d\r\n", &tt.x0_pp ) ;
+        fscanf(cfile, "y0_pp %d\r\n", &tt.y0_pp ) ;
+        fscanf(cfile, "x1_off %d\r\n", &tt.x1_off ) ;
+        fscanf(cfile, "y1_off %d\r\n", &tt.y1_off ) ;
+        fscanf(cfile, "x1_pp %d\r\n", &tt.x1_pp ) ;
+        fscanf(cfile, "y1_pp %d\r\n", &tt.y1_pp ) ;
+        fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ;
+        fclose(cfile);
+    }
+}