Dual CANbus monitor and instrumentation cluster

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed

Fork of CANary by Tick Tock

Revision:
26:462ccb580472
Parent:
25:ddf0ec209f03
Child:
27:6bd073c33977
--- a/displayModes.cpp	Fri Mar 15 04:28:34 2013 +0000
+++ b/displayModes.cpp	Sat Mar 16 02:07:09 2013 +0000
@@ -112,7 +112,7 @@
 
 void braking (bool force, bool prdata=false){
     unsigned long targetBraking, regenBraking, speed;
-    static unsigned long maxTarget = 0, maxRegen = 0, tarDivReg = 1000000;
+    static unsigned long maxTarget = 0, maxRegen = 0, tarDivReg = 1000;
     short rpm;
     unsigned long temp;
     static unsigned char lastPressure[4] = {200,200,200,200};
@@ -169,18 +169,18 @@
 
     if(targetBraking>50){
         temp = targetBraking;
-        temp *= 200;
+        temp *=200;
         temp /= maxTarget;
         t = (char) temp;
-        if (t>220) t=220;
+        if (t>200) t=200;
         temp = regenBraking;
         temp *= tarDivReg;
-        temp *= 200;
         temp /= maxTarget;
+        temp /= 5;
         r = (char) temp;
-        if (r>220) r=220;
+        if (r>200) r=200;
         if(lr!=r&&prdata){
-            tt.foreground(Red);
+            tt.foreground(Yellow);
             tt.set_font((unsigned char*) Arial28x28);
             tt.locate(100,40);
             printf("%d %d    \n",regenBraking,maxRegen);
@@ -188,12 +188,18 @@
             printf("%3.1f (%3.1f%s)    \n",(float)tarDivReg/10,(float)regenBraking*tarDivReg/targetBraking/10,"%");
         }    
         if(lt!=t&&prdata){
-            tt.foreground(Red);
+            tt.foreground(Yellow);
             tt.set_font((unsigned char*) Arial28x28);
             tt.locate(100,10);
             printf("%d %d    \n",targetBraking,maxTarget);
         }
+        if (r>t) t=r;  //Should never happen
         if((lr!=r||lt!=t)&&!prdata){
+            tt.fillrect(200,10,300,239-t,Navy);
+            tt.fillrect(200,239-t,300,239-r,Red);
+            tt.fillrect(200,239-r,300,239,Green);
+        }
+        /*if((lr!=r||lt!=t)&&!prdata){
             if(t<lt){
                 tt.fillrect(200,238-lt,300,237-t,Navy);
                 if(t<lr) lr=t;
@@ -205,7 +211,7 @@
             } else {
                 tt.fillrect(200,238-r,300,238-lr,Green);
             }
-        }
+        }*/
         lt=t;
         lr=r;
     }
@@ -308,36 +314,36 @@
             tt.foreground(Yellow);
             tt.background(DarkCyan);
             tt.set_font((unsigned char*) Arial12x12);
-            sprintf(sTemp1,"");
+            sprintf(sTemp2,"");
             switch(dtMode){
                 case 0:
-                    sprintf(sTemp2,"Year");
+                    sprintf(sTemp1,"Year");
                     break;
                 case 1:
-                    sprintf(sTemp2,"Month");
+                    sprintf(sTemp1,"Month");
                     break;
                 case 2:
-                    sprintf(sTemp2,"Day");
+                    sprintf(sTemp1,"Day");
                     break;
                 case 3:
-                    sprintf(sTemp2,"Hour");
+                    sprintf(sTemp1,"Hour");
                     break;
                 case 4:
-                    sprintf(sTemp2,"Minute");
+                    sprintf(sTemp1,"Minute");
                     break;
                 case 5:
-                    sprintf(sTemp2,"Second");
+                    sprintf(sTemp1,"Second");
                     break;
                 case 6:
-                    sprintf(sTemp2,"Select");
+                    sprintf(sTemp1,"Select");
                     break;
                 default:
                     break;
             }
             showButton(0,1,sTemp1,sTemp2,3,3);               
-            sprintf(sTemp2,"   UP");
+            sprintf(sTemp1,"   UP");
             showButton(1,1,sTemp1,sTemp2,3,3);               
-            sprintf(sTemp2,"  DOWN");
+            sprintf(sTemp1,"  DOWN");
             showButton(2,1,sTemp1,sTemp2,3,3);               
         }
     }