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:
89:2263d349b484
Parent:
88:45185a5f1c9b
Child:
91:33ab084a184f
--- a/utility.cpp	Sat Apr 20 17:08:40 2013 +0000
+++ b/utility.cpp	Sat Apr 20 19:30:10 2013 +0000
@@ -91,7 +91,7 @@
                         writeBuffer[tempWritePointer][3]=0xfe; // MsgID, low byte
                         writeBuffer[tempWritePointer][4]=0xff; // Len nibble, and MsgID high nibble
                         // lay in the "Lost0002" text
-                        for(i=5;i<13;i++){ 
+                        for(i=5;i<13;++i){ 
                             writeBuffer[tempWritePointer][i]= strLost[i-5];
                         }
                     } else {
@@ -101,7 +101,7 @@
                         
                         // lay the new count into the comment
                         sprintf(strLost,"%04d",nLost);
-                        for(i=9;i<13;i++){ 
+                        for(i=9;i<13;++i){ 
                             writeBuffer[tempWritePointer][i]= strLost[i-9];
                         }
                     }
@@ -115,7 +115,7 @@
                     writeBuffer[writePointer][3]=canRXmsg.id&0xff; // MsgID, low byte
                     char sLen = canRXmsg.len ;
                     writeBuffer[writePointer][4]=(canRXmsg.id>>8)+(sLen<<4); // Len nibble, and MsgID high nibble
-                    for(i=0;i<8;i++){ // Is there a better way to do this? (writeBuffer[writePointer][i]=canRXmsg.data?)
+                    for(i=0;i<8;++i){ // Is there a better way to do this? (writeBuffer[writePointer][i]=canRXmsg.data?)
                         if(i<sLen) 
                             writeBuffer[writePointer][i+5]=canRXmsg.data[i];
                         else // i>=sLen
@@ -165,7 +165,7 @@
             writeBuffer[localWritePointer][2]=(ts&0x00ff);
             writeBuffer[localWritePointer][3]=canRXmsg.id&0xff;
             writeBuffer[localWritePointer][4]=(canRXmsg.id>>8)+(canRXmsg.len<<4);
-            for(i=5;i<13;i++){ // Is there a better way to do this? (writeBuffer[localWritePointer][i]=canRXmsg.data?)
+            for(i=5;i<13;++i){ // Is there a better way to do this? (writeBuffer[localWritePointer][i]=canRXmsg.data?)
                 writeBuffer[localWritePointer][i]=canRXmsg.data[i-5];
             }
             if (writePointer==readPointer) {
@@ -186,7 +186,7 @@
             } else {
                 // the ii array is full, more than 100 MsgIDs found
                 if(ii==99) {
-                    ii++; // step to 100 to log only one error
+                    ++ii; // step to 100 to log only one error
                     sprintf(sTemp,"MsgID buffer overrun.\n");
                     printMsg(sTemp); // write buffer overrun
                 }
@@ -197,7 +197,7 @@
         if(dMode[0]==changedScreen||dMode[1]==changedScreen){// Skip if not using (for execution speed)
             changed=msgChanged[indexLastMsg[canRXmsg.id]];
             // This is cleared in the main loop when reset button is touched
-            for(i=0;i<8;i++){
+            for(i=0;i<8;++i){
                 if(lastMsg[indexLastMsg[canRXmsg.id]].data[i]!=canRXmsg.data[i]){
                     changed |= 1<<i;
                 }
@@ -209,10 +209,7 @@
         
         //-------------------
         //Miscellaneous on-recieve operations below
-        if((mType==2)&&(canRXmsg.id==0x358)){ // headlight/turn signal indicator
-            headlights = (canRXmsg.data[1]&0x80)?true:false;
-            
-        }else 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){//Group 2 = cellpair data
                     bdi=BatDataBaseG2; // index offset for CP data (uses 00 - 1C)
@@ -279,7 +276,7 @@
             imWs_x4 *= -packA; // milliWattseconds*4
             if (!((imotorRPM<2)&&(imWs_x4<0))){ //Ignore if charging from wall
                 mWs_x4 += imWs_x4; // total mWs_x4
-                numWsamples++;
+                ++numWsamples;
             }
         }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed
             imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5]));
@@ -287,7 +284,7 @@
                 imotorRPM=-imotorRPM;
             }
             motorRPM+=imotorRPM;
-            numSsamples++;
+            ++numSsamples;
         }
     }
 }
@@ -318,7 +315,7 @@
     tsMsg.len=0xf;
     int iMsgLen = strlen(eventMsg);
     // 8 character message compatible with CAN-Do
-    for(int i=0; i<8; i++){
+    for(int i=0; i<8; ++i){
       tsMsg.data[i]=' '; 
       if( i < iMsgLen ) tsMsg.data[i]=eventMsg[i];
     }
@@ -328,37 +325,37 @@
 void sendReq() {
     static char data[8] = {0x02, 0x21, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff};
     if(reqMsgCnt<99){
-        switch (reqMsgCnt){
-            case 0:
+        switch (++reqMsgCnt){
+            case 1:
                 can1.monitor(false); // set to active mode
                 can1SleepMode = 0; // enable TX
                 data[0]=0x02; //change to request group 1
                 data[1]=0x21;
                 data[2]=0x01;
                 break;
-            case 6: // group 1 has 6 frames
+            case 7: // group 1 has 6 frames
                 can1.monitor(false); // set to active mode
                 can1SleepMode = 0; // enable TX
                 data[0]=0x02; //change to request group 2 (cp data)
                 data[1]=0x21;
                 data[2]=0x02;
                 break;
-            case 35: // group 2 has 29 frames
+            case 36: // group 2 has 29 frames
                 data[0]=0x02; //change to request group 3
                 data[1]=0x21;
                 data[2]=0x03;
                 break;
-            case 40: // group 3 has 5 frames
+            case 41: // group 3 has 5 frames
                 data[0]=0x02; //change to request group 4 (temperature)
                 data[1]=0x21;
                 data[2]=0x04;
                 break;
-            case 43: // group 4 has 3 frames
+            case 44: // group 4 has 3 frames
                 data[0]=0x02; //change to request group 5
                 data[1]=0x21;
                 data[2]=0x05;
                 break;
-            case 54: // group 5 has 11 frames
+            case 55: // group 5 has 11 frames
                 reqMsgCnt = 99;
                 can1SleepMode = 1; // disable TX
                 can1.monitor(true); // set to snoop mode
@@ -369,7 +366,6 @@
                 data[2]=0x00;
         }
         can1.write(CANMessage(0x79b, data, 8));
-        reqMsgCnt++;
     }
 }
 
@@ -587,7 +583,7 @@
     max=0;
     min=9999;
     avg=0;
-    for(i=0; i<96; i++) {
+    for(i=0; i<96; ++i) {
         bd=(battData[i*2+3]<<8)+battData[i*2+4];
         avg+=bd;
         if(bd>max) max=bd;
@@ -609,7 +605,7 @@
         // BatDataBaseG4 * 7 = 224        
         fprintf(bfile,"%d,%d,%d,%d,",(battData[224+ 3]<<8)+battData[224+ 4],battData[224+ 5],(battData[224+ 6]<<8)+battData[224+ 7],battData[224+ 8]);
         fprintf(bfile,"%d,%d,%d,%d", (battData[224+ 9]<<8)+battData[224+10],battData[224+11],(battData[224+12]<<8)+battData[224+13],battData[224+14]);
-        for(i=0; i<96; i++) {
+        for(i=0; i<96; ++i) {
             bd=(battData[i*2+3]<<8)+battData[i*2+4];
             fprintf(bfile,",%d",bd);
         }