test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Revision:
40:0e6e71a7323f
Parent:
39:eef8beac7411
Child:
41:8d4609ea7259
--- a/main.cpp	Mon Mar 25 15:13:15 2013 +0000
+++ b/main.cpp	Sun Mar 31 17:45:05 2013 +0000
@@ -85,7 +85,8 @@
 unsigned short pollInt = 300; // polling interval=5 minutes (until config file read)
 bool accOn = false; // Accessories on
 float scale12V = 16.2; // R1:R2 ratio
-signed long mWs = 0;
+signed long mWs_x4 = 0;
+unsigned short numWsamples = 0;
 unsigned long miles = 0;
 float mpkWh = 0;
 float accV = 0;
@@ -95,7 +96,6 @@
 bool step = false;
 char header[5];
 char data[8];
-//unsigned short pbts;
 
 int main() {
     int readPointer=0;
@@ -280,8 +280,12 @@
         if(touched){ // call touchscreen procedure if touch interrupt detected
             lastTouch = tt.get_touch();       
             lastTouch = tt.to_pixel(lastTouch);          // convert to pixel pos
-            if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){
-                secsNoTouch=0; //debounce
+            if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){ // filter phantom touches
+                if (!userIdle) {
+                    secsNoTouch=0;
+                } else {
+                    secsNoTouch=2; // Ignore first touch if user idle
+                }
             }
             //sprintf(sTemp,"%d,%d ",lastTouch.x,lastTouch.y);
             //logMsg(sTemp);
@@ -360,7 +364,7 @@
                             case 31:
                                 if (dMode[i]==config1Screen) {
                                     logEn = !logEn;
-                                    if (!logEn) repeatPoll=false;
+                                    if (!logEn) repeatPoll=false; // disable auto polling, too
                                 } else if (dMode[i]==dateScreen){
                                     dtMode=(dtMode<6)?dtMode+1:0;
                                     lastDMode[i]=99;
@@ -450,24 +454,29 @@
         }
 
         if(tick){ // Executes once a second
-            accV=mon12V*scale12V;
+            accV=floor(mon12V*scale12V*10+0.5)/10;
+            //accV=mon12V*scale12V;
             accOn=(accV>5)?true:false;
             if(!accOn&&!logEn&&userIdle&&!playbackEn){
+                //sprintf(sTemp,"Display Off %4.2f\n",accV);
+                //logMsg(sTemp);
                 dled = 0; // turn off display if car off and logging disabled and no user activity
             }else if(!headlights){
                 dled = ledHi;
             }else{
                 dled = ledLo;
             }
-            //if(mWs>0){
-            if(true){
-                mpkWh= ((float) mWs)/1e6; // just kW for now               
+            //if(mWs_x4>0){
+            if(numWsamples>0){
+                mpkWh= ((float) mWs_x4)/numWsamples/4e3; // just kW for now               
             }else{
                 mpkWh=99;
             }
             miles=0;
-            mWs=0;
-            if(logCP) logPackVoltages(); // Turbo3
+            mWs_x4=0;
+            numWsamples=0;
+            if(logCP)
+                logPackVoltages(); // Turbo3
             tick=false;
         }
 
@@ -478,8 +487,8 @@
             sendCPreq(); // send cellpair data request.
             wait_ms(16);
             sendTreq(); //send temperature request
-            wait_ms(16);
-            showCP=true;
+            //wait_ms(16);
+            //showCP=true;
             pollCP=false;
         }