Dual CANbus monitor and instrumentation cluster

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Tue Apr 09 04:13:20 2013 +0000
Parent:
51:6187c5264a73
Child:
53:8a51361434ae
Child:
55:591406a71fa8
Commit message:
Improved DTE to eliminate discontinuity at 1 minute and reduce occasional flicker

Changed in this revision

displayModes.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/displayModes.cpp	Sun Apr 07 17:11:28 2013 +0000
+++ b/displayModes.cpp	Tue Apr 09 04:13:20 2013 +0000
@@ -741,8 +741,10 @@
 
     tt.background(Navy);
     tt.foreground(Yellow);
+    if(force){
+        tt.cls();
+    }
     if(force||lgids!=gids){
-        tt.cls();
         tt.set_font((unsigned char*) Arial12x12);
         for(i=0;i<10;i++){
             y=200-i*20;
@@ -756,27 +758,27 @@
         }
 
         x=50+0*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("sec\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+9*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("min\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+18*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("hour\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+25*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("day\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+32*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("mon\n");  
         tt.line(x,10,x,220,DarkGrey);     
         x=50+38*6;
-        tt.locate(x-6,226);
+        tt.locate(x-10,226);
         printf("year\n");  
         tt.line(x,10,x,220,DarkGrey);
         lgids=gids;    
@@ -805,10 +807,11 @@
         tt.line(x,180,x,220,DarkGrey);     
         tt.set_font((unsigned char*) SCProSB31x55);
         tt.foreground(Green);
-        tt.locate(180,10);
         if (showMiles){
-            printf("%4.1f\n",mpkWh[dtePeriod]*((float)(gids-5)*.075));
+            tt.locate(160,10);
+            printf("%4.1f \n",mpkWh[dtePeriod]*((float)(gids-5)*.075));
         } else {
+            tt.locate(180,10);
             printf("%3.1f\n",mpkWh[dtePeriod]);
         }
         lx=50;
@@ -819,7 +822,7 @@
             ly=0;
         }
         if(dtePeriod==0){
-            radius=4;
+            radius=6;
             color=Magenta;
         }else{
             radius=2;
@@ -846,7 +849,9 @@
             tt.fillcircle(x,leff[i],radius,Navy);
             tt.line(x-6,leff[i-1],x,leff[i],Navy);
             leff[i-1]=ly;
-            tt.fillcircle(x,y,radius,color);
+            if(y>0){
+                tt.fillcircle(x,y,radius,color);
+            }
             tt.line(lx,ly,x,y,White);
             lx=x;
             ly=y;
--- a/main.cpp	Sun Apr 07 17:11:28 2013 +0000
+++ b/main.cpp	Tue Apr 09 04:13:20 2013 +0000
@@ -101,12 +101,11 @@
 float kW[39]={0};
 float mpkWh[39]={0};
 // Logarithmic division scale (roughly - snapped to common units of time)
-// First 10 are updated each second; the rest are updated each minute
 float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute
-                     1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 hour
-                     60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*24, // 1 day
-                     60*24*1.58, 60*24*2.51, 60*24*3.98, 60*24*6.31, 60*24*10, 60*24*15.8, 60*24*30, // 1 month
-                     60*24*39.8, 60*24*63.1, 60*24*100, 60*24*158, 60*24*251, 60*24*365}; // 1 year
+                     60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*25.1, 60*39.8, 60*60, // 1 hour
+                     60*60*1.58, 60*60*2.51, 60*60*3.98, 60*60*6.31, 60*60*10, 60*60*15.8, 60*60*24, // 1 day
+                     60*60*24*1.58, 60*60*24*2.51, 60*60*24*3.98, 60*60*24*6.31, 60*60*24*10, 60*60*24*15.8, 60*60*24*30, // 1 month
+                     60*60*24*39.8, 60*60*24*63.1, 60*60*24*100, 60*60*24*158, 60*60*24*251, 60*60*24*365}; // 1 year
 bool updateDTE = false;
 
 int main() {
@@ -114,9 +113,8 @@
     char sTemp[40];
     unsigned long secs;
     unsigned char i,j,display=0,lwt=0;
-    unsigned char minuteCount=0;
     point lastTouch;
-    float average,mph9,kW9;
+    float average;
 
     can1.monitor(true); // set to snoop mode
     can2.monitor(true); // set to snoop mode
@@ -155,7 +153,7 @@
     t = *localtime(&seconds) ;
     strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t);
     logMsg(sTemp);
-    sprintf(sTemp,"CANary firmware rev51\n");
+    sprintf(sTemp,"CANary firmware rev52\n");
     logMsg(sTemp);
 
     // Look for new binary on thumbdrive
@@ -559,38 +557,21 @@
             numSsamples=0;
             mWs_x4=0;
             numWsamples=0;
-            // First ten are updated each second
-            for(i=1;i<10;i++){
-                mph9=mph[i]/timeConstant[i];
-                mph[i]-=mph9;
-                mph[i]+=mph[0];
-                kW9=kW[i]/timeConstant[i];
-                kW[i]-=kW9;
-                kW[i]+=kW[0];
-                mpkWh[i]=mph[i];
-                mpkWh[i]/=kW[i];
-                if (mpkWh[i]<0) {
-                    mpkWh[i]=99;// negative means inf.
-                }
-                //mpkWh[i]=floor(mpkWh[i]*10+0.5)/10; // Round to nearest 10th
-           }
-           // The rest are updated each minute
-           if(++minuteCount>59){ //
-                minuteCount=0;
-                for(i=10;i<39;i++){
+            if(accOn){
+                for(i=1;i<39;i++){
                     average=mph[i]/timeConstant[i];
                     mph[i]-=average;
-                    mph[i]+=mph9;
+                    mph[i]+=mph[0];
+                    mpkWh[i]=average;
                     average=kW[i]/timeConstant[i];
                     kW[i]-=average;
-                    kW[i]+=kW9;
-                    mpkWh[i]=mph[i];
-                    mpkWh[i]/=kW[i];
+                    kW[i]+=kW[0];
+                    mpkWh[i]/=average;
                     if (mpkWh[i]<0) {
                         mpkWh[i]=99;// negative means inf.
                     }
                     //mpkWh[i]=floor(mpkWh[i]*10+0.5)/10; // Round to nearest 10th
-                }
+               }
             }
             updateDTE=true;
             if(logCP)