test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Revision:
55:591406a71fa8
Parent:
54:6ce808d0995e
Parent:
52:d5385fbf4ea1
Child:
56:0de6b316c19b
--- a/main.cpp	Tue Apr 09 06:16:26 2013 +0000
+++ b/main.cpp	Tue Apr 09 06:45:46 2013 +0000
@@ -103,12 +103,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() {
@@ -116,9 +115,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
@@ -162,7 +160,9 @@
     // sprintf(sTemp,"CANary firmware rev51-gg1\n"); // gg - shows 4x4 buttons, 
             // but the touch areas are still 3x3 
     //sprintf(sTemp,"CANary firmware rev51-gg2\n"); // gg - decodes 4x4 button touches, 
-    sprintf(sTemp,"CANary firmware rev51-gg3\n"); // gg - cleaned 4x4 button and touches, 
+    //sprintf(sTemp,"CANary firmware rev51-gg3\n"); // gg - cleaned 4x4 button and touches, 
+    //sprintf(sTemp,"CANary firmware rev52\n"); 
+    sprintf(sTemp,"CANary firmware rev54\n"); // merged 53 (51-gg3) and 52
     logMsg(sTemp);
 
     // Look for new binary on thumbdrive
@@ -596,38 +596,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)