Dual CANbus monitor and instrumentation cluster

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed

Fork of CANary by Tick Tock

Branch:
Metric
Revision:
118:02010b18efdc
Parent:
117:49883c779a74
Child:
119:0e2b641e98a2
--- a/main.cpp	Thu Jul 04 18:01:52 2013 +0000
+++ b/main.cpp	Fri Jul 05 15:38:40 2013 +0000
@@ -12,7 +12,6 @@
 // * Change semilog efficiency graph to linear with 10 minute values
 // * Add additional 79b bank readouts
 // * Add ability to transfer settings config file to/from USB
-// * Move log dump to ISR (but CAN RX at higher priority)
 
 #include "mbed.h"
 #include "CAN.h"
@@ -24,7 +23,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "117"; // gg - revision string, max 6 characters
+char revStr[7] = "118"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -123,6 +122,7 @@
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
+float unloadedVavg,unloadedV,Resr,Rlms,redRlms,incRlms;
 // Logarithmic division scale (roughly - snapped to common units of time)
 float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute
                      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
@@ -152,7 +152,7 @@
     touchpad.rise(&touch_ISR);
     tt.wfi();               // enable interrupt on touch
     dled = 0.8; // turn on display LED 80%
-
+    Resr = 0.1; // initial guess of Resr
     timer.start() ;
     RTC_Init(); // start the RTC Interrupts that sync the timer
     struct tm t; // pointer to a static tm structure
@@ -724,9 +724,22 @@
                 if (mpkWh[0]<0) {
                     mpkWh[0]=99;// negative means inf.
                 }
+                unloadedV = unloadedVavg/numWsamples;
+                //Rlms /= numWsamples; //unecessary
+                //redRlms /= numWsamples;
+                //incRlms /= numWsamples;
+                if (redRlms<Rlms) {
+                    Resr-=0.001;
+                } else if (incRlms<Rlms) {
+                    Resr+=0.001;
+                }
             } else {
                 kW[0]=0;
                 mpkWh[0]=0;
+                unloadedVavg=0;
+                Rlms=0;
+                redRlms=0;
+                incRlms=0;
             }
             kWh_trip[0]+=kW[0]/3600;
             kWh_trip[1]+=kW[0]/3600;