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:
97:a25940fd7b5b
Parent:
95:248b3c25a7df
Child:
99:c05abf8e1cdc
--- a/utility.cpp	Fri May 03 14:31:07 2013 +0000
+++ b/utility.cpp	Sat Jun 15 12:23:36 2013 +0000
@@ -148,7 +148,7 @@
         }
     }else{ // not debugMode - keep code short
         if(logOpen){
-            NVIC_DisableIRQ(CAN_IRQn);  // Block interrupts until write pointer assigned
+            NVIC_DisableIRQ(CAN_IRQn); // Block interrupts until write pointer assigned
             int localWritePointer = writePointer++; // create local copy to make logCan reentrant
             // note that the static variables do not prevent safe reentry
             // since they are only used for msgId<0x800 which will never interrupt
@@ -157,7 +157,7 @@
                 writePointer = 0;
                 led3 = !led3;
             }
-            NVIC_EnableIRQ(CAN_IRQn);  // Unblock interrupts once local pointer set and global pointer incremented
+            NVIC_EnableIRQ(CAN_IRQn); // Unblock interrupts once local pointer set and global pointer incremented
             ts=getTimeStamp();
             writeBuffer[localWritePointer][0]=mType;
             writeBuffer[localWritePointer][1]=(ts&0xff00)>>8;
@@ -213,28 +213,38 @@
             if(canRXmsg.data[0]<0x20){
                 if(canRXmsg.data[3]==2){//Group 2 = cellpair data
                     bdi=BatDataBaseG2; // index offset for CP data (uses 00 - 1C)
-                    sprintf(sTemp,"  Getting cell pair data\n");
-                    printMsg(sTemp);
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting cell pair data\n");
+                        printMsg(sTemp);
+                    }
                     
                 }else if(canRXmsg.data[3]==4){//Group 4 = temperature data
                     bdi=BatDataBaseG4; // index offset for Temperature data (uses 20 - 22)
-                    sprintf(sTemp,"  Getting temperature data\n");
-                    printMsg(sTemp);
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting temperature data\n");
+                        printMsg(sTemp);
+                    }
                     
                 }else if(canRXmsg.data[3]==1){//Group 1 data
                     bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22)
-                    sprintf(sTemp,"  Getting Group 1 data\n");
-                    printMsg(sTemp);
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting Group 1 data\n");
+                        printMsg(sTemp);
+                    }
                     
                 }else if(canRXmsg.data[3]==3){//Group 3 data
                     bdi=BatDataBaseG3; // index offset for Group 3 data (uses 20 - 22)
-                    sprintf(sTemp,"  Getting Group 3 data\n");
-                    printMsg(sTemp);
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting Group 3 data\n");
+                        printMsg(sTemp);
+                    }
                     
                 }else if(canRXmsg.data[3]==5){//Group 5 data
                     bdi=BatDataBaseG5; // index offset for Group 5 data (uses 20 - 22)
-                    sprintf(sTemp,"  Getting Group 5 data\n");
-                    printMsg(sTemp);
+                    if(debugMode){
+                        sprintf(sTemp,"  Getting Group 5 data\n");
+                        printMsg(sTemp);
+                    }
                     
                 }else bdi=0xff; // ignore other messages (for now)
                 lasti=0;
@@ -275,10 +285,10 @@
             packA -= 1; //Slight correction to value required (unique to my Leaf?)
             imWs_x4 = packV; // Volts*milliSeconds*2
             imWs_x4 *= -packA; // milliWattseconds*4
-            if (!((imotorRPM<2)&&(imWs_x4<0))){ //Ignore if charging from wall
+            //if (!((imotorRPM<2)&&(imWs_x4<0))){ //Ignore if charging from wall
                 mWs_x4 += imWs_x4; // total mWs_x4
                 numWsamples++;
-            }
+            //}
         }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed
             imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5]));
             if(imotorRPM<0){ // take absolute value
@@ -372,9 +382,9 @@
 }
 
 void autoPollISR(){
-    char sTemp[40]; // just for debug
-    sprintf(sTemp,"Requesting cp data\n"); // just for debug
-    printMsg(sTemp); // just for debug
+    //char sTemp[40]; // just for debug
+    //sprintf(sTemp,"Requesting cp data\n"); // just for debug
+    //printMsg(sTemp); // just for debug
     reqMsgCnt = 0; //reset message counter
     msgReq.attach(&sendReq,0.015);
 }
@@ -419,7 +429,6 @@
 void saveConfig(){
     FILE *cfile;
     cfile = fopen("/local/config.txt", "w");
-    //fprintf(cfile,"format 3\r\n");
     fprintf(cfile,"format 4\r\n");
     fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
     fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
@@ -621,3 +630,4 @@
     showCP=true;
 }
 
+