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.
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 182:10017d74de67, committed 2014-03-30
- Comitter:
- TickTock
- Date:
- Sun Mar 30 03:00:14 2014 +0000
- Parent:
- 181:396fdcceefd2
- Child:
- 183:a1fba6f76e69
- Commit message:
- // * whpg display formatting
Changed in this revision
| displayModes.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/displayModes.cpp Tue Mar 25 19:57:08 2014 +0000
+++ b/displayModes.cpp Sun Mar 30 03:00:14 2014 +0000
@@ -1427,51 +1427,41 @@
}
void whpgDisplay(bool force, bool showButtons, bool showWh){
- unsigned short maxVal, minVal, maxGid, minGid, i, j, y;
- float avg;
+ unsigned short maxGid, minGid, i, y, delta;
static unsigned short lmg;
tt.foreground(White);
tt.background(Navy);
tt.set_font((unsigned char*) Arial12x12_prop); // select the font
- maxVal=0;
- minVal=9999;
maxGid=0;
minGid=9999;
- avg=0;
+ delta=0;
if(force){
lmg=281;
}
- // find max/min/avg
+ // find max/min/delta
if(showWh){
- for(i=0; i<299; i++){
+ for(i=0; i<300; i++){
if(wh[i]>0){
- j=(wh[i+1]-wh[i]);
- avg+=j;
- if(j>maxVal) maxVal=j;
- if(j<minVal) minVal=j;
if(i>maxGid) maxGid=i;
if(i<minGid) minGid=i;
}
}
+ delta = (wh[maxGid]-wh[minGid]);
}else{
- for(i=0; i<299; i++){
+ for(i=0; i<300; i++){
if(whpg[i]>0){
- j=(whpg[i]-whpg[i+1]);
- avg+=j;
- if(j>maxVal) maxVal=j;
- if(j<minVal) minVal=j;
if(i>maxGid) maxGid=i;
if(i<minGid) minGid=i;
}
}
+ delta = (whpg[minGid]-whpg[maxGid]);
}
- avg /= (maxGid-minGid+1);
- if (minGid<lmg){ //update if new data
+ if (force||(minGid<lmg)){ //update if new data
lmg = minGid;
//------------------
tt.cls();
@@ -1485,36 +1475,45 @@
tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1, Red);
tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2, Green);
// draw grid
- for( i=20; i<yWinMax-yWinMin; i+=20){
+ for( i=0; i<yWinMax-yWinMin; i+=20){
tt.line(xWinMin,yWinMax-i,xWinMax,yWinMax-i,DarkGrey);
+ if(i%40 == 0){
+ // label the y axis each 40
+ tt.line( xWinMin-8,yWinMax-i, xWinMin-2,yWinMax-i, White ); // a white tick mark
+ tt.locate( 0, yWinMax-i-4 );
+ printf("%d\n", i );
+ }
}
- for( i=20; i<xWinMax-xWinMin; i+=20){
- tt.line(xWinMin+i,yWinMin,xWinMin+i,yWinMax,DarkGrey);
+ for( i=0; i<xWinMax-xWinMin; i+=10){
+ // tic mark the x axis each 10
+ tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+4, White ); // a white tick mark
+ if(i%40 == 0){
+ // label the x axis each 40
+ tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+8, White ); // a white tick mark
+ if(i<100){
+ tt.locate( i+xWinMin-7, yWinMax+8 );
+ }else{
+ tt.locate( i+xWinMin-15, yWinMax+8 );
+ }
+ printf("%d\n", i );
+ }
+ if(i%20 == 0){
+ tt.line(xWinMin+i,yWinMin,xWinMin+i,yWinMax,DarkGrey);
+ }
}
- //----------------
- if( maxVal > minVal ) {
-
- // label the Y axis
- tt.locate( 2, yWinMin-6); printf("%d\n",yWinMax-yWinMin);
- tt.locate( 2, yWinMax-6); printf("0\n");
- //tt.locate( xWinMin+3, yWinMax-avg-6); printf("%3.1f avg\n", avg );
- tt.locate( xWinMin+4, yWinMin+4); printf("%3.1f avg\n", avg );
+ // plot
+ if( maxGid >= minGid ) {
+ tt.locate( xWinMin+4, yWinMin+4);
+ printf("%3.1f avg\n", (float) delta/(maxGid-minGid) );
+ if(debugMode){
+ tt.locate( xWinMin+4, yWinMin+20);
+ printf("minGids=%d; maxGids=%d\n", minGid,maxGid);
+ tt.locate( xWinMin+4, yWinMin+36);
+ printf("minwhpg=%d; maxwhpg=%d\n", whpg[minGid],whpg[maxGid]);
+ }
for( i=4; i<=286; i++) {
- if(i%40 == 0){
- // label the x axis each 40
- tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+8, White ); // a white tick mark
- if(i<10){
- tt.locate( i+xWinMin-12, yWinMax+8 );
- }else{
- tt.locate( i+xWinMin-20, yWinMax+8 );
- }
- printf("%d\n", i );
- } else if(i%10 == 0){
- // tic mark the x axis each 10
- tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+4, White ); // a white tick mark
- }
if(showWh){
y = wh[i]-wh[i-1];
tt.fillcircle(i+xWinMin,yWinMax-y,2,Green);
--- a/main.cpp Tue Mar 25 19:57:08 2014 +0000
+++ b/main.cpp Sun Mar 30 03:00:14 2014 +0000
@@ -9,10 +9,9 @@
// * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?)
// * Add on screen messages for heater on, etc, and use refresh feature above to clear in x seconds
// * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
-
+// * Fix wrong whpg bug when charging away from home (no clearing of trip[3])
-// rev181
-// Added grid to whpg displays
+// rev182
#include "mbed.h"
#include "CAN.h"
@@ -23,7 +22,7 @@
#include "displayModes.h"
#include "TOUCH_TFTx2.h"
-char revStr[7] = "181";
+char revStr[7] = "182";
unsigned long maxTarget = 1000;
FATFS USBdrive;
LocalFileSystem local("local");
@@ -920,21 +919,32 @@
if(whpg[i]>maxWhpg){
maxWhpg=whpg[i];
minWh=wh[i];
+ if(debugMode){
+ sprintf(sTemp,"maxWhpg=%3.1f;minWh=%3.1f\n", maxWhpg,minWh);
+ printMsg(sTemp); // revision
+ }
}
if(minWh>0){
if((whpg[i]==0)&&(whpg[i-1]>0)){ //Remember the offset at the end of the measured range
whOff = minWh+maxWhpg-wh[i];
- }
+ if(debugMode){
+ sprintf(sTemp,"whOff=%3.1f\n", whOff);
+ printMsg(sTemp); // revision
+ }
+ }
wh[i] *= 4;
- if(whOff>0){ // Apply offset to all level above measured range
- wh[i] += wh[i]+whOff;
+ if(whpg[i]==0){ // Apply offset to all levels outside measured range
+ wh[i] += wh[i];
+ wh[i] += whOff;
}else{ // Apply adjustment to measured range
- wh[i] += minWh+maxWhpg-whpg[i];
+ wh[i] += minWh;
+ wh[i] += maxWhpg;
+ wh[i] -= (float) whpg[i];
}
- wh[i] /=5;
+ wh[i] /= 5;
}
}
- for(i=1;i<300;i++){ // clear array
+ for(i=0;i<300;i++){ // clear array
whpg[i]=0;
}
}
@@ -1062,6 +1072,9 @@
miles_trip[1]=0;
kWh_trip[1]=0;
CCkWh_trip[1]=0;
+ //if((cgids>0)&&(cgids<300)){
+ // whpg[cgids]=0;
+ //}
}
motorRPM=0;
