Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Committer:
TickTock
Date:
Wed Sep 25 03:33:18 2013 +0000
Revision:
149:e9739523109f
Parent:
148:6e3b9135fad2
Child:
150:ef46ce63345c
Compensated DTE with air drag of current ambient temperature.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TickTock 13:62e0f7f39ff5 1 //displayModes.cpp
TickTock 37:fea2c1d52c5f 2 #include "displayModes.h"
TickTock 13:62e0f7f39ff5 3
TickTock 25:ddf0ec209f03 4 char sTemp1[40];
TickTock 24:6cf76ed8c432 5 char sTemp2[16];
TickTock 13:62e0f7f39ff5 6
TickTock 42:4533b13b297d 7 void mainDisplay (bool force, bool showButtons){
TickTock 124:0d622967b764 8 unsigned short gids, SOC_x10, packV_x2, tireP;
TickTock 136:41a204105511 9 float useable_kWh,dte;
TickTock 149:e9739523109f 10 //unsigned char aTemp;
TickTock 148:6e3b9135fad2 11 static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0;
TickTock 148:6e3b9135fad2 12 static unsigned char laTemp=0;
TickTock 138:a2f5af85ed0d 13 static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0;
TickTock 131:0d926c080a65 14
TickTock 13:62e0f7f39ff5 15 CANMessage msg;
TickTock 13:62e0f7f39ff5 16
TickTock 13:62e0f7f39ff5 17 msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
TickTock 13:62e0f7f39ff5 18 gids = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 13:62e0f7f39ff5 19 msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC
TickTock 122:138a40892a4c 20 SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 13:62e0f7f39ff5 21 msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts
TickTock 119:0e2b641e98a2 22 packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6);
TickTock 149:e9739523109f 23
TickTock 124:0d622967b764 24 msg = lastMsg[indexLastMsg[0x385]]; //Get tire pressure
TickTock 124:0d622967b764 25 tireP = msg.data[2]+msg.data[3]+msg.data[4]+msg.data[5];
TickTock 118:02010b18efdc 26
TickTock 13:62e0f7f39ff5 27 tt.background(Navy);
TickTock 38:155ec32c5e91 28 tt.set_font((unsigned char*) Arial28x28);
TickTock 13:62e0f7f39ff5 29 if(force) tt.cls();
TickTock 48:d1ce92104a1f 30 if(skin==ttSkin){
TickTock 50:83d5864c64a0 31 if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){
TickTock 136:41a204105511 32 tt.locate(16,10);
TickTock 136:41a204105511 33 tt.foreground(White);
TickTock 136:41a204105511 34 printf("%3d gids \n",gids);
TickTock 49:a3d2c5bb3cfa 35 tt.locate(10,40);
TickTock 136:41a204105511 36 tt.foreground(Cyan);
TickTock 136:41a204105511 37 useable_kWh = (float)(gids-5)*0.075;
TickTock 136:41a204105511 38 if (useable_kWh<0){
TickTock 136:41a204105511 39 useable_kWh=0;
TickTock 136:41a204105511 40 }
TickTock 132:08748a67280a 41 printf("%4.1f kWh \n",useable_kWh);
TickTock 136:41a204105511 42
TickTock 132:08748a67280a 43 // Display DTE
TickTock 149:e9739523109f 44 dte=convertDistance(minTripEff*nomDrag/airDrag(ambient_F)*useable_kWh);
TickTock 136:41a204105511 45 tt.foreground(Green);
TickTock 138:a2f5af85ed0d 46 tt.locate(20,80);
TickTock 139:ac227b203ef2 47 if(dte>=9.5){
TickTock 136:41a204105511 48 printf("%2.0f \n",dte); //LM - add metric conversion
TickTock 136:41a204105511 49 }else{
TickTock 136:41a204105511 50 printf("%2.1f \n",dte); //LM - add metric conversion
TickTock 136:41a204105511 51 }
TickTock 136:41a204105511 52
TickTock 48:d1ce92104a1f 53 tt.set_font((unsigned char*) SCProSB31x55);
TickTock 136:41a204105511 54 tt.foreground(Yellow);
TickTock 149:e9739523109f 55 //Totest:convert from 25C to current ambient temperature
TickTock 149:e9739523109f 56 dte=convertDistance(mpkWh[dtePeriod]);
TickTock 136:41a204105511 57 if(dte>199){
TickTock 136:41a204105511 58 dte=199;
TickTock 136:41a204105511 59 }
TickTock 136:41a204105511 60 // " "=0x10, "."=0x15, #=0x1D
TickTock 139:ac227b203ef2 61 if(dte>=99.5){
TickTock 138:a2f5af85ed0d 62 tt.locate(80,85);
TickTock 138:a2f5af85ed0d 63 printf(" %3.0f\n",dte); //LM - add metric conversion
TickTock 139:ac227b203ef2 64 }else if(dte>=9.5){
TickTock 138:a2f5af85ed0d 65 tt.locate(94,85);
TickTock 136:41a204105511 66 printf(" %2.0f\n",dte); //LM - add metric conversion
TickTock 136:41a204105511 67 }else{
TickTock 138:a2f5af85ed0d 68 tt.locate(89,85);
TickTock 136:41a204105511 69 printf(" %2.1f\n",dte); //LM - add metric conversion
TickTock 136:41a204105511 70 }
TickTock 136:41a204105511 71 tt.set_font((unsigned char*) Arial28x28);
TickTock 138:a2f5af85ed0d 72 tt.locate(195,106);
TickTock 137:70853cf5a30f 73 printf("%s\n",distanceUnit()); //LM - add metric conversion
TickTock 136:41a204105511 74
TickTock 149:e9739523109f 75 dte=convertDistance(maxTripEff*nomDrag/airDrag(ambient_F)*useable_kWh);
TickTock 136:41a204105511 76 tt.foreground(Orange);
TickTock 139:ac227b203ef2 77 if(dte>=99.5){
TickTock 138:a2f5af85ed0d 78 tt.locate(255,80);
TickTock 138:a2f5af85ed0d 79 printf("%3.0f \n",dte); //LM - add metric conversion
TickTock 139:ac227b203ef2 80 }else if(dte>=9.5){
TickTock 138:a2f5af85ed0d 81 tt.locate(270,80);
TickTock 136:41a204105511 82 printf("%2.0f \n",dte); //LM - add metric conversion
TickTock 136:41a204105511 83 }else{
TickTock 138:a2f5af85ed0d 84 tt.locate(265,80);
TickTock 136:41a204105511 85 printf("%2.1f \n",dte); //LM - add metric conversion
TickTock 136:41a204105511 86 }
TickTock 48:d1ce92104a1f 87 lgids=gids;
TickTock 50:83d5864c64a0 88 lmpkWh=mpkWh[dtePeriod];
TickTock 48:d1ce92104a1f 89 }
TickTock 49:a3d2c5bb3cfa 90 if(force||kW[0]!=lkW){
TickTock 136:41a204105511 91 tt.foreground(Cyan);
TickTock 122:138a40892a4c 92 if(kW[0]<-10){ //Right justify
TickTock 122:138a40892a4c 93 tt.locate(171,40);
TickTock 122:138a40892a4c 94 printf("%4.2fkW\n",kW[0]);
TickTock 122:138a40892a4c 95 } else if (kW[0]<0){
TickTock 122:138a40892a4c 96 tt.locate(171,40);
TickTock 122:138a40892a4c 97 printf(" %4.2fkW\n",kW[0]);
TickTock 122:138a40892a4c 98 } else if (kW[0]<10){
TickTock 122:138a40892a4c 99 tt.locate(165,40);
TickTock 122:138a40892a4c 100 printf(" %4.2fkW\n",kW[0]);
TickTock 122:138a40892a4c 101 } else {
TickTock 122:138a40892a4c 102 tt.locate(165,40);
TickTock 122:138a40892a4c 103 printf(" %4.2fkW\n",kW[0]);
TickTock 122:138a40892a4c 104 }
TickTock 49:a3d2c5bb3cfa 105 lkW=kW[0];
TickTock 48:d1ce92104a1f 106 }
TickTock 136:41a204105511 107 if(force||SOC_x10!=lSOC){
TickTock 136:41a204105511 108 tt.locate(215,10);
TickTock 136:41a204105511 109 tt.foreground(White);
TickTock 136:41a204105511 110 printf("%4.1f%s\n",(float)SOC_x10/10,"%");
TickTock 136:41a204105511 111 lSOC=SOC_x10;
TickTock 136:41a204105511 112 }
TickTock 136:41a204105511 113 if(force||packV_x2!=lpackV_x2){
TickTock 136:41a204105511 114 tt.locate(210,176);
TickTock 136:41a204105511 115 tt.foreground(Yellow);
TickTock 136:41a204105511 116 printf("%4.1fV\n",(float)packV_x2/2);
TickTock 136:41a204105511 117 lpackV_x2=packV_x2;
TickTock 136:41a204105511 118 ltireP=0;//Force tire pressure redraw, too
TickTock 136:41a204105511 119 }
TickTock 149:e9739523109f 120 if(force||ambient_F!=laTemp){
TickTock 138:a2f5af85ed0d 121 tt.foreground(Cyan);
TickTock 148:6e3b9135fad2 122 tt.locate(20,146);
TickTock 149:e9739523109f 123 printf("%2.0f%s\n",convertF(ambient_F),temperatureUnit());
TickTock 149:e9739523109f 124 laTemp=ambient_F;
TickTock 148:6e3b9135fad2 125 }
TickTock 136:41a204105511 126 if(force||maxTemp!=lmaxTemp){
TickTock 136:41a204105511 127 tt.foreground(Cyan);
TickTock 138:a2f5af85ed0d 128 tt.locate(210,146);
TickTock 148:6e3b9135fad2 129 if (convertC(maxTemp)<100){
TickTock 148:6e3b9135fad2 130 printf(" %3.1f%s\n",convertC(maxTemp),temperatureUnit());
TickTock 136:41a204105511 131 }else{
TickTock 148:6e3b9135fad2 132 printf("%4.1f%s\n",convertC(maxTemp),temperatureUnit());
TickTock 136:41a204105511 133 }
TickTock 136:41a204105511 134 lmaxTemp=maxTemp;
TickTock 136:41a204105511 135 }
TickTock 136:41a204105511 136 if(force||accV!=laccV){
TickTock 136:41a204105511 137 tt.locate(20,176);
TickTock 136:41a204105511 138 tt.foreground(Yellow);
TickTock 148:6e3b9135fad2 139 printf("%3.1fV \n",accV);
TickTock 136:41a204105511 140 laccV=accV;
TickTock 136:41a204105511 141 }
TickTock 131:0d926c080a65 142 if(force||tireP!=ltireP){
TickTock 134:ad243e4f1a17 143 if(msg.data[2]<minTirePressure){
TickTock 134:ad243e4f1a17 144 tt.foreground(Orange); // Hi-light if any are low (<35psi)
TickTock 134:ad243e4f1a17 145 }else{
TickTock 134:ad243e4f1a17 146 tt.foreground(LightGrey);
TickTock 134:ad243e4f1a17 147 }
TickTock 131:0d926c080a65 148 if(msg.data[6]&0x80){
TickTock 134:ad243e4f1a17 149 if(msg.data[2]<minTirePressure){
TickTock 134:ad243e4f1a17 150 tt.foreground(Orange); // Hi-light if any are low (<35psi)
TickTock 134:ad243e4f1a17 151 }else{
TickTock 134:ad243e4f1a17 152 tt.foreground(LightGrey);
TickTock 134:ad243e4f1a17 153 }
TickTock 131:0d926c080a65 154 tt.locate(10,206);
TickTock 131:0d926c080a65 155 printf("%3.1f\n",(float)msg.data[2]/4);
TickTock 131:0d926c080a65 156 }
TickTock 131:0d926c080a65 157 if(msg.data[6]&0x40){
TickTock 134:ad243e4f1a17 158 if(msg.data[3]<minTirePressure){
TickTock 134:ad243e4f1a17 159 tt.foreground(Orange); // Hi-light if any are low (<35psi)
TickTock 134:ad243e4f1a17 160 }else{
TickTock 134:ad243e4f1a17 161 tt.foreground(LightGrey);
TickTock 134:ad243e4f1a17 162 }
TickTock 131:0d926c080a65 163 tt.locate(90,206);
TickTock 131:0d926c080a65 164 printf("%3.1f\n",(float)msg.data[3]/4);
TickTock 131:0d926c080a65 165 }
TickTock 131:0d926c080a65 166 if(msg.data[6]&0x20){
TickTock 134:ad243e4f1a17 167 if(msg.data[4]<minTirePressure){
TickTock 134:ad243e4f1a17 168 tt.foreground(Orange); // Hi-light if any are low (<35psi)
TickTock 134:ad243e4f1a17 169 }else{
TickTock 134:ad243e4f1a17 170 tt.foreground(LightGrey);
TickTock 134:ad243e4f1a17 171 }
TickTock 131:0d926c080a65 172 tt.locate(170,206);
TickTock 131:0d926c080a65 173 printf("%3.1f\n",(float)msg.data[4]/4);
TickTock 131:0d926c080a65 174 }
TickTock 131:0d926c080a65 175 if(msg.data[6]&0x10){
TickTock 134:ad243e4f1a17 176 if(msg.data[5]<minTirePressure){
TickTock 134:ad243e4f1a17 177 tt.foreground(Orange); // Hi-light if any are low (<35psi)
TickTock 134:ad243e4f1a17 178 }else{
TickTock 134:ad243e4f1a17 179 tt.foreground(LightGrey);
TickTock 134:ad243e4f1a17 180 }
TickTock 131:0d926c080a65 181 tt.locate(250,206);
TickTock 131:0d926c080a65 182 printf("%3.1f\n",(float)msg.data[5]/4);
TickTock 131:0d926c080a65 183 }
TickTock 131:0d926c080a65 184 ltireP=tireP;
TickTock 102:fd19f777a0b4 185 }
TickTock 48:d1ce92104a1f 186 }else {//if(skin==ggSkin){
TickTock 48:d1ce92104a1f 187 if(force||gids!=lgids){
TickTock 48:d1ce92104a1f 188 tt.locate(10,10);
TickTock 48:d1ce92104a1f 189 printf("%4d GIDs \n",gids);
TickTock 48:d1ce92104a1f 190
TickTock 48:d1ce92104a1f 191 tt.locate(40,40); // gg - add GIDs Percent of 281
TickTock 48:d1ce92104a1f 192 printf("%4.1f%s \n", (float)gids*0.355872, "% ") ;
TickTock 48:d1ce92104a1f 193 tt.locate(20,70);
TickTock 48:d1ce92104a1f 194 printf("%4.1f kwh \n",(float)gids*0.075); // gg - closer to usable
TickTock 48:d1ce92104a1f 195
TickTock 48:d1ce92104a1f 196 tt.set_font((unsigned char*) SCProSB31x55);
TickTock 48:d1ce92104a1f 197 tt.foreground(Green);
TickTock 48:d1ce92104a1f 198 //tt.locate(60,96);
TickTock 48:d1ce92104a1f 199 tt.locate(60,116); // gg - move down a little
leafman 98:9f8bab96edff 200 printf("%4.1f %s \n",convertDistance((float)(gids-5)*0.31),distanceUnit()); // Approx for now - LM added metric
TickTock 48:d1ce92104a1f 201 lgids=gids;
TickTock 48:d1ce92104a1f 202 tt.foreground(Yellow);
TickTock 48:d1ce92104a1f 203 tt.set_font((unsigned char*) Arial28x28);
TickTock 48:d1ce92104a1f 204 }
TickTock 48:d1ce92104a1f 205
TickTock 122:138a40892a4c 206 if(force||SOC_x10!=lSOC){
TickTock 48:d1ce92104a1f 207 tt.locate(200,10);
TickTock 122:138a40892a4c 208 printf("%4.1f%s\n",(float)SOC_x10/10,"% ");
TickTock 122:138a40892a4c 209 lSOC=SOC_x10;
TickTock 48:d1ce92104a1f 210 }
TickTock 119:0e2b641e98a2 211 if(force||packV_x2!=lpackV_x2){
TickTock 48:d1ce92104a1f 212 tt.locate(200,200);
TickTock 119:0e2b641e98a2 213 printf("%4.1fV \n",(float)packV_x2/2);
TickTock 119:0e2b641e98a2 214 lpackV_x2=packV_x2;
TickTock 48:d1ce92104a1f 215 }
TickTock 48:d1ce92104a1f 216 if(force||accV!=laccV){
TickTock 48:d1ce92104a1f 217 tt.locate(20,200);
TickTock 48:d1ce92104a1f 218 printf("%3.1fV \n",accV);
TickTock 48:d1ce92104a1f 219 laccV=accV;
TickTock 48:d1ce92104a1f 220 }
TickTock 49:a3d2c5bb3cfa 221 if(force||kW[0]!=lkW){
TickTock 48:d1ce92104a1f 222 tt.locate(160,40); // gg - move left to keep from wrap
TickTock 49:a3d2c5bb3cfa 223 printf("%3.2fkw \n",kW[0]); // use small w to save space
TickTock 49:a3d2c5bb3cfa 224 lkW=kW[0];
TickTock 48:d1ce92104a1f 225 }
TickTock 35:5acbd8a64a89 226 }
TickTock 108:29b5a760adc2 227 if(led4){
TickTock 106:f016912a03db 228 tt.fillcircle(310,10,6,Red);
TickTock 106:f016912a03db 229 }else{
TickTock 106:f016912a03db 230 tt.fillcircle(310,10,6,Navy);
TickTock 106:f016912a03db 231 }
TickTock 13:62e0f7f39ff5 232 }
TickTock 13:62e0f7f39ff5 233
TickTock 42:4533b13b297d 234 void printLast (bool force, bool showButtons){
TickTock 13:62e0f7f39ff5 235 CANMessage msg;
TickTock 13:62e0f7f39ff5 236 tt.locate(0,6);
TickTock 13:62e0f7f39ff5 237 tt.foreground(Red);
TickTock 13:62e0f7f39ff5 238 tt.background(Yellow);
TickTock 13:62e0f7f39ff5 239 if(force) tt.cls(); // Just clear screen if forced - always update display
TickTock 13:62e0f7f39ff5 240 tt.set_font((unsigned char*) Arial12x12_prop); // select the font
TickTock 13:62e0f7f39ff5 241 for(int i=0; i<19; i++){
TickTock 13:62e0f7f39ff5 242 msg = lastMsg[i+indexOffset];
TickTock 13:62e0f7f39ff5 243 printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
TickTock 13:62e0f7f39ff5 244 }
TickTock 122:138a40892a4c 245 if(showButtons){
TickTock 25:ddf0ec209f03 246 tt.foreground(Yellow);
TickTock 25:ddf0ec209f03 247 tt.background(DarkCyan);
TickTock 25:ddf0ec209f03 248 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 249
garygid 54:6ce808d0995e 250 showButton(0,0," <up>","",4,4);
garygid 54:6ce808d0995e 251 showButton(2,0,"<down>","",4,4);
TickTock 25:ddf0ec209f03 252 }
TickTock 13:62e0f7f39ff5 253 }
TickTock 13:62e0f7f39ff5 254
TickTock 42:4533b13b297d 255 void printChanged (bool force, bool showButtons){
TickTock 13:62e0f7f39ff5 256 CANMessage msg;
TickTock 13:62e0f7f39ff5 257 unsigned char i,j;
TickTock 13:62e0f7f39ff5 258 tt.locate(0,6);
TickTock 13:62e0f7f39ff5 259 tt.foreground(Red);
TickTock 13:62e0f7f39ff5 260 tt.background(Yellow);
TickTock 13:62e0f7f39ff5 261 if(force) tt.cls(); // Just clear screen if forced - always update display
TickTock 13:62e0f7f39ff5 262 tt.set_font((unsigned char*) Arial12x12_prop); // select the font
TickTock 13:62e0f7f39ff5 263 i=0;
TickTock 13:62e0f7f39ff5 264 j=indexOffset;
TickTock 13:62e0f7f39ff5 265 do{
TickTock 13:62e0f7f39ff5 266 j=j<99?j+1:j;
TickTock 13:62e0f7f39ff5 267 if(msgChanged[j]>0){
TickTock 13:62e0f7f39ff5 268 msg = lastMsg[j];
TickTock 13:62e0f7f39ff5 269 printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
TickTock 13:62e0f7f39ff5 270 i++;
TickTock 13:62e0f7f39ff5 271 }// if changed
TickTock 13:62e0f7f39ff5 272 }while(i<19&&j<99);
TickTock 122:138a40892a4c 273 if(showButtons){
TickTock 40:0e6e71a7323f 274 tt.foreground(Yellow);
TickTock 40:0e6e71a7323f 275 tt.background(DarkCyan);
TickTock 40:0e6e71a7323f 276 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 277 showButton(0,0," <up>","",4,4);
garygid 54:6ce808d0995e 278 showButton(2,0," <down>","",4,4);
garygid 54:6ce808d0995e 279 showButton(1,0," Reset","Baseline",4,4);
TickTock 40:0e6e71a7323f 280 }
TickTock 13:62e0f7f39ff5 281 }
TickTock 13:62e0f7f39ff5 282
TickTock 42:4533b13b297d 283 void printLog (bool force, bool showButtons){
TickTock 118:02010b18efdc 284 static unsigned char lastldl = 0;
TickTock 118:02010b18efdc 285 unsigned char ldl=displayLoc;
TickTock 118:02010b18efdc 286 if(force||ldl!=lastldl){ //only update if changed
TickTock 13:62e0f7f39ff5 287 tt.foreground(Amber);
TickTock 13:62e0f7f39ff5 288 tt.background(Black);
TickTock 13:62e0f7f39ff5 289 tt.cls();
TickTock 13:62e0f7f39ff5 290 tt.locate(0,6);
TickTock 13:62e0f7f39ff5 291 tt.set_font((unsigned char*) Arial12x12);
TickTock 13:62e0f7f39ff5 292 for(int i=0; i<19; i++){
TickTock 118:02010b18efdc 293 printf("%s",displayLog[ldl]);
TickTock 118:02010b18efdc 294 ldl=ldl>17?0:ldl+1;
TickTock 13:62e0f7f39ff5 295 }
TickTock 13:62e0f7f39ff5 296 }
TickTock 118:02010b18efdc 297 lastldl=ldl;
TickTock 13:62e0f7f39ff5 298 }
TickTock 13:62e0f7f39ff5 299
TickTock 118:02010b18efdc 300 void tripDisplay (bool force, bool showButtons){
TickTock 118:02010b18efdc 301 static float lkWh=0;
TickTock 118:02010b18efdc 302 tt.background(White);
TickTock 118:02010b18efdc 303 if(force){
TickTock 118:02010b18efdc 304 tt.cls();
TickTock 118:02010b18efdc 305 }
TickTock 118:02010b18efdc 306 if(force||(int)(lkWh*100)!=(int)(kWh_trip[0]*100)){ //only update if changed
TickTock 118:02010b18efdc 307 tt.foreground(Navy);
TickTock 118:02010b18efdc 308 tt.set_font((unsigned char*) Arial28x28);
TickTock 118:02010b18efdc 309 tt.locate(6,210);
TickTock 118:02010b18efdc 310 printf("kWh : %s : Eff\n",distanceUnit());
TickTock 118:02010b18efdc 311 for(int i=0; i<3; i++){
TickTock 118:02010b18efdc 312 tt.locate(6,20+i*60);
TickTock 118:02010b18efdc 313 printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
TickTock 118:02010b18efdc 314 }
TickTock 122:138a40892a4c 315 }
TickTock 122:138a40892a4c 316 if(showButtons){
TickTock 118:02010b18efdc 317 tt.set_font((unsigned char*) Arial12x12);
TickTock 118:02010b18efdc 318 tt.background(DarkCyan);
TickTock 118:02010b18efdc 319 tt.foreground(Yellow);
TickTock 118:02010b18efdc 320 showButton(3,1," Reset"," A",4,4);
TickTock 118:02010b18efdc 321 showButton(3,2," Reset"," B",4,4);
TickTock 118:02010b18efdc 322 lkWh=kWh_trip[0];
TickTock 118:02010b18efdc 323 }
TickTock 118:02010b18efdc 324 }
TickTock 118:02010b18efdc 325
TickTock 118:02010b18efdc 326 void healthDisplay (bool force, bool showButtons){
TickTock 131:0d926c080a65 327 unsigned short gids, SOC_x10, SOH_x2;
TickTock 118:02010b18efdc 328 static unsigned short lgids=0, lSOC=0, lSOH=0;
TickTock 124:0d622967b764 329 static float lmaxTemp=0, lresr=0, lunlV=0;
TickTock 118:02010b18efdc 330 static unsigned long lAh=0;
TickTock 13:62e0f7f39ff5 331 CANMessage msg;
TickTock 13:62e0f7f39ff5 332
TickTock 13:62e0f7f39ff5 333 msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
TickTock 13:62e0f7f39ff5 334 gids = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 13:62e0f7f39ff5 335 msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC
TickTock 122:138a40892a4c 336 SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 131:0d926c080a65 337 msg = lastMsg[indexLastMsg[0x5b3]]; //Get SOH
TickTock 131:0d926c080a65 338 SOH_x2 = msg.data[1];
TickTock 13:62e0f7f39ff5 339
TickTock 118:02010b18efdc 340 tt.background(Blue);
TickTock 38:155ec32c5e91 341 tt.foreground(Yellow);
TickTock 38:155ec32c5e91 342 tt.set_font((unsigned char*) Arial28x28);
TickTock 13:62e0f7f39ff5 343 if(force) tt.cls();
TickTock 121:553faf139a20 344
TickTock 121:553faf139a20 345 /*if(force||tock){ // for esr debug
TickTock 121:553faf139a20 346 tt.locate(10,10);
TickTock 121:553faf139a20 347 printf("%d %d amps\n",Imax,Imin);
TickTock 121:553faf139a20 348 tt.locate(10,40);
TickTock 121:553faf139a20 349 printf(" %4.1f %4.1f\n",incRmax/2,incRmin/2);
TickTock 121:553faf139a20 350 tt.locate(10,70);
TickTock 121:553faf139a20 351 printf(" %4.1f %4.1f\n",redRmax/2,redRmin/2);
TickTock 121:553faf139a20 352 tt.locate(10,100);
TickTock 121:553faf139a20 353 printf(" %4.1f %4.1f\n",curRmax/2,curRmin/2);
TickTock 121:553faf139a20 354 //tt.locate(10,130);
TickTock 121:553faf139a20 355 curRmin=1000;
TickTock 121:553faf139a20 356 curRmax=0;
TickTock 121:553faf139a20 357 incRmin=1000;
TickTock 121:553faf139a20 358 incRmax=0;
TickTock 121:553faf139a20 359 redRmin=1000;
TickTock 121:553faf139a20 360 redRmax=0;
TickTock 121:553faf139a20 361 Imax=-1000;
TickTock 121:553faf139a20 362 Imin=1000;
TickTock 121:553faf139a20 363 }*/
TickTock 118:02010b18efdc 364 if(force||gids!=lgids){
TickTock 118:02010b18efdc 365 tt.locate(10,10);
TickTock 118:02010b18efdc 366 printf("%4d gids \n",gids);
TickTock 119:0e2b641e98a2 367 lgids=gids;
TickTock 118:02010b18efdc 368 }
TickTock 122:138a40892a4c 369 if(force||SOC_x10!=lSOC){
TickTock 119:0e2b641e98a2 370 tt.locate(10,40);
TickTock 122:138a40892a4c 371 printf(" %4.1f%s \n",(float)SOC_x10/10,"% SOC");
TickTock 122:138a40892a4c 372 lSOC=SOC_x10;
TickTock 118:02010b18efdc 373 }
TickTock 143:88b5155622a5 374 if(force||SOH2_x100!=lSOH){
TickTock 118:02010b18efdc 375 tt.locate(10,70);
TickTock 143:88b5155622a5 376 printf(" %4.1f%s,%4.1f%s \n",(float)SOH_x2/2,"%",(float)SOH2_x100/100,"% SOH");
TickTock 143:88b5155622a5 377 lSOH=SOH2_x100;
TickTock 118:02010b18efdc 378 }
TickTock 118:02010b18efdc 379 if(force||Ah_x10000!=lAh){
TickTock 118:02010b18efdc 380 tt.locate(10,100);
TickTock 120:041edeec08f5 381 printf(" %4.2f Ah cap \n",(float)Ah_x10000/10000);
TickTock 118:02010b18efdc 382 lAh=Ah_x10000;
TickTock 118:02010b18efdc 383 }
TickTock 124:0d622967b764 384 if(force||maxTemp!=lmaxTemp){
TickTock 124:0d622967b764 385 tt.locate(10,130);
TickTock 148:6e3b9135fad2 386 printf(" %4.1f %s (max) \n",convertC(maxTemp),temperatureUnit());
TickTock 124:0d622967b764 387 lmaxTemp=maxTemp;
TickTock 124:0d622967b764 388 }
TickTock 123:a8c0042df617 389 if(force||unloadedV_x2!=lunlV){
TickTock 124:0d622967b764 390 tt.locate(10,160);
TickTock 120:041edeec08f5 391 printf(" %4.1f V \n",unloadedV_x2/2);
TickTock 119:0e2b641e98a2 392 lunlV=unloadedV_x2;
TickTock 118:02010b18efdc 393 }
TickTock 118:02010b18efdc 394 if(force||Resr!=lresr){
TickTock 124:0d622967b764 395 tt.locate(10,190);
TickTock 120:041edeec08f5 396 printf(" %3.0f mOhms \n",Resr*1000);
TickTock 118:02010b18efdc 397 lresr=Resr;
TickTock 35:5acbd8a64a89 398 }
TickTock 13:62e0f7f39ff5 399 }
TickTock 13:62e0f7f39ff5 400
TickTock 42:4533b13b297d 401 void braking (bool force, bool showButtons, bool prdata=false){
TickTock 28:f24ac05645d9 402 unsigned long targetBraking, regenBraking;
TickTock 73:62ee8eae3a84 403 static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
TickTock 28:f24ac05645d9 404 unsigned long temp;
TickTock 28:f24ac05645d9 405 static unsigned char lastPressure[4] = {200,200,200,200};
TickTock 28:f24ac05645d9 406 unsigned char i,r,t;
TickTock 37:fea2c1d52c5f 407 static unsigned char lr=0, lt=0;
TickTock 37:fea2c1d52c5f 408 signed short steering;
TickTock 37:fea2c1d52c5f 409 unsigned short s;
TickTock 37:fea2c1d52c5f 410 static unsigned short ls;
TickTock 37:fea2c1d52c5f 411 unsigned char throttle;
TickTock 37:fea2c1d52c5f 412 static unsigned char lthrottle;
TickTock 48:d1ce92104a1f 413 short steerOutBounds = 0 ;
TickTock 28:f24ac05645d9 414 CANMessage msg;
TickTock 28:f24ac05645d9 415
TickTock 48:d1ce92104a1f 416 //---------------
TickTock 37:fea2c1d52c5f 417 msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position
TickTock 37:fea2c1d52c5f 418 throttle = msg.data[5];
TickTock 48:d1ce92104a1f 419
TickTock 48:d1ce92104a1f 420 // ---- steering ----
TickTock 37:fea2c1d52c5f 421 msg = lastMsg[indexLastMsg[0x002]]; //Get Steering angle
TickTock 37:fea2c1d52c5f 422 steering = (msg.data[1]<<8)+msg.data[0];
TickTock 48:d1ce92104a1f 423
TickTock 48:d1ce92104a1f 424 if(skin==ttSkin){
TickTock 66:b7476ce7a59e 425 s= (unsigned short) ((steering/10)+155)%310; // this modulo wraps display
TickTock 48:d1ce92104a1f 426 }else{// if(skin==ggSkin){
TickTock 48:d1ce92104a1f 427 // do not go off screen left or right. gg - steering
TickTock 48:d1ce92104a1f 428 short ss = (short) ((steering/15)+160); // less gain 10 -> 15
TickTock 48:d1ce92104a1f 429 if(ss<0) { ss=0; steerOutBounds = 1; }
TickTock 48:d1ce92104a1f 430 if(ss>310) { ss=310; steerOutBounds = 1; }
TickTock 48:d1ce92104a1f 431 s = (unsigned short) ss;
TickTock 48:d1ce92104a1f 432 }
TickTock 48:d1ce92104a1f 433
TickTock 48:d1ce92104a1f 434 //--------------
TickTock 28:f24ac05645d9 435 msg = lastMsg[indexLastMsg[0x1ca]]; //Get brake pressure
TickTock 28:f24ac05645d9 436 tt.background(Navy);
TickTock 28:f24ac05645d9 437 if (force) {
TickTock 28:f24ac05645d9 438 tt.cls();
TickTock 28:f24ac05645d9 439 tt.rect(0,111,170,239,White);
TickTock 28:f24ac05645d9 440 tt.line(0,207,170,207,White);
TickTock 28:f24ac05645d9 441 tt.line(0,175,170,175,White);
TickTock 28:f24ac05645d9 442 tt.line(0,143,170,143,White);
TickTock 28:f24ac05645d9 443 lastPressure[0] = 200;
TickTock 28:f24ac05645d9 444 lastPressure[1] = 200;
TickTock 28:f24ac05645d9 445 lastPressure[2] = 200;
TickTock 28:f24ac05645d9 446 lastPressure[3] = 200;
TickTock 28:f24ac05645d9 447 }
TickTock 48:d1ce92104a1f 448
TickTock 48:d1ce92104a1f 449 // display the steering position small square
TickTock 37:fea2c1d52c5f 450 if (s!=ls){
TickTock 48:d1ce92104a1f 451 // steering position has moved
TickTock 48:d1ce92104a1f 452 //tt.fillrect(ls,5,ls+9,14, Navy); // blank old position
TickTock 48:d1ce92104a1f 453
TickTock 48:d1ce92104a1f 454 //---- gg - steering red
TickTock 48:d1ce92104a1f 455 // box is blanked by top of Braking bar, so move up 5
TickTock 48:d1ce92104a1f 456 tt.fillrect(ls,0,ls+9,9, Navy); // blank old position
TickTock 48:d1ce92104a1f 457 if( steerOutBounds != 0 ) // draw out-of-bounds as a red box
TickTock 48:d1ce92104a1f 458 tt.fillrect(s,0,s+9,9, Red); // draw out-of-bounds position
TickTock 48:d1ce92104a1f 459 else
TickTock 48:d1ce92104a1f 460 tt.fillrect(s,0,s+9,9, White); // draw new in-bounds position
TickTock 48:d1ce92104a1f 461
TickTock 48:d1ce92104a1f 462 //----
TickTock 37:fea2c1d52c5f 463 //tt.foreground(Yellow);
TickTock 37:fea2c1d52c5f 464 //tt.set_font((unsigned char*) Arial28x28);
TickTock 37:fea2c1d52c5f 465 //tt.locate(10,40);
TickTock 37:fea2c1d52c5f 466 //printf("%d %d \n",s,ls);
TickTock 37:fea2c1d52c5f 467 ls=s;
TickTock 37:fea2c1d52c5f 468 }
TickTock 48:d1ce92104a1f 469
TickTock 37:fea2c1d52c5f 470 if (throttle!=lthrottle){
TickTock 37:fea2c1d52c5f 471 if (throttle>239) throttle=239;
TickTock 37:fea2c1d52c5f 472 if(throttle<lthrottle){
TickTock 37:fea2c1d52c5f 473 tt.fillrect(280,239-lthrottle,310,239-throttle,Navy);
TickTock 37:fea2c1d52c5f 474 }else{
TickTock 37:fea2c1d52c5f 475 tt.fillrect(280,239-throttle,310,239,Yellow);
TickTock 37:fea2c1d52c5f 476 }
TickTock 37:fea2c1d52c5f 477 lthrottle=throttle;
TickTock 37:fea2c1d52c5f 478 }
TickTock 37:fea2c1d52c5f 479
TickTock 28:f24ac05645d9 480 // plot bar graph for each wheel pressure
TickTock 28:f24ac05645d9 481 for (i=0; i<4; i++){
TickTock 28:f24ac05645d9 482 if (msg.data[i]<239) {
TickTock 28:f24ac05645d9 483 if (msg.data[i]>lastPressure[i]){
TickTock 28:f24ac05645d9 484 tt.fillrect(10+40*i,239-msg.data[i],40+40*i,239,Red);
TickTock 28:f24ac05645d9 485 } else if (msg.data[i]<lastPressure[i]) {
TickTock 28:f24ac05645d9 486 tt.fillrect(10+40*i,238-lastPressure[i],40+40*i,238-msg.data[i],Navy);
TickTock 28:f24ac05645d9 487 }
TickTock 28:f24ac05645d9 488 lastPressure[i]=msg.data[i];
TickTock 28:f24ac05645d9 489 }
TickTock 28:f24ac05645d9 490 }
TickTock 28:f24ac05645d9 491
TickTock 73:62ee8eae3a84 492 msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen
TickTock 73:62ee8eae3a84 493 regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
TickTock 73:62ee8eae3a84 494 targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
TickTock 113:f388b4505463 495 msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode
TickTock 113:f388b4505463 496 if (msg.data[0]==0x18) { // In Neutral
TickTock 108:29b5a760adc2 497 regenBraking = 0; // No regen when in Neutral
TickTock 108:29b5a760adc2 498 }
TickTock 73:62ee8eae3a84 499
TickTock 73:62ee8eae3a84 500 if (targetBraking<2045){
TickTock 73:62ee8eae3a84 501 if ((targetBraking>50)&&(regenBraking>50)){
TickTock 73:62ee8eae3a84 502 temp = targetBraking;
TickTock 73:62ee8eae3a84 503 temp *= 1000;
TickTock 73:62ee8eae3a84 504 temp /= regenBraking;
TickTock 73:62ee8eae3a84 505 if (temp<tardivreg_x1000) tardivreg_x1000=temp;
TickTock 73:62ee8eae3a84 506 }
TickTock 73:62ee8eae3a84 507 if (targetBraking>maxTarget) maxTarget=targetBraking;
TickTock 73:62ee8eae3a84 508 if (regenBraking>maxRegen) maxRegen=regenBraking;
TickTock 73:62ee8eae3a84 509 temp = targetBraking;
TickTock 73:62ee8eae3a84 510 temp *=200;
TickTock 73:62ee8eae3a84 511 temp /= maxTarget;
TickTock 73:62ee8eae3a84 512 t = (char) temp;
TickTock 73:62ee8eae3a84 513 if (t>200) t=200;
TickTock 73:62ee8eae3a84 514 temp = regenBraking;
TickTock 73:62ee8eae3a84 515 temp *= tardivreg_x1000;
TickTock 73:62ee8eae3a84 516 temp /= maxTarget;
TickTock 73:62ee8eae3a84 517 temp /= 5; // 1000/200=5
TickTock 73:62ee8eae3a84 518 r = (char) temp;
TickTock 73:62ee8eae3a84 519 if (r>200) r=200;
TickTock 73:62ee8eae3a84 520 if(lr!=r&&prdata){
TickTock 73:62ee8eae3a84 521 tt.foreground(Yellow);
TickTock 73:62ee8eae3a84 522 tt.set_font((unsigned char*) Arial28x28);
TickTock 73:62ee8eae3a84 523 tt.locate(100,40);
TickTock 73:62ee8eae3a84 524 printf("%d %d \n",regenBraking,maxRegen);
TickTock 73:62ee8eae3a84 525 tt.locate(100,70);
TickTock 73:62ee8eae3a84 526 printf("%3.1f (%3.1f%s) \n",(float)tardivreg_x1000/10,(float)regenBraking*tardivreg_x1000/targetBraking/10,"%");
TickTock 73:62ee8eae3a84 527 }
TickTock 73:62ee8eae3a84 528 if(lt!=t&&prdata){
TickTock 73:62ee8eae3a84 529 tt.foreground(Yellow);
TickTock 73:62ee8eae3a84 530 tt.set_font((unsigned char*) Arial28x28);
TickTock 73:62ee8eae3a84 531 tt.locate(100,10);
TickTock 73:62ee8eae3a84 532 printf("%d %d \n",targetBraking,maxTarget);
TickTock 73:62ee8eae3a84 533 }
TickTock 73:62ee8eae3a84 534 if (r>t) t=r; //Should never happen
TickTock 73:62ee8eae3a84 535 if((lr!=r||lt!=t)&&!prdata){
TickTock 73:62ee8eae3a84 536 tt.fillrect(190,10,260,239-t,Navy);
TickTock 73:62ee8eae3a84 537 tt.fillrect(190,239-t,260,239-r,Red);
TickTock 73:62ee8eae3a84 538 tt.fillrect(190,239-r,260,239,Green);
TickTock 73:62ee8eae3a84 539 }
TickTock 73:62ee8eae3a84 540 lt=t;
TickTock 73:62ee8eae3a84 541 lr=r;
TickTock 28:f24ac05645d9 542 }
TickTock 28:f24ac05645d9 543 }
TickTock 28:f24ac05645d9 544
TickTock 42:4533b13b297d 545 void cpData(bool force, bool showButtons){
TickTock 36:dbd39c315258 546 short unsigned max, min, jv, i, bd;
TickTock 36:dbd39c315258 547 unsigned avg;
TickTock 97:a25940fd7b5b 548 static char step=0; // counter to allow incremental update
TickTock 36:dbd39c315258 549 if(force){
TickTock 36:dbd39c315258 550 tt.foreground(White);
TickTock 36:dbd39c315258 551 tt.background(Navy);
TickTock 36:dbd39c315258 552 tt.set_font((unsigned char*) Arial12x12_prop); // select the font
TickTock 36:dbd39c315258 553 max=0;
TickTock 36:dbd39c315258 554 min=9999;
TickTock 36:dbd39c315258 555 avg=0;
TickTock 36:dbd39c315258 556 for(i=0; i<96; i++){
TickTock 124:0d622967b764 557 bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4];
TickTock 36:dbd39c315258 558 avg+=bd;
TickTock 36:dbd39c315258 559 if(bd>max) max=bd;
TickTock 36:dbd39c315258 560 if(bd<min) min=bd;
TickTock 36:dbd39c315258 561 }
TickTock 36:dbd39c315258 562 avg /= 96;
TickTock 36:dbd39c315258 563 if(min<3713) {
TickTock 36:dbd39c315258 564 jv=avg-(max-avg)*1.5;
TickTock 36:dbd39c315258 565 } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement
TickTock 36:dbd39c315258 566 jv=0;
TickTock 36:dbd39c315258 567 }
TickTock 99:c05abf8e1cdc 568
TickTock 107:e9be732c1ad4 569 char* sTemperatureUnit = temperatureUnit();
TickTock 97:a25940fd7b5b 570 switch(step){
TickTock 97:a25940fd7b5b 571 case 0:
TickTock 97:a25940fd7b5b 572 tt.cls();
TickTock 97:a25940fd7b5b 573 showCP=true;
TickTock 97:a25940fd7b5b 574 break;
TickTock 97:a25940fd7b5b 575 case 1:
TickTock 97:a25940fd7b5b 576 tt.locate(0,6);
TickTock 99:c05abf8e1cdc 577 printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n",
TickTock 148:6e3b9135fad2 578 max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
TickTock 148:6e3b9135fad2 579 convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
TickTock 97:a25940fd7b5b 580 tt.rect(8+0*41,16,40+0*41,28,Green);
TickTock 97:a25940fd7b5b 581 tt.rect(8+1*41,16,40+1*41,28,Yellow);
TickTock 97:a25940fd7b5b 582 //tt.rect(8+2*41,16,40+2*41,28,White);
TickTock 97:a25940fd7b5b 583 tt.rect(8+3*41,16,40+3*41,28,Red);
TickTock 97:a25940fd7b5b 584 break;
TickTock 97:a25940fd7b5b 585 default:
TickTock 97:a25940fd7b5b 586 tt.locate(0,36+(step-2)*48);
TickTock 97:a25940fd7b5b 587 for(i=(step-2)*4; i<(step-1)*4; i++){
TickTock 97:a25940fd7b5b 588 printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n",
TickTock 97:a25940fd7b5b 589 i*6+1,i*6+6,
TickTock 124:0d622967b764 590 (battData[BatDataBaseG2*7+i*12+3]<<8)+battData[BatDataBaseG2*7+i*12+4],(battData[BatDataBaseG2*7+i*12+5]<<8)+battData[BatDataBaseG2*7+i*12+6],
TickTock 124:0d622967b764 591 (battData[BatDataBaseG2*7+i*12+7]<<8)+battData[BatDataBaseG2*7+i*12+8],(battData[BatDataBaseG2*7+i*12+9]<<8)+battData[BatDataBaseG2*7+i*12+10],
TickTock 124:0d622967b764 592 (battData[BatDataBaseG2*7+i*12+11]<<8)+battData[BatDataBaseG2*7+i*12+12],(battData[BatDataBaseG2*7+i*12+13]<<8)+battData[BatDataBaseG2*7+i*12+14]);
TickTock 97:a25940fd7b5b 593 }
TickTock 97:a25940fd7b5b 594 for(i=(step-2)*24; i<(step-1)*24; i++){
TickTock 124:0d622967b764 595 bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4];
TickTock 97:a25940fd7b5b 596 if(bd>0){
TickTock 97:a25940fd7b5b 597 if(bd==max) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Green);
TickTock 97:a25940fd7b5b 598 //if(bd==avg) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,White);
TickTock 97:a25940fd7b5b 599 if(bd==min) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Yellow);
TickTock 97:a25940fd7b5b 600 if(bd<jv) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Red);
TickTock 97:a25940fd7b5b 601 }
TickTock 97:a25940fd7b5b 602 }
TickTock 36:dbd39c315258 603 }
TickTock 97:a25940fd7b5b 604 step=step<5?step+1:0;
TickTock 97:a25940fd7b5b 605 if(step==0){
TickTock 97:a25940fd7b5b 606 showCP=false;
TickTock 36:dbd39c315258 607 }
TickTock 36:dbd39c315258 608 }
TickTock 122:138a40892a4c 609 if(showButtons){
TickTock 36:dbd39c315258 610 tt.foreground(Yellow);
TickTock 36:dbd39c315258 611 tt.background(DarkCyan);
TickTock 36:dbd39c315258 612 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 613
garygid 54:6ce808d0995e 614 showButton(1,0,"Request","CP Data",4,4);
TickTock 44:6262a9fd1e56 615 }
TickTock 44:6262a9fd1e56 616 }
TickTock 44:6262a9fd1e56 617
TickTock 44:6262a9fd1e56 618 //----------------
garygid 67:2022fce701d0 619 // gg - index
garygid 67:2022fce701d0 620 void showIndex(bool force, bool showButtons){
garygid 67:2022fce701d0 621
garygid 67:2022fce701d0 622 if(force){
garygid 67:2022fce701d0 623 tt.foreground(White);
garygid 67:2022fce701d0 624 tt.background(Navy);
garygid 67:2022fce701d0 625 //tt.set_font((unsigned char*) Arial12x12_prop); // select the font
garygid 67:2022fce701d0 626
garygid 67:2022fce701d0 627 tt.cls();
garygid 67:2022fce701d0 628
garygid 67:2022fce701d0 629 // add the buttons to GoTo to other screens
garygid 67:2022fce701d0 630
garygid 67:2022fce701d0 631 tt.foreground(Yellow);
garygid 67:2022fce701d0 632 tt.background(DarkCyan);
garygid 67:2022fce701d0 633 tt.set_font((unsigned char*) Arial12x12);
garygid 67:2022fce701d0 634
garygid 67:2022fce701d0 635 // top row
garygid 67:2022fce701d0 636 showButton(0,0," GoTo"," Main",4,4);
garygid 67:2022fce701d0 637 showButton(1,0," GoTo"," Brake",4,4);
garygid 67:2022fce701d0 638 showButton(2,0," GoTo"," EFF",4,4);
TickTock 122:138a40892a4c 639 showButton(3,0," GoTo","Health",4,4);
garygid 67:2022fce701d0 640 // middle row
garygid 67:2022fce701d0 641 showButton(0,1," GoTo","CP Data",4,4);
garygid 67:2022fce701d0 642 showButton(1,1," GoTo","CP Hist",4,4);
garygid 67:2022fce701d0 643 showButton(2,1," GoTo","CP Bars",4,4);
leafman 98:9f8bab96edff 644 showButton(3,1," GoTo"," Config",4,4);
leafman 98:9f8bab96edff 645 // bottom (not Nav) row
leafman 98:9f8bab96edff 646 showButton(0,2," GoTo","Playback",4,4);
TickTock 131:0d926c080a65 647 //showButton(1,2," GoTo","Set Time",4,4);
leafman 98:9f8bab96edff 648 showButton(2,2," GoTo"," Log",4,4);
TickTock 108:29b5a760adc2 649 showButton(3,2," GoTo"," Trip",4,4);
garygid 67:2022fce701d0 650
garygid 67:2022fce701d0 651 showCP=false;
garygid 67:2022fce701d0 652 }
garygid 67:2022fce701d0 653
garygid 67:2022fce701d0 654 if(sMode==1&&showButtons){
garygid 67:2022fce701d0 655 tt.foreground(Yellow);
garygid 67:2022fce701d0 656 tt.background(DarkCyan);
garygid 67:2022fce701d0 657 tt.set_font((unsigned char*) Arial12x12);
garygid 67:2022fce701d0 658
garygid 67:2022fce701d0 659 // do nothing here?
garygid 67:2022fce701d0 660 }
garygid 67:2022fce701d0 661 }
garygid 67:2022fce701d0 662
garygid 67:2022fce701d0 663 //----------------
TickTock 48:d1ce92104a1f 664 // gg - cpbars
TickTock 48:d1ce92104a1f 665 void cpBarPlot(bool force, bool showButtons){
TickTock 48:d1ce92104a1f 666 short unsigned max, min, jv, i, bd;
TickTock 48:d1ce92104a1f 667 unsigned avg;
TickTock 48:d1ce92104a1f 668 short unsigned nBar[96] ; // bar height over min
TickTock 48:d1ce92104a1f 669
TickTock 48:d1ce92104a1f 670 if(force){
TickTock 48:d1ce92104a1f 671 tt.foreground(White);
TickTock 48:d1ce92104a1f 672 tt.background(Navy);
TickTock 48:d1ce92104a1f 673 tt.set_font((unsigned char*) Arial12x12_prop); // select the font
TickTock 48:d1ce92104a1f 674 max=0;
TickTock 48:d1ce92104a1f 675 min=9999;
TickTock 48:d1ce92104a1f 676 avg=0;
TickTock 48:d1ce92104a1f 677
TickTock 48:d1ce92104a1f 678 // calc each cell-pair voltage, find max and min
TickTock 48:d1ce92104a1f 679 for(i=0; i<96; i++){
TickTock 124:0d622967b764 680 bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4];
TickTock 48:d1ce92104a1f 681 nBar[i] = bd; // init to bar height
TickTock 48:d1ce92104a1f 682 avg+=bd;
TickTock 48:d1ce92104a1f 683 if(bd>max) max=bd;
TickTock 48:d1ce92104a1f 684 if(bd<min) min=bd;
TickTock 48:d1ce92104a1f 685 }
TickTock 48:d1ce92104a1f 686 avg /= 96;
TickTock 48:d1ce92104a1f 687
TickTock 48:d1ce92104a1f 688 if(min<3713) {
TickTock 48:d1ce92104a1f 689 jv=avg-(max-avg)*1.5;
TickTock 48:d1ce92104a1f 690 } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement
TickTock 48:d1ce92104a1f 691 jv=0;
TickTock 48:d1ce92104a1f 692 }
TickTock 48:d1ce92104a1f 693
TickTock 48:d1ce92104a1f 694 //------------------
TickTock 48:d1ce92104a1f 695 tt.cls();
TickTock 48:d1ce92104a1f 696
TickTock 48:d1ce92104a1f 697 // show as vertical bar plot
TickTock 48:d1ce92104a1f 698 int xWinMin = 26;
TickTock 48:d1ce92104a1f 699 int xWinMax = 316;
TickTock 48:d1ce92104a1f 700 int yWinMin = 50;
TickTock 48:d1ce92104a1f 701 int yWinMax = 150;
TickTock 48:d1ce92104a1f 702 // draw the Bar Graph Frame, 2 pixels wide
TickTock 48:d1ce92104a1f 703 tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
TickTock 48:d1ce92104a1f 704 tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
TickTock 48:d1ce92104a1f 705
TickTock 48:d1ce92104a1f 706 // bar heights
TickTock 48:d1ce92104a1f 707 int height = yWinMax - yWinMin ;
TickTock 48:d1ce92104a1f 708 int iBarValMax = max - min ; // zero to N
TickTock 48:d1ce92104a1f 709
TickTock 48:d1ce92104a1f 710 //----------------
TickTock 48:d1ce92104a1f 711 if( iBarValMax == 0 ) {
TickTock 48:d1ce92104a1f 712 // for testing
TickTock 48:d1ce92104a1f 713 min = 3501 ;
TickTock 48:d1ce92104a1f 714 //max = min + 95*2 ; // for tall values
TickTock 48:d1ce92104a1f 715 max = min + 95/4 ; // for small values
TickTock 48:d1ce92104a1f 716 avg = ( max + min ) / 2;
TickTock 48:d1ce92104a1f 717 iBarValMax = max - min ; // zero to N
TickTock 48:d1ce92104a1f 718 for(int i=0; i<96; i++) {
TickTock 48:d1ce92104a1f 719 //nBar[i] = i*2 + min ; // test tall values
TickTock 48:d1ce92104a1f 720 nBar[i] = i/4 + min ; // test small values
TickTock 48:d1ce92104a1f 721 }
TickTock 48:d1ce92104a1f 722 }
TickTock 48:d1ce92104a1f 723 //---------------
TickTock 48:d1ce92104a1f 724 float nBarScale = float(height) / iBarValMax ;
TickTock 48:d1ce92104a1f 725 if( nBarScale < 0.1 ) nBarScale = 0.1 ;
TickTock 48:d1ce92104a1f 726
TickTock 48:d1ce92104a1f 727 // do the Bar-height scaling
TickTock 48:d1ce92104a1f 728 for(int i=0; i<96; i++){
TickTock 48:d1ce92104a1f 729 nBar[i] -= min ; // now, 0 to N = iBinValMax
TickTock 48:d1ce92104a1f 730 nBar[i] *= nBarScale ; // scale, as needed
TickTock 48:d1ce92104a1f 731 }
TickTock 48:d1ce92104a1f 732
TickTock 138:a2f5af85ed0d 733 // label the X axis (approximate)
TickTock 138:a2f5af85ed0d 734 //tt.locate( 2, yWinMin-14 ); printf("%04d = %04d from %1.4f", max, int( height / nBarScale ) + min, nBarScale );
TickTock 138:a2f5af85ed0d 735 tt.locate( 2, yWinMin-14 ); printf("%04d = (%d) mv range.\n", max , max - min );
TickTock 138:a2f5af85ed0d 736 tt.locate( 2, yWinMax+5); printf("%04d\n", min );
TickTock 48:d1ce92104a1f 737 // values, for now
TickTock 124:0d622967b764 738 // BatDataBaseG4 * 7 = 280
TickTock 48:d1ce92104a1f 739 tt.locate( 0, yWinMax+40 );
TickTock 108:29b5a760adc2 740 char* sTemperatureUnit = temperatureUnit();
TickTock 138:a2f5af85ed0d 741 printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n",
TickTock 148:6e3b9135fad2 742 max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
TickTock 148:6e3b9135fad2 743 convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
TickTock 108:29b5a760adc2 744 //printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
TickTock 124:0d622967b764 745 // max,min,avg,jv, battData[BatDataBaseG4*7+5],battData[BatDataBaseG4*7+8], battData[BatDataBaseG4*7+11],battData[BatDataBaseG4*7+14]);
TickTock 48:d1ce92104a1f 746
TickTock 48:d1ce92104a1f 747
TickTock 48:d1ce92104a1f 748 //---------------
TickTock 48:d1ce92104a1f 749 // show the bars
TickTock 48:d1ce92104a1f 750 int nBarWidth = 2 ;
TickTock 48:d1ce92104a1f 751 int nBarSpace = 1 ; // 1 for testing
TickTock 48:d1ce92104a1f 752
TickTock 48:d1ce92104a1f 753 int xPos = xWinMin + 2 ; // start one from the left
TickTock 48:d1ce92104a1f 754
TickTock 48:d1ce92104a1f 755 for( int i=0; i<96; i++) {
TickTock 48:d1ce92104a1f 756 height = nBar[i] ;
TickTock 48:d1ce92104a1f 757 if( height > 100 ) height = 100 ; // clip tops
TickTock 48:d1ce92104a1f 758
TickTock 48:d1ce92104a1f 759 // draw the bar, is always inside x-window
TickTock 121:553faf139a20 760 if (shunt[i]){
TickTock 121:553faf139a20 761 tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Red);
TickTock 121:553faf139a20 762 } else {
TickTock 121:553faf139a20 763 tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);
TickTock 121:553faf139a20 764 }
TickTock 48:d1ce92104a1f 765 // tic mark the y axis each 5
TickTock 48:d1ce92104a1f 766 if(i%5 == 4){
TickTock 48:d1ce92104a1f 767 tt.line( xPos,yWinMax+2, xPos,yWinMax+5, White); // a white tick mark
TickTock 48:d1ce92104a1f 768 tt.line( xPos+1,yWinMax+2, xPos+1,yWinMax+5, White); // a white tick mark, to widen
TickTock 48:d1ce92104a1f 769 //tt.rect( xPos,yWinMax+2, xPos+1,yWinMax+5, White); // a white 2-wide tick mark is SLOW
TickTock 48:d1ce92104a1f 770 }
TickTock 48:d1ce92104a1f 771 // label the y axis each 10
TickTock 48:d1ce92104a1f 772 if(i%10 == 9){
TickTock 48:d1ce92104a1f 773 tt.locate( xPos-6, yWinMax+8 );
TickTock 48:d1ce92104a1f 774 printf("%02d\n", i+1 );
TickTock 48:d1ce92104a1f 775 }
TickTock 48:d1ce92104a1f 776
TickTock 48:d1ce92104a1f 777 // step to the next bar position
TickTock 48:d1ce92104a1f 778 xPos += nBarWidth + nBarSpace ;
TickTock 48:d1ce92104a1f 779 }
TickTock 48:d1ce92104a1f 780
TickTock 48:d1ce92104a1f 781 showCP=false;
TickTock 48:d1ce92104a1f 782 }
TickTock 48:d1ce92104a1f 783
TickTock 48:d1ce92104a1f 784 // handle the button
TickTock 48:d1ce92104a1f 785 if(sMode==1&&showButtons){
TickTock 48:d1ce92104a1f 786 tt.foreground(Yellow);
TickTock 48:d1ce92104a1f 787 tt.background(DarkCyan);
TickTock 48:d1ce92104a1f 788 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 789
garygid 54:6ce808d0995e 790 showButton(1,0,"Request","CP Data",4,4);
TickTock 48:d1ce92104a1f 791 }
TickTock 48:d1ce92104a1f 792 }
TickTock 48:d1ce92104a1f 793
TickTock 48:d1ce92104a1f 794 //----------------
TickTock 44:6262a9fd1e56 795 // gg - hist
TickTock 47:9cc7d876dd6d 796 void cpHistogram(bool force, bool showButtons){
TickTock 44:6262a9fd1e56 797 short unsigned max, min, jv, i, bd;
TickTock 44:6262a9fd1e56 798 unsigned avg;
TickTock 44:6262a9fd1e56 799 if(force){
TickTock 44:6262a9fd1e56 800 tt.foreground(White);
TickTock 44:6262a9fd1e56 801 tt.background(Navy);
TickTock 44:6262a9fd1e56 802 tt.set_font((unsigned char*) Arial12x12_prop); // select the font
TickTock 44:6262a9fd1e56 803 max=0;
TickTock 44:6262a9fd1e56 804 min=9999;
TickTock 44:6262a9fd1e56 805 avg=0;
TickTock 44:6262a9fd1e56 806 for(i=0; i<96; i++){
TickTock 124:0d622967b764 807 bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4];
TickTock 44:6262a9fd1e56 808 avg+=bd;
TickTock 44:6262a9fd1e56 809 if(bd>max) max=bd;
TickTock 44:6262a9fd1e56 810 if(bd<min) min=bd;
TickTock 44:6262a9fd1e56 811 }
TickTock 44:6262a9fd1e56 812 avg /= 96;
TickTock 44:6262a9fd1e56 813 if(min<3713) {
TickTock 44:6262a9fd1e56 814 jv=avg-(max-avg)*1.5;
TickTock 44:6262a9fd1e56 815 } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement
TickTock 44:6262a9fd1e56 816 jv=0;
TickTock 44:6262a9fd1e56 817 }
TickTock 44:6262a9fd1e56 818
TickTock 44:6262a9fd1e56 819 //------------------
TickTock 44:6262a9fd1e56 820 tt.cls();
TickTock 44:6262a9fd1e56 821
TickTock 44:6262a9fd1e56 822 // show as histogram
TickTock 44:6262a9fd1e56 823 int xWinMin = 20;
TickTock 44:6262a9fd1e56 824 int xWinMax = 300;
TickTock 44:6262a9fd1e56 825 int yWinMin = 50;
TickTock 44:6262a9fd1e56 826 int yWinMax = 150;
TickTock 44:6262a9fd1e56 827 // draw the Histogram Frame, 2 pixels wide
TickTock 44:6262a9fd1e56 828 tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
TickTock 44:6262a9fd1e56 829 tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
TickTock 44:6262a9fd1e56 830
TickTock 44:6262a9fd1e56 831 // binning
TickTock 44:6262a9fd1e56 832 short nBin[301] ; // bins to count Min values in nBin[0], etc.
TickTock 44:6262a9fd1e56 833 int height ;
TickTock 44:6262a9fd1e56 834 int iBinIndxMax = 300 ;
TickTock 44:6262a9fd1e56 835 int iBinValMax = max - min ; // zero to N
TickTock 44:6262a9fd1e56 836 if( iBinValMax > iBinIndxMax ) iBinValMax = iBinIndxMax ;
TickTock 44:6262a9fd1e56 837
TickTock 44:6262a9fd1e56 838 // clean the bins
TickTock 44:6262a9fd1e56 839 for(int i=0; i<=iBinIndxMax; i++) {
TickTock 44:6262a9fd1e56 840 nBin[i] = 0;
TickTock 44:6262a9fd1e56 841 }
TickTock 44:6262a9fd1e56 842
TickTock 44:6262a9fd1e56 843 // do the bin counting
TickTock 44:6262a9fd1e56 844 for(int i=0; i<96; i++){
TickTock 124:0d622967b764 845 bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4] - min ;
TickTock 44:6262a9fd1e56 846 if( bd > iBinValMax ) bd = iBinValMax ;
TickTock 44:6262a9fd1e56 847 nBin[bd] ++ ;
TickTock 44:6262a9fd1e56 848 }
TickTock 44:6262a9fd1e56 849
TickTock 44:6262a9fd1e56 850 //----------------
TickTock 44:6262a9fd1e56 851 if( iBinValMax == 0 ) {
TickTock 44:6262a9fd1e56 852 // for testing
TickTock 44:6262a9fd1e56 853 min = 10 ;
TickTock 44:6262a9fd1e56 854 max = 50 ;
TickTock 44:6262a9fd1e56 855 avg = ( max + min ) / 2;
TickTock 44:6262a9fd1e56 856 iBinValMax = max - min ;
TickTock 44:6262a9fd1e56 857 for(int i=0; i<=(iBinValMax/2); i++) {
TickTock 44:6262a9fd1e56 858 nBin[i] = i ;
TickTock 44:6262a9fd1e56 859 nBin[iBinValMax-i] = i ;
TickTock 44:6262a9fd1e56 860 }
TickTock 44:6262a9fd1e56 861 }
TickTock 44:6262a9fd1e56 862
TickTock 48:d1ce92104a1f 863 // the values, for now
TickTock 124:0d622967b764 864 // BatDataBaseG4 * 7 = 280
TickTock 48:d1ce92104a1f 865 tt.locate( 0, yWinMax+40 );
TickTock 108:29b5a760adc2 866 char* sTemperatureUnit = temperatureUnit();
TickTock 108:29b5a760adc2 867 printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n",
TickTock 148:6e3b9135fad2 868 max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
TickTock 148:6e3b9135fad2 869 convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
TickTock 108:29b5a760adc2 870 //printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
TickTock 124:0d622967b764 871 // max,min,avg,jv, battData[BatDataBaseG2*7+BatDataBaseG4*7+5],battData[BatDataBaseG2*7+BatDataBaseG4*7+8], battData[BatDataBaseG2*7+BatDataBaseG4*7+11],battData[BatDataBaseG2*7+BatDataBaseG4*7+14]);
TickTock 48:d1ce92104a1f 872
TickTock 44:6262a9fd1e56 873 //---------------
TickTock 44:6262a9fd1e56 874 // show the bars
TickTock 44:6262a9fd1e56 875 int nBarWidth = 3 ;
TickTock 44:6262a9fd1e56 876 int nBarSpace = 1 ; // 1 for testing
TickTock 44:6262a9fd1e56 877
TickTock 44:6262a9fd1e56 878 int xPos = (xWinMin + xWinMax) / 2 ;
TickTock 44:6262a9fd1e56 879 xPos -= (avg-min) * (nBarWidth + nBarSpace) ;
TickTock 44:6262a9fd1e56 880
TickTock 44:6262a9fd1e56 881 for( int i=0; i<=iBinValMax; i++) {
TickTock 44:6262a9fd1e56 882 height = 4 * nBin[i] ;
TickTock 44:6262a9fd1e56 883 if( height > 100 ) height = 100 ; // clip tops
TickTock 44:6262a9fd1e56 884
TickTock 44:6262a9fd1e56 885 // if inside the window, draw the bar
TickTock 44:6262a9fd1e56 886 if( ( xPos + nBarWidth < xWinMax ) && ( xPos > xWinMin ) )
TickTock 44:6262a9fd1e56 887 tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);
TickTock 44:6262a9fd1e56 888
TickTock 44:6262a9fd1e56 889 // step to the next bar position
TickTock 44:6262a9fd1e56 890 xPos += nBarWidth + nBarSpace ;
TickTock 44:6262a9fd1e56 891 }
TickTock 44:6262a9fd1e56 892
TickTock 44:6262a9fd1e56 893 showCP=false;
TickTock 44:6262a9fd1e56 894 }
TickTock 44:6262a9fd1e56 895
TickTock 44:6262a9fd1e56 896 // handle the button
TickTock 47:9cc7d876dd6d 897 if(sMode==1&&showButtons){
TickTock 44:6262a9fd1e56 898 tt.foreground(Yellow);
TickTock 44:6262a9fd1e56 899 tt.background(DarkCyan);
TickTock 44:6262a9fd1e56 900 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 901
garygid 54:6ce808d0995e 902 showButton(1,0,"Request","CP Data",4,4);
garygid 54:6ce808d0995e 903 }
TickTock 36:dbd39c315258 904 }
TickTock 36:dbd39c315258 905
TickTock 48:d1ce92104a1f 906 //---------------
leafman 98:9f8bab96edff 907 void config(bool force, bool showButtons){
TickTock 36:dbd39c315258 908 if (force) {
TickTock 36:dbd39c315258 909 tt.background(Black);
TickTock 36:dbd39c315258 910 tt.cls();
TickTock 36:dbd39c315258 911 }
TickTock 36:dbd39c315258 912 tt.foreground(Yellow);
TickTock 36:dbd39c315258 913 tt.background(DarkCyan);
TickTock 36:dbd39c315258 914 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 915
garygid 65:821fc79cd7fe 916 //-------- top row --------
garygid 54:6ce808d0995e 917 showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
garygid 54:6ce808d0995e 918 showButton(1,0," Reset","",4,4);
TickTock 131:0d926c080a65 919 showButton(2,0," Save"," Config",4,4);
garygid 65:821fc79cd7fe 920
garygid 65:821fc79cd7fe 921 // a button to step to the next skin
garygid 65:821fc79cd7fe 922 unsigned int nextSkin = skin + 1 ;
garygid 65:821fc79cd7fe 923 if( nextSkin > maxSkin ) nextSkin = 0 ;
garygid 54:6ce808d0995e 924
garygid 65:821fc79cd7fe 925 if( nextSkin == ttSkin ) sprintf(sTemp1,"Skin TT");
garygid 65:821fc79cd7fe 926 else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG");
garygid 65:821fc79cd7fe 927 else sprintf(sTemp1,"Skin %d",nextSkin);
garygid 65:821fc79cd7fe 928
TickTock 131:0d926c080a65 929 showButton(3,0," Use",sTemp1,4,4);
TickTock 48:d1ce92104a1f 930
TickTock 48:d1ce92104a1f 931 //------- second row -----
TickTock 108:29b5a760adc2 932 if (logEn&&usbEn) {
garygid 54:6ce808d0995e 933 sprintf(sTemp1,"Disable");
TickTock 36:dbd39c315258 934 } else {
garygid 54:6ce808d0995e 935 sprintf(sTemp1,"Enable");
TickTock 36:dbd39c315258 936 }
garygid 54:6ce808d0995e 937 showButton(0,1,sTemp1,"Logging",4,4);
TickTock 48:d1ce92104a1f 938
TickTock 36:dbd39c315258 939 if (repeatPoll) {
garygid 54:6ce808d0995e 940 sprintf(sTemp1,"Disable");
TickTock 36:dbd39c315258 941 } else {
garygid 54:6ce808d0995e 942 sprintf(sTemp1,"Enable");
TickTock 36:dbd39c315258 943 }
garygid 54:6ce808d0995e 944 showButton(1,1,sTemp1,"Auto CP",4,4);
TickTock 48:d1ce92104a1f 945
TickTock 48:d1ce92104a1f 946 // add Enable/Disable Batt Log gg - yesBattLog
TickTock 48:d1ce92104a1f 947 if (yesBattLog) {
garygid 54:6ce808d0995e 948 sprintf(sTemp1,"Disable");
TickTock 48:d1ce92104a1f 949 } else {
garygid 54:6ce808d0995e 950 sprintf(sTemp1,"Enable");
TickTock 48:d1ce92104a1f 951 }
garygid 54:6ce808d0995e 952 showButton(2,1,sTemp1,"Batt Log",4,4);
garygid 87:46ac3f2519d6 953
garygid 87:46ac3f2519d6 954 // add Enable/Disable Debug - debugMode
garygid 87:46ac3f2519d6 955 if (debugMode) {
TickTock 131:0d926c080a65 956 sprintf(sTemp1," Disable");
garygid 87:46ac3f2519d6 957 } else {
TickTock 131:0d926c080a65 958 sprintf(sTemp1," Enable");
garygid 87:46ac3f2519d6 959 }
garygid 87:46ac3f2519d6 960 showButton(3,1,sTemp1," Debug",4,4);
leafman 98:9f8bab96edff 961
TickTock 140:ab3e94eb0227 962 if(brakeMon)
TickTock 140:ab3e94eb0227 963 showButton(0,2,"Disable","BrkMon",4,4);
leafman 98:9f8bab96edff 964 else
TickTock 140:ab3e94eb0227 965 showButton(0,2," Enable"," BrkMon",4,4);
leafman 98:9f8bab96edff 966
TickTock 131:0d926c080a65 967 showButton(1,2," Set"," Time",4,4);
TickTock 131:0d926c080a65 968 if (showHealth) {
TickTock 131:0d926c080a65 969 sprintf(sTemp1," Hide");
TickTock 131:0d926c080a65 970 } else {
TickTock 131:0d926c080a65 971 sprintf(sTemp1," Show");
TickTock 131:0d926c080a65 972 }
TickTock 131:0d926c080a65 973 showButton(2,2,sTemp1," Health",4,4);
leafman 98:9f8bab96edff 974 showButton(3,2,"Update","Firmware",4,4);
leafman 98:9f8bab96edff 975
TickTock 36:dbd39c315258 976 }
TickTock 36:dbd39c315258 977
TickTock 42:4533b13b297d 978 void pbScreen(bool force, bool showButtons){
TickTock 36:dbd39c315258 979 if (force) {
TickTock 36:dbd39c315258 980 tt.background(Black);
TickTock 36:dbd39c315258 981 tt.cls();
TickTock 36:dbd39c315258 982 }
TickTock 36:dbd39c315258 983 tt.foreground(Yellow);
TickTock 36:dbd39c315258 984 tt.background(DarkCyan);
TickTock 36:dbd39c315258 985 tt.set_font((unsigned char*) Arial12x12);
TickTock 36:dbd39c315258 986 if(playbackOpen){
garygid 54:6ce808d0995e 987 showButton(0,0,"Slower"," <--",4,4);
garygid 54:6ce808d0995e 988
TickTock 36:dbd39c315258 989 if(playbackEn){
garygid 54:6ce808d0995e 990 sprintf(sTemp1,"Pause");
TickTock 36:dbd39c315258 991 }else{
garygid 54:6ce808d0995e 992 sprintf(sTemp1," Run");
TickTock 36:dbd39c315258 993 }
garygid 54:6ce808d0995e 994 sprintf(sTemp2,"%4.3f ",playbackInt);
garygid 54:6ce808d0995e 995 showButton(1,0,sTemp1,sTemp2,4,4);
garygid 54:6ce808d0995e 996
garygid 54:6ce808d0995e 997 showButton(2,0,"Faster"," -->",4,4);
TickTock 36:dbd39c315258 998 }
TickTock 36:dbd39c315258 999 if(playbackOpen){
TickTock 36:dbd39c315258 1000 sprintf(sTemp1," Stop");
TickTock 36:dbd39c315258 1001 }else{
garygid 54:6ce808d0995e 1002 sprintf(sTemp1,"Start");
TickTock 36:dbd39c315258 1003 }
garygid 54:6ce808d0995e 1004 showButton(1,1,sTemp1,"Playback",4,4);
TickTock 36:dbd39c315258 1005 }
TickTock 36:dbd39c315258 1006
TickTock 42:4533b13b297d 1007 void showDateTime(bool force, bool showButtons){
TickTock 36:dbd39c315258 1008 struct tm t; // pointer to a static tm structure
TickTock 36:dbd39c315258 1009 time_t seconds ;
TickTock 36:dbd39c315258 1010 tt.foreground(Yellow);
TickTock 44:6262a9fd1e56 1011 tt.background(Black);
TickTock 36:dbd39c315258 1012 if (force) {
TickTock 36:dbd39c315258 1013 tt.cls();
TickTock 36:dbd39c315258 1014 seconds = time(NULL);
TickTock 36:dbd39c315258 1015 t = *localtime(&seconds) ;
TickTock 36:dbd39c315258 1016
TickTock 36:dbd39c315258 1017 tt.locate(10,10);
TickTock 43:e7f6f80590e3 1018 tt.set_font((unsigned char*) Arial12x12);
TickTock 36:dbd39c315258 1019 strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t);
TickTock 36:dbd39c315258 1020 printf("%s",sTemp1);
TickTock 122:138a40892a4c 1021 if(showButtons){
TickTock 36:dbd39c315258 1022 switch(dtMode){
TickTock 36:dbd39c315258 1023 case 0:
TickTock 36:dbd39c315258 1024 sprintf(sTemp1,"Year");
TickTock 36:dbd39c315258 1025 break;
TickTock 36:dbd39c315258 1026 case 1:
TickTock 36:dbd39c315258 1027 sprintf(sTemp1,"Month");
TickTock 36:dbd39c315258 1028 break;
TickTock 36:dbd39c315258 1029 case 2:
TickTock 36:dbd39c315258 1030 sprintf(sTemp1,"Day");
TickTock 36:dbd39c315258 1031 break;
TickTock 36:dbd39c315258 1032 case 3:
TickTock 36:dbd39c315258 1033 sprintf(sTemp1,"Hour");
TickTock 36:dbd39c315258 1034 break;
TickTock 36:dbd39c315258 1035 case 4:
TickTock 36:dbd39c315258 1036 sprintf(sTemp1,"Minute");
TickTock 36:dbd39c315258 1037 break;
TickTock 36:dbd39c315258 1038 case 5:
TickTock 36:dbd39c315258 1039 sprintf(sTemp1,"Second");
TickTock 36:dbd39c315258 1040 break;
TickTock 36:dbd39c315258 1041 default:
TickTock 36:dbd39c315258 1042 break;
TickTock 36:dbd39c315258 1043 }
TickTock 44:6262a9fd1e56 1044 tt.background(DarkCyan);
TickTock 66:b7476ce7a59e 1045 showButton(0,1,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1046 showButton(1,1," UP","",4,4);
garygid 54:6ce808d0995e 1047 showButton(2,1," DOWN","",4,4);
TickTock 36:dbd39c315258 1048 }
TickTock 36:dbd39c315258 1049 }
TickTock 36:dbd39c315258 1050 }
TickTock 36:dbd39c315258 1051
TickTock 50:83d5864c64a0 1052 void dteDisplay(bool force, bool showButtons, bool showMiles){
TickTock 66:b7476ce7a59e 1053 unsigned short i,x,y,lx,ly,gids,radius,color,r,t;
TickTock 79:68f0dd8d1f19 1054 unsigned char toVal;
TickTock 50:83d5864c64a0 1055 static unsigned short lgids=0;
TickTock 50:83d5864c64a0 1056 static unsigned char leff[39]={0};
TickTock 50:83d5864c64a0 1057 CANMessage msg;
TickTock 66:b7476ce7a59e 1058 unsigned long targetBraking, regenBraking, temp;
TickTock 73:62ee8eae3a84 1059 static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
TickTock 66:b7476ce7a59e 1060 static unsigned char lr=0, lt=0;
TickTock 50:83d5864c64a0 1061
TickTock 50:83d5864c64a0 1062 msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
TickTock 50:83d5864c64a0 1063 gids = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 50:83d5864c64a0 1064 if(gids==0){
TickTock 83:52b1f330a62d 1065 gids=281; // Display new, fully charged capacity until real data obtained
TickTock 50:83d5864c64a0 1066 }
TickTock 50:83d5864c64a0 1067
TickTock 37:fea2c1d52c5f 1068 tt.background(Navy);
TickTock 49:a3d2c5bb3cfa 1069 tt.foreground(Yellow);
TickTock 52:d5385fbf4ea1 1070 if(force){
TickTock 97:a25940fd7b5b 1071 tt.set_font((unsigned char*) Arial12x12);
TickTock 52:d5385fbf4ea1 1072 tt.cls();
TickTock 49:a3d2c5bb3cfa 1073 x=50+0*6;
TickTock 52:d5385fbf4ea1 1074 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1075 printf("sec\n");
TickTock 50:83d5864c64a0 1076 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1077 x=50+9*6;
TickTock 52:d5385fbf4ea1 1078 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1079 printf("min\n");
TickTock 50:83d5864c64a0 1080 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1081 x=50+18*6;
TickTock 52:d5385fbf4ea1 1082 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1083 printf("hour\n");
TickTock 83:52b1f330a62d 1084 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1085 x=50+25*6;
TickTock 52:d5385fbf4ea1 1086 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1087 printf("day\n");
TickTock 50:83d5864c64a0 1088 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1089 x=50+32*6;
TickTock 52:d5385fbf4ea1 1090 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1091 printf("mon\n");
TickTock 50:83d5864c64a0 1092 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1093 x=50+38*6;
TickTock 66:b7476ce7a59e 1094 //tt.locate(x-10,226);
TickTock 66:b7476ce7a59e 1095 //printf("year\n");
TickTock 66:b7476ce7a59e 1096 //tt.line(x,10,x,220,DarkGrey);
TickTock 97:a25940fd7b5b 1097 toVal=33;
TickTock 83:52b1f330a62d 1098 } else {
TickTock 97:a25940fd7b5b 1099 toVal=24;// no need to constantly update the long tc values
TickTock 50:83d5864c64a0 1100 }
TickTock 83:52b1f330a62d 1101 if(force||lgids!=gids){ // update Y axis when kWh changes
TickTock 97:a25940fd7b5b 1102 tt.set_font((unsigned char*) Arial24x23);
TickTock 97:a25940fd7b5b 1103 //for(i=0;i<10;i++){
TickTock 97:a25940fd7b5b 1104 //y=200-i*20;
TickTock 131:0d926c080a65 1105 for(i=2;i<7;i++){
TickTock 131:0d926c080a65 1106 y=200-(i-2)*40;
TickTock 97:a25940fd7b5b 1107 tt.locate(0,y-8);
TickTock 83:52b1f330a62d 1108 if (showMiles){
leafman 98:9f8bab96edff 1109 printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support
TickTock 83:52b1f330a62d 1110 }else{
TickTock 83:52b1f330a62d 1111 printf("%d.0\n",i);
TickTock 50:83d5864c64a0 1112 }
TickTock 97:a25940fd7b5b 1113 tt.line(48,y,toVal*6+56,y,DarkGrey);
TickTock 83:52b1f330a62d 1114 }
TickTock 50:83d5864c64a0 1115 lgids=gids;
TickTock 50:83d5864c64a0 1116 }
TickTock 121:553faf139a20 1117 if(tock||force){
TickTock 131:0d926c080a65 1118 for(i=2;i<7;i++){
TickTock 131:0d926c080a65 1119 y=200-(i-2)*40;
TickTock 83:52b1f330a62d 1120 tt.line(40,y,158,y,DarkGrey);
TickTock 50:83d5864c64a0 1121 }
TickTock 50:83d5864c64a0 1122
TickTock 50:83d5864c64a0 1123 x=50+0*6;
TickTock 50:83d5864c64a0 1124 tt.line(x,10,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1125 x=50+9*6;
TickTock 50:83d5864c64a0 1126 tt.line(x,10,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1127 x=50+18*6;
TickTock 50:83d5864c64a0 1128 tt.line(x,10,x,220,DarkGrey);
TickTock 83:52b1f330a62d 1129 //x=50+25*6;
TickTock 83:52b1f330a62d 1130 //tt.line(x,60,x,220,DarkGrey);
TickTock 83:52b1f330a62d 1131 //x=50+32*6;
TickTock 83:52b1f330a62d 1132 //tt.line(x,60,x,220,DarkGrey);
TickTock 66:b7476ce7a59e 1133 //x=50+38*6;
TickTock 66:b7476ce7a59e 1134 //tt.line(x,60,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1135 tt.set_font((unsigned char*) SCProSB31x55);
TickTock 50:83d5864c64a0 1136 tt.foreground(Green);
TickTock 50:83d5864c64a0 1137 if (showMiles){
TickTock 149:e9739523109f 1138 //Totest:convert from 25C to current ambient temperature
TickTock 93:c2402e8cd0e2 1139 float miles = mpkWh[dtePeriod]*((float)(gids-5)*.075);
leafman 98:9f8bab96edff 1140 miles = convertDistance(miles); // LM - Metric support
TickTock 93:c2402e8cd0e2 1141 // Right justify
TickTock 94:c3a14b3975d6 1142 if (miles>99.9){ //space=18; num=31; . = 23
TickTock 94:c3a14b3975d6 1143 tt.locate(161,8);
TickTock 94:c3a14b3975d6 1144 printf("%4.1f\n",miles);
TickTock 93:c2402e8cd0e2 1145 } else if (miles>9.9){
TickTock 94:c3a14b3975d6 1146 tt.locate(156,8);
TickTock 94:c3a14b3975d6 1147 printf(" %3.1f\n",miles);
TickTock 93:c2402e8cd0e2 1148 } else {
TickTock 94:c3a14b3975d6 1149 tt.locate(151,8);
TickTock 94:c3a14b3975d6 1150 printf(" %2.1f\n",miles);
TickTock 93:c2402e8cd0e2 1151 }
TickTock 97:a25940fd7b5b 1152 tt.foreground(Cyan);
TickTock 97:a25940fd7b5b 1153 tt.set_font((unsigned char*) Arial24x23);
TickTock 97:a25940fd7b5b 1154 tt.locate(198,70);
TickTock 149:e9739523109f 1155 //Totest:convert from 25C to current ambient temperature
TickTock 97:a25940fd7b5b 1156 printf("%3.1f \n",mpkWh[dtePeriod]);
TickTock 50:83d5864c64a0 1157 } else {
TickTock 97:a25940fd7b5b 1158 tt.locate(200,10);
TickTock 149:e9739523109f 1159 //Totest:convert from 25C to current ambient temperature
TickTock 66:b7476ce7a59e 1160 printf("%3.1f \n",mpkWh[dtePeriod]);
TickTock 144:b0c9d30dd346 1161 tt.foreground(Cyan);
TickTock 144:b0c9d30dd346 1162 tt.set_font((unsigned char*) Arial24x23);
TickTock 144:b0c9d30dd346 1163 tt.locate(222,70);
TickTock 144:b0c9d30dd346 1164 printf("%2.1f \n",curEff);
TickTock 50:83d5864c64a0 1165 }
TickTock 49:a3d2c5bb3cfa 1166 lx=50;
TickTock 97:a25940fd7b5b 1167 ly=mpkWh[0]*40;
TickTock 50:83d5864c64a0 1168 if(dtePeriod==0){
TickTock 52:d5385fbf4ea1 1169 radius=6;
TickTock 79:68f0dd8d1f19 1170 color=Yellow;
TickTock 50:83d5864c64a0 1171 }else{
TickTock 50:83d5864c64a0 1172 radius=2;
TickTock 50:83d5864c64a0 1173 color=Green;
TickTock 50:83d5864c64a0 1174 }
TickTock 131:0d926c080a65 1175 if(ly<60){
TickTock 97:a25940fd7b5b 1176 ly=220;
TickTock 97:a25940fd7b5b 1177 color=Red;
TickTock 131:0d926c080a65 1178 }else if(ly<280) {
TickTock 131:0d926c080a65 1179 ly=280-ly;
TickTock 97:a25940fd7b5b 1180 }else{
TickTock 97:a25940fd7b5b 1181 ly=0;
TickTock 97:a25940fd7b5b 1182 }
TickTock 50:83d5864c64a0 1183 tt.fillcircle(lx,leff[0],radius,Navy);
TickTock 50:83d5864c64a0 1184 tt.fillcircle(lx,ly,radius,color);
TickTock 49:a3d2c5bb3cfa 1185
TickTock 79:68f0dd8d1f19 1186 for(i=1;i<toVal;i++){
TickTock 49:a3d2c5bb3cfa 1187 x=50+i*6;
TickTock 97:a25940fd7b5b 1188 y=mpkWh[i]*40;
TickTock 50:83d5864c64a0 1189 if(i==dtePeriod){
TickTock 79:68f0dd8d1f19 1190 radius=6;
TickTock 79:68f0dd8d1f19 1191 color=Yellow;
TickTock 50:83d5864c64a0 1192 }else{
TickTock 50:83d5864c64a0 1193 radius=2;
TickTock 50:83d5864c64a0 1194 color=Green;
TickTock 50:83d5864c64a0 1195 }
TickTock 131:0d926c080a65 1196 if(y<60){
TickTock 97:a25940fd7b5b 1197 y=220;
TickTock 97:a25940fd7b5b 1198 color=Red;
TickTock 131:0d926c080a65 1199 }else if(y<280) {
TickTock 131:0d926c080a65 1200 y=280-y;
TickTock 97:a25940fd7b5b 1201 }else{
TickTock 97:a25940fd7b5b 1202 y=0;
TickTock 97:a25940fd7b5b 1203 }
TickTock 50:83d5864c64a0 1204 tt.fillcircle(x,leff[i],radius,Navy);
TickTock 50:83d5864c64a0 1205 tt.line(x-6,leff[i-1],x,leff[i],Navy);
TickTock 50:83d5864c64a0 1206 leff[i-1]=ly;
TickTock 52:d5385fbf4ea1 1207 if(y>0){
TickTock 52:d5385fbf4ea1 1208 tt.fillcircle(x,y,radius,color);
TickTock 52:d5385fbf4ea1 1209 }
TickTock 49:a3d2c5bb3cfa 1210 tt.line(lx,ly,x,y,White);
TickTock 49:a3d2c5bb3cfa 1211 lx=x;
TickTock 49:a3d2c5bb3cfa 1212 ly=y;
TickTock 49:a3d2c5bb3cfa 1213 }
TickTock 50:83d5864c64a0 1214 leff[i-1]=y;
TickTock 37:fea2c1d52c5f 1215 }
TickTock 66:b7476ce7a59e 1216
TickTock 66:b7476ce7a59e 1217 msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen
TickTock 66:b7476ce7a59e 1218 regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
TickTock 66:b7476ce7a59e 1219 targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
TickTock 113:f388b4505463 1220 msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode
TickTock 113:f388b4505463 1221 if (msg.data[0]==0x18) { // In Neutral
TickTock 108:29b5a760adc2 1222 regenBraking = 0; // No regen when in Neutral
TickTock 108:29b5a760adc2 1223 }
TickTock 73:62ee8eae3a84 1224
TickTock 73:62ee8eae3a84 1225 if (targetBraking<2045){
TickTock 73:62ee8eae3a84 1226 if ((targetBraking>50)&&(regenBraking>50)){
TickTock 73:62ee8eae3a84 1227 temp = targetBraking;
TickTock 73:62ee8eae3a84 1228 temp *= 1000;
TickTock 73:62ee8eae3a84 1229 temp /= regenBraking;
TickTock 73:62ee8eae3a84 1230 if (temp<tardivreg_x1000) tardivreg_x1000=temp;
TickTock 73:62ee8eae3a84 1231 }
TickTock 73:62ee8eae3a84 1232 if (targetBraking>maxTarget) maxTarget=targetBraking;
TickTock 73:62ee8eae3a84 1233 if (regenBraking>maxRegen) maxRegen=regenBraking;
TickTock 73:62ee8eae3a84 1234
TickTock 66:b7476ce7a59e 1235 temp = targetBraking;
TickTock 73:62ee8eae3a84 1236 temp *=200;
TickTock 73:62ee8eae3a84 1237 temp /= maxTarget;
TickTock 73:62ee8eae3a84 1238 t = (char) temp;
TickTock 73:62ee8eae3a84 1239 if (t>175) t=175;
TickTock 73:62ee8eae3a84 1240 temp = regenBraking;
TickTock 73:62ee8eae3a84 1241 temp *= tardivreg_x1000;
TickTock 73:62ee8eae3a84 1242 temp /= maxTarget;
TickTock 73:62ee8eae3a84 1243 temp /= 5; // 1000/200=5
TickTock 73:62ee8eae3a84 1244 r = (char) temp;
TickTock 73:62ee8eae3a84 1245 if (r>175) r=175;
TickTock 73:62ee8eae3a84 1246 if (r>t) t=r; //Should never happen
TickTock 73:62ee8eae3a84 1247 if(lr!=r||lt!=t){
TickTock 73:62ee8eae3a84 1248 tt.fillrect(264,64,310,239-t,Navy);
TickTock 73:62ee8eae3a84 1249 tt.fillrect(264,239-t,310,239-r,Red);
TickTock 73:62ee8eae3a84 1250 tt.fillrect(264,239-r,310,239,Green);
TickTock 73:62ee8eae3a84 1251 }
TickTock 73:62ee8eae3a84 1252 lt=t;
TickTock 73:62ee8eae3a84 1253 lr=r;
TickTock 66:b7476ce7a59e 1254 }
TickTock 37:fea2c1d52c5f 1255 }
TickTock 37:fea2c1d52c5f 1256
TickTock 148:6e3b9135fad2 1257 void debugDisplay (bool force, bool showButtons){
TickTock 148:6e3b9135fad2 1258 static unsigned short maxPS=0;
TickTock 148:6e3b9135fad2 1259 unsigned char i, uData[8];
TickTock 148:6e3b9135fad2 1260 CANMessage msg;
TickTock 148:6e3b9135fad2 1261
TickTock 148:6e3b9135fad2 1262 for (i=0; i<8; i++){
TickTock 148:6e3b9135fad2 1263 msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]]; //Get ambient
TickTock 148:6e3b9135fad2 1264 uData[i] = msg.data[(uMsgId[i]&0x000f)];
TickTock 148:6e3b9135fad2 1265 }
TickTock 148:6e3b9135fad2 1266 tt.set_font((unsigned char*) Arial24x23);
TickTock 148:6e3b9135fad2 1267 tt.foreground(Yellow);
TickTock 148:6e3b9135fad2 1268 tt.background(Navy);
TickTock 148:6e3b9135fad2 1269 if(force){
TickTock 148:6e3b9135fad2 1270 tt.cls();
TickTock 148:6e3b9135fad2 1271 }
TickTock 148:6e3b9135fad2 1272 if(pointerSep>maxPS){maxPS=pointerSep;}
TickTock 148:6e3b9135fad2 1273 tt.locate(10,10);
TickTock 149:e9739523109f 1274 //printf("%3d sep %3d max\n",pointerSep,maxPS);
TickTock 149:e9739523109f 1275 printf("%f %4.3f \n", ambient_F, airDrag(ambient_F));
TickTock 148:6e3b9135fad2 1276 tt.locate(10,40);
TickTock 148:6e3b9135fad2 1277 printf("%4.2fV %4.2fV \n",accV,accV2);
TickTock 148:6e3b9135fad2 1278 for (i=0; i<4; i++){
TickTock 148:6e3b9135fad2 1279 tt.locate(10,90+i*30);
TickTock 148:6e3b9135fad2 1280 printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
TickTock 148:6e3b9135fad2 1281 }
TickTock 148:6e3b9135fad2 1282 }
TickTock 148:6e3b9135fad2 1283
TickTock 36:dbd39c315258 1284 void updateDisplay(char display){
TickTock 122:138a40892a4c 1285 bool changed,showButtons;
TickTock 36:dbd39c315258 1286 changed = dMode[display]!=lastDMode[display];
TickTock 122:138a40892a4c 1287 showButtons = (display==whichTouched)&&(sMode==1);
TickTock 36:dbd39c315258 1288 tt.set_display(display);
TickTock 36:dbd39c315258 1289 switch (dMode[display]) {
TickTock 36:dbd39c315258 1290 case logScreen:
TickTock 122:138a40892a4c 1291 printLog(changed,showButtons);
TickTock 36:dbd39c315258 1292 break;
TickTock 41:8d4609ea7259 1293 case mainScreen:
TickTock 122:138a40892a4c 1294 mainDisplay(changed,showButtons);
TickTock 36:dbd39c315258 1295 break;
TickTock 36:dbd39c315258 1296 case brakeScreen:
TickTock 122:138a40892a4c 1297 braking(changed,showButtons);
TickTock 36:dbd39c315258 1298 break;
TickTock 41:8d4609ea7259 1299 case dteScreen:
TickTock 122:138a40892a4c 1300 dteDisplay(changed,showButtons,true);
TickTock 37:fea2c1d52c5f 1301 break;
TickTock 50:83d5864c64a0 1302 case effScreen:
TickTock 122:138a40892a4c 1303 dteDisplay(changed,showButtons,false);
TickTock 50:83d5864c64a0 1304 break;
TickTock 50:83d5864c64a0 1305 case monitorScreen:
TickTock 122:138a40892a4c 1306 printLast(changed,showButtons);
TickTock 36:dbd39c315258 1307 break;
TickTock 36:dbd39c315258 1308 case changedScreen:
TickTock 122:138a40892a4c 1309 printChanged(changed,showButtons);
TickTock 36:dbd39c315258 1310 break;
TickTock 36:dbd39c315258 1311 case cpScreen:
TickTock 122:138a40892a4c 1312 cpData(changed||showCP,showButtons);
TickTock 36:dbd39c315258 1313 break;
leafman 98:9f8bab96edff 1314 case configScreen:
TickTock 122:138a40892a4c 1315 config(changed,showButtons);
TickTock 36:dbd39c315258 1316 break;
TickTock 38:155ec32c5e91 1317 case playbackScreen:
TickTock 122:138a40892a4c 1318 pbScreen(changed,showButtons);
TickTock 36:dbd39c315258 1319 break;
TickTock 36:dbd39c315258 1320 case dateScreen:
TickTock 122:138a40892a4c 1321 showDateTime(changed,showButtons);
TickTock 36:dbd39c315258 1322 break;
TickTock 44:6262a9fd1e56 1323 case cpHistScreen: // gg - hist
TickTock 122:138a40892a4c 1324 cpHistogram(changed||showCP,showButtons);
TickTock 44:6262a9fd1e56 1325 break;
TickTock 48:d1ce92104a1f 1326 case cpBarScreen: // gg - cpbars
TickTock 122:138a40892a4c 1327 cpBarPlot(changed||showCP,showButtons);
TickTock 48:d1ce92104a1f 1328 break;
garygid 67:2022fce701d0 1329 case indexScreen:
TickTock 122:138a40892a4c 1330 showIndex(changed,showButtons);
garygid 67:2022fce701d0 1331 break;
TickTock 107:e9be732c1ad4 1332 case tripScreen:
TickTock 122:138a40892a4c 1333 tripDisplay(changed,showButtons);
TickTock 107:e9be732c1ad4 1334 break;
TickTock 118:02010b18efdc 1335 case healthScreen:
TickTock 122:138a40892a4c 1336 healthDisplay(changed,showButtons);
garygid 67:2022fce701d0 1337 break;
TickTock 148:6e3b9135fad2 1338 case debugScreen:
TickTock 148:6e3b9135fad2 1339 debugDisplay(changed,showButtons);
TickTock 148:6e3b9135fad2 1340 break;
TickTock 36:dbd39c315258 1341 default:
TickTock 43:e7f6f80590e3 1342 if (changed){
TickTock 43:e7f6f80590e3 1343 tt.background(Black);
TickTock 43:e7f6f80590e3 1344 tt.cls();
TickTock 43:e7f6f80590e3 1345 }
TickTock 36:dbd39c315258 1346 break;
TickTock 36:dbd39c315258 1347 }
TickTock 36:dbd39c315258 1348 lastDMode[display]=dMode[display];
TickTock 36:dbd39c315258 1349
TickTock 42:4533b13b297d 1350 if(display==whichTouched){
TickTock 42:4533b13b297d 1351 switch (sMode) {
TickTock 42:4533b13b297d 1352 case 1: // Select screens
TickTock 42:4533b13b297d 1353 tt.foreground(Yellow);
TickTock 42:4533b13b297d 1354 tt.background(DarkCyan);
garygid 54:6ce808d0995e 1355 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 1356
garygid 54:6ce808d0995e 1357 showButton(0,tNavRow," <-Prev","",4,4); // gg - 4x4
garygid 67:2022fce701d0 1358 // col 1 see below
garygid 67:2022fce701d0 1359 showButton(2,tNavRow," Go To"," Index",4,4); // gg - index
garygid 54:6ce808d0995e 1360 showButton(3,tNavRow," Next->","",4,4); // gg - move next
garygid 54:6ce808d0995e 1361
garygid 67:2022fce701d0 1362 // col 1 in Nav row
TickTock 42:4533b13b297d 1363 switch (dMode[display]) {
TickTock 44:6262a9fd1e56 1364 case offScreen:
garygid 54:6ce808d0995e 1365 sprintf(sTemp2," Off");
TickTock 42:4533b13b297d 1366 break;
TickTock 44:6262a9fd1e56 1367 case logScreen:
garygid 54:6ce808d0995e 1368 sprintf(sTemp2," Log");
TickTock 42:4533b13b297d 1369 break;
TickTock 44:6262a9fd1e56 1370 case mainScreen:
garygid 54:6ce808d0995e 1371 sprintf(sTemp2," Main");
TickTock 42:4533b13b297d 1372 break;
TickTock 44:6262a9fd1e56 1373 case brakeScreen:
garygid 54:6ce808d0995e 1374 sprintf(sTemp2,"Braking");
TickTock 42:4533b13b297d 1375 break;
TickTock 44:6262a9fd1e56 1376 case dteScreen:
garygid 54:6ce808d0995e 1377 sprintf(sTemp2," DTE");
TickTock 42:4533b13b297d 1378 break;
TickTock 50:83d5864c64a0 1379 case effScreen:
garygid 54:6ce808d0995e 1380 sprintf(sTemp2," Eff");
TickTock 50:83d5864c64a0 1381 break;
TickTock 44:6262a9fd1e56 1382 case monitorScreen:
garygid 54:6ce808d0995e 1383 sprintf(sTemp2," Monitor");
TickTock 42:4533b13b297d 1384 break;
TickTock 44:6262a9fd1e56 1385 case changedScreen:
garygid 54:6ce808d0995e 1386 sprintf(sTemp2,"DeltaMon");
TickTock 42:4533b13b297d 1387 break;
TickTock 44:6262a9fd1e56 1388 case cpScreen:
garygid 67:2022fce701d0 1389 sprintf(sTemp2,"CP Data");
TickTock 42:4533b13b297d 1390 break;
leafman 98:9f8bab96edff 1391 case configScreen:
garygid 54:6ce808d0995e 1392 sprintf(sTemp2," Config");
leafman 98:9f8bab96edff 1393 break;
TickTock 44:6262a9fd1e56 1394 case playbackScreen:
garygid 54:6ce808d0995e 1395 sprintf(sTemp2,"Playback");
TickTock 42:4533b13b297d 1396 break;
TickTock 44:6262a9fd1e56 1397 case dateScreen:
garygid 54:6ce808d0995e 1398 sprintf(sTemp2,"Set Time");
TickTock 42:4533b13b297d 1399 break;
TickTock 44:6262a9fd1e56 1400 case cpHistScreen: // gg - hist
garygid 54:6ce808d0995e 1401 sprintf(sTemp2,"CP Hist");
TickTock 44:6262a9fd1e56 1402 break;
TickTock 48:d1ce92104a1f 1403 case cpBarScreen: // gg - cpbars
garygid 54:6ce808d0995e 1404 sprintf(sTemp2,"CP Bars");
TickTock 48:d1ce92104a1f 1405 break;
TickTock 107:e9be732c1ad4 1406 case tripScreen:
TickTock 107:e9be732c1ad4 1407 sprintf(sTemp2," Trip");
TickTock 107:e9be732c1ad4 1408 break;
TickTock 118:02010b18efdc 1409 case healthScreen:
TickTock 118:02010b18efdc 1410 sprintf(sTemp2,"Health");
TickTock 118:02010b18efdc 1411 break;
garygid 67:2022fce701d0 1412 case indexScreen: // gg - index
garygid 67:2022fce701d0 1413 sprintf(sTemp2," Index");
garygid 67:2022fce701d0 1414 break;
TickTock 42:4533b13b297d 1415 }
garygid 54:6ce808d0995e 1416 showButton(1,tNavRow," Select",sTemp2,4,4);
garygid 54:6ce808d0995e 1417
TickTock 42:4533b13b297d 1418 wait_ms(100); // pause a moment to reduce flicker
TickTock 42:4533b13b297d 1419 break;
garygid 54:6ce808d0995e 1420
TickTock 42:4533b13b297d 1421 case 2: // numpad
TickTock 42:4533b13b297d 1422 tt.foreground(Yellow);
TickTock 42:4533b13b297d 1423 tt.background(DarkCyan);
TickTock 42:4533b13b297d 1424 tt.set_font((unsigned char*) Arial24x23);
garygid 54:6ce808d0995e 1425
garygid 54:6ce808d0995e 1426 sprintf(sTemp2,"");
garygid 54:6ce808d0995e 1427 showButton(0,0," 1",sTemp2,4,4);
garygid 54:6ce808d0995e 1428 showButton(1,0," 2",sTemp2,4,4);
garygid 54:6ce808d0995e 1429 showButton(2,0," 3",sTemp2,4,4);
garygid 54:6ce808d0995e 1430 showButton(0,1," 4",sTemp2,4,4);
garygid 54:6ce808d0995e 1431 showButton(1,1," 5",sTemp2,4,4);
garygid 54:6ce808d0995e 1432 showButton(2,1," 6",sTemp2,4,4);
garygid 54:6ce808d0995e 1433 showButton(0,2," 7",sTemp2,4,4);
garygid 54:6ce808d0995e 1434 showButton(1,2," 8",sTemp2,4,4);
garygid 54:6ce808d0995e 1435 showButton(2,2," 9",sTemp2,4,4);
garygid 54:6ce808d0995e 1436 showButton(1,3," 0",sTemp2,4,4);
garygid 54:6ce808d0995e 1437
garygid 54:6ce808d0995e 1438 showButton(0,3,"<--",sTemp2,4,4);
garygid 54:6ce808d0995e 1439 showButton(2,3,"-->",sTemp2,4,4);
garygid 54:6ce808d0995e 1440 showButton(3,3,"return",sTemp2,4,4);
TickTock 42:4533b13b297d 1441 case 3:
TickTock 42:4533b13b297d 1442 break;
TickTock 42:4533b13b297d 1443 default:
TickTock 42:4533b13b297d 1444 break;
TickTock 42:4533b13b297d 1445 }
TickTock 36:dbd39c315258 1446 }
TickTock 121:553faf139a20 1447 tock=false;
TickTock 121:553faf139a20 1448 } // updateDisplay
TickTock 36:dbd39c315258 1449
garygid 58:4d06288d75a2 1450 //---------------------
garygid 58:4d06288d75a2 1451 // gg - highlight
TickTock 62:ffd15edb5431 1452 void highlightButton(unsigned char column, unsigned char row, unsigned char tScn, unsigned char columns, unsigned char rows){
TickTock 62:ffd15edb5431 1453
garygid 58:4d06288d75a2 1454 unsigned short x1,x2,y1,y2;
garygid 58:4d06288d75a2 1455
garygid 58:4d06288d75a2 1456 x1=column*(320/columns)+btnGap/2;
garygid 58:4d06288d75a2 1457 x2=(column+1)*(320/columns)-btnGap/2;
garygid 58:4d06288d75a2 1458 y1=row*(240/rows)+btnGap/2;
garygid 58:4d06288d75a2 1459 y2=(row+1)*(240/rows)-btnGap/2;
garygid 65:821fc79cd7fe 1460
garygid 65:821fc79cd7fe 1461 tt.set_display(tScn);
garygid 65:821fc79cd7fe 1462
garygid 65:821fc79cd7fe 1463 if( skin == ggSkin ){
garygid 65:821fc79cd7fe 1464 // paint the whole button box, for a better visual effect
garygid 65:821fc79cd7fe 1465 // especially on a screen with a yellow background
garygid 65:821fc79cd7fe 1466 if( tScn == 0 )
garygid 65:821fc79cd7fe 1467 tt.fillrect(x1,y1,x2,y2,White); // DarkCyan);
garygid 65:821fc79cd7fe 1468 else
garygid 65:821fc79cd7fe 1469 tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan);
TickTock 66:b7476ce7a59e 1470 } else {
TickTock 66:b7476ce7a59e 1471 tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan);
garygid 65:821fc79cd7fe 1472 }
garygid 58:4d06288d75a2 1473
garygid 58:4d06288d75a2 1474 // paint the outer pixel as a yellow frame
garygid 58:4d06288d75a2 1475 tt.rect(x1,y1,x2,y2,Yellow) ; // DarkCyan);
garygid 58:4d06288d75a2 1476 }
garygid 58:4d06288d75a2 1477
garygid 58:4d06288d75a2 1478 //---------------------
TickTock 36:dbd39c315258 1479 void showButton(unsigned char column, unsigned char row, char * text1, char * text2, unsigned char columns, unsigned char rows){
TickTock 36:dbd39c315258 1480 unsigned short x1,x2,y1,y2;
garygid 54:6ce808d0995e 1481
TickTock 36:dbd39c315258 1482 x1=column*(320/columns)+btnGap/2;
TickTock 36:dbd39c315258 1483 x2=(column+1)*(320/columns)-btnGap/2;
TickTock 36:dbd39c315258 1484 y1=row*(240/rows)+btnGap/2;
TickTock 36:dbd39c315258 1485 y2=(row+1)*(240/rows)-btnGap/2;
TickTock 36:dbd39c315258 1486 tt.fillrect(x1,y1,x2,y2,DarkCyan);
garygid 54:6ce808d0995e 1487
garygid 54:6ce808d0995e 1488 // adapt formatting of text to the smaller 4x4 box
garygid 54:6ce808d0995e 1489 tt.locate(x1+btnGap/2,y1+btnGap); // gg - 4x4
TickTock 36:dbd39c315258 1490 printf("%s\n",text1);
garygid 54:6ce808d0995e 1491
garygid 54:6ce808d0995e 1492 tt.locate(x1+btnGap/2,y1+btnGap+20);
TickTock 36:dbd39c315258 1493 printf("%s\n",text2);
TickTock 36:dbd39c315258 1494 }
garygid 54:6ce808d0995e 1495
TickTock 13:62e0f7f39ff5 1496
leafman 98:9f8bab96edff 1497 //The temps are stored as metric, distances as imperial... I'm assuming the input based on that - LM
TickTock 148:6e3b9135fad2 1498 float convertC(float input)
leafman 98:9f8bab96edff 1499 {
leafman 98:9f8bab96edff 1500 if (!metric) {
TickTock 149:e9739523109f 1501 //convert C to F!
leafman 98:9f8bab96edff 1502 float output = input *1.8f;
leafman 98:9f8bab96edff 1503 output += 32.0f;
leafman 98:9f8bab96edff 1504 return output;
TickTock 23:cd03f9c3395e 1505 }
leafman 98:9f8bab96edff 1506 return input;
leafman 98:9f8bab96edff 1507 }
TickTock 148:6e3b9135fad2 1508
TickTock 148:6e3b9135fad2 1509 float convertF(float input)
TickTock 148:6e3b9135fad2 1510 {
TickTock 148:6e3b9135fad2 1511 if (metric) {
TickTock 149:e9739523109f 1512 //convert F to C!
TickTock 148:6e3b9135fad2 1513 float output = input -32.0f;
TickTock 148:6e3b9135fad2 1514 output /= 1.8f;
TickTock 148:6e3b9135fad2 1515 return output;
TickTock 148:6e3b9135fad2 1516 }
TickTock 148:6e3b9135fad2 1517 return input;
TickTock 148:6e3b9135fad2 1518 }
leafman 98:9f8bab96edff 1519 float convertDistance(float input)
leafman 98:9f8bab96edff 1520 {
leafman 98:9f8bab96edff 1521 if (metric) {
leafman 98:9f8bab96edff 1522 return input / 0.62137f;
TickTock 13:62e0f7f39ff5 1523 }
leafman 98:9f8bab96edff 1524 return input;
leafman 98:9f8bab96edff 1525 }
leafman 98:9f8bab96edff 1526 char* distanceUnit()
leafman 98:9f8bab96edff 1527 {
leafman 98:9f8bab96edff 1528 if(metric)
leafman 98:9f8bab96edff 1529 return "km";
leafman 98:9f8bab96edff 1530 return "mi";
leafman 98:9f8bab96edff 1531 }
leafman 98:9f8bab96edff 1532 char* temperatureUnit()
leafman 98:9f8bab96edff 1533 {
leafman 98:9f8bab96edff 1534 if(metric)
leafman 98:9f8bab96edff 1535 return "C";
leafman 98:9f8bab96edff 1536 return "F";
leafman 98:9f8bab96edff 1537 }
TickTock 149:e9739523109f 1538