Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: displayModes.cpp
- Revision:
- 44:6262a9fd1e56
- Parent:
- 43:e7f6f80590e3
- Child:
- 47:9cc7d876dd6d
--- a/displayModes.cpp Tue Apr 02 06:32:25 2013 +0000
+++ b/displayModes.cpp Tue Apr 02 06:53:50 2013 +0000
@@ -52,10 +52,11 @@
sprintf(sTemp1,"<up>");
sprintf(sTemp2,"");
showButton(0,0,sTemp1,sTemp2,3,3);
- sprintf(sTemp1,"Reset");
+ sprintf(sTemp1," <down>");
+ showButton(2,0,sTemp1,sTemp2,3,3);
+ sprintf(sTemp1," Reset");
+ sprintf(sTemp2," Baseline");
showButton(1,0,sTemp1,sTemp2,3,3);
- sprintf(sTemp1,"<down>");
- showButton(2,0,sTemp1,sTemp2,3,3);
}
}
@@ -78,7 +79,7 @@
void mainDisplay (bool force, bool showButtons){
unsigned short gids, SOC, packV;
static unsigned short lgids=0, lSOC=0, lpackV=0;
- static float lmpkWh=0, laccV=0;;
+ static float lkW=0, laccV=0;;
CANMessage msg;
msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
@@ -94,9 +95,9 @@
if(force) tt.cls();
if(force||gids!=lgids){
tt.locate(10,10);
- printf("%4d gids\n",gids);
+ printf("%4d gids \n",gids);
tt.locate(20,40);
- printf("%4.1f kWh\n",(float)gids*0.08);
+ printf("%4.1f kWh \n",(float)gids*0.08);
tt.set_font((unsigned char*) SCProSB31x55);
tt.foreground(Green);
tt.locate(60,96);
@@ -107,7 +108,7 @@
}
if(force||SOC!=lSOC){
tt.locate(200,10);
- printf("%4.1f%s\n",(float)SOC/10,"%");
+ printf("%4.1f%s\n",(float)SOC/10,"% ");
lSOC=SOC;
}
if(force||packV!=lpackV){
@@ -120,10 +121,10 @@
printf("%3.1fV \n",accV);
laccV=accV;
}
- if(force||mpkWh!=lmpkWh){
+ if(force||kW!=lkW){
tt.locate(180,40);
- printf("%3.2fkW \n",mpkWh); //kW for now
- lmpkWh=mpkWh;
+ printf("%3.2fkW \n",kW);
+ lkW=kW;
}
}
@@ -286,8 +287,114 @@
tt.foreground(Yellow);
tt.background(DarkCyan);
tt.set_font((unsigned char*) Arial12x12);
- sprintf(sTemp1,"Request");
- sprintf(sTemp2,"CP data");
+ sprintf(sTemp1," Request");
+ sprintf(sTemp2," CP data");
+ showButton(1,0,sTemp1,sTemp2,3,3);
+ }
+}
+
+//----------------
+// gg - hist
+void cpHistogram(bool force){
+ short unsigned max, min, jv, i, bd;
+ unsigned avg;
+ if(force){
+ tt.foreground(White);
+ tt.background(Navy);
+ tt.set_font((unsigned char*) Arial12x12_prop); // select the font
+ max=0;
+ min=9999;
+ avg=0;
+ for(i=0; i<96; i++){
+ bd=(battData[i*2+3]<<8)+battData[i*2+4];
+ avg+=bd;
+ if(bd>max) max=bd;
+ if(bd<min) min=bd;
+ }
+ avg /= 96;
+ if(min<3713) {
+ jv=avg-(max-avg)*1.5;
+ } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement
+ jv=0;
+ }
+
+ //------------------
+ tt.cls();
+
+ // show as histogram
+ int xWinMin = 20;
+ int xWinMax = 300;
+ int yWinMin = 50;
+ int yWinMax = 150;
+ // draw the Histogram Frame, 2 pixels wide
+ tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
+ tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
+
+ tt.locate( 0, yWinMax+10 );
+ printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
+
+ // binning
+ short nBin[301] ; // bins to count Min values in nBin[0], etc.
+ int height ;
+ int iBinIndxMax = 300 ;
+ int iBinValMax = max - min ; // zero to N
+ if( iBinValMax > iBinIndxMax ) iBinValMax = iBinIndxMax ;
+
+ // clean the bins
+ for(int i=0; i<=iBinIndxMax; i++) {
+ nBin[i] = 0;
+ }
+
+ // do the bin counting
+ for(int i=0; i<96; i++){
+ bd=(battData[i*2+3]<<8)+battData[i*2+4] - min ;
+ if( bd > iBinValMax ) bd = iBinValMax ;
+ nBin[bd] ++ ;
+ }
+
+ //----------------
+ if( iBinValMax == 0 ) {
+ // for testing
+ min = 10 ;
+ max = 50 ;
+ avg = ( max + min ) / 2;
+ iBinValMax = max - min ;
+ for(int i=0; i<=(iBinValMax/2); i++) {
+ nBin[i] = i ;
+ nBin[iBinValMax-i] = i ;
+ }
+ }
+
+ //---------------
+ // show the bars
+ int nBarWidth = 3 ;
+ int nBarSpace = 1 ; // 1 for testing
+
+ int xPos = (xWinMin + xWinMax) / 2 ;
+ xPos -= (avg-min) * (nBarWidth + nBarSpace) ;
+
+ for( int i=0; i<=iBinValMax; i++) {
+ height = 4 * nBin[i] ;
+ if( height > 100 ) height = 100 ; // clip tops
+
+ // if inside the window, draw the bar
+ if( ( xPos + nBarWidth < xWinMax ) && ( xPos > xWinMin ) )
+ tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);
+
+ // step to the next bar position
+ xPos += nBarWidth + nBarSpace ;
+ }
+
+ showCP=false;
+ }
+
+ // handle the button
+ if(sMode==1){
+ tt.foreground(Yellow);
+ tt.background(DarkCyan);
+ tt.set_font((unsigned char*) Arial12x12);
+ sprintf(sTemp1," Request");
+ sprintf(sTemp2," CP data");
showButton(1,0,sTemp1,sTemp2,3,3);
}
}
@@ -323,9 +430,6 @@
}
sprintf(sTemp2," Auto CP");
showButton(1,1,sTemp1,sTemp2,3,3);
- //sprintf(sTemp1," Start");
- //sprintf(sTemp2,"Playback");
- //showButton(2,1,sTemp1,sTemp2,3,3);
}
void pbScreen(bool force, bool showButtons){
@@ -364,15 +468,13 @@
struct tm t; // pointer to a static tm structure
time_t seconds ;
tt.foreground(Yellow);
- tt.background(Navy);
+ tt.background(Black);
if (force) {
tt.cls();
seconds = time(NULL);
t = *localtime(&seconds) ;
tt.locate(10,10);
- tt.foreground(Yellow);
- tt.background(DarkCyan);
tt.set_font((unsigned char*) Arial12x12);
strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t);
printf("%s",sTemp1);
@@ -403,6 +505,7 @@
default:
break;
}
+ tt.background(DarkCyan);
showButton(0,1,sTemp1,sTemp2,3,3);
sprintf(sTemp1," UP");
showButton(1,1,sTemp1,sTemp2,3,3);
@@ -464,6 +567,9 @@
case dateScreen:
showDateTime(changed,(display==whichTouched));
break;
+ case cpHistScreen: // gg - hist
+ cpHistogram(changed);
+ break;
default:
if (changed){
tt.background(Black);
@@ -486,39 +592,42 @@
showButton(2,2,sTemp1,sTemp2,3,3);
sprintf(sTemp1," Select");
switch (dMode[display]) {
- case 0:
+ case offScreen:
sprintf(sTemp2," Off");
break;
- case 1:
+ case logScreen:
sprintf(sTemp2," Log");
break;
- case 2:
+ case mainScreen:
sprintf(sTemp2," Main");
break;
- case 3:
+ case brakeScreen:
sprintf(sTemp2," Braking");
break;
- case 4:
+ case dteScreen:
sprintf(sTemp2," DTE");
break;
- case 5:
+ case monitorScreen:
sprintf(sTemp2," Monitor");
break;
- case 6:
+ case changedScreen:
sprintf(sTemp2,"Delta Mon");
break;
- case 7:
+ case cpScreen:
sprintf(sTemp2," Cell Pair");
break;
- case 8:
+ case config1Screen:
sprintf(sTemp2," Config");
break;
- case 9:
+ case playbackScreen:
sprintf(sTemp2," Playback");
break;
- case 10:
+ case dateScreen:
sprintf(sTemp2," Set Time");
break;
+ case cpHistScreen: // gg - hist
+ sprintf(sTemp2," CP Hist");
+ break;
}
showButton(1,2,sTemp1,sTemp2,3,3);
wait_ms(100); // pause a moment to reduce flicker
