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 TFT_fonts TOUCH_TFTx2 beep mbed
Fork of CANary by
Revision 50:83d5864c64a0, committed 2013-04-07
- Comitter:
- TickTock
- Date:
- Sun Apr 07 16:34:12 2013 +0000
- Parent:
- 49:a3d2c5bb3cfa
- Child:
- 51:6187c5264a73
- Commit message:
- Removed DTE flicker. Added efficiency screen. Added configurable DTE interval. Allowed CP update even if CP logging disabled.
Changed in this revision
--- a/common.h Sun Apr 07 08:29:04 2013 +0000 +++ b/common.h Sun Apr 07 16:34:12 2013 +0000 @@ -2,16 +2,17 @@ #define logScreen 1 #define mainScreen 2 #define brakeScreen 3 -#define dteScreen 4 -#define monitorScreen 5 -#define changedScreen 6 -#define cpScreen 7 -#define config1Screen 8 -#define playbackScreen 9 -#define dateScreen 10 -#define cpHistScreen 11 -#define cpBarScreen 12 -#define maxScreens 12 +#define effScreen 4 +#define dteScreen 5 +#define cpScreen 6 +#define cpHistScreen 7 +#define cpBarScreen 8 +#define monitorScreen 9 +#define changedScreen 10 +#define playbackScreen 11 +#define dateScreen 12 +#define config1Screen 13 +#define maxScreens 13 #define btnGap 10 #define ttSkin 0 #define ggSkin 1
--- a/displayModes.cpp Sun Apr 07 08:29:04 2013 +0000
+++ b/displayModes.cpp Sun Apr 07 16:34:12 2013 +0000
@@ -94,7 +94,7 @@
tt.set_font((unsigned char*) Arial28x28);
if(force) tt.cls();
if(skin==ttSkin){
- if(force||gids!=lgids||mpkWh[9]!=lmpkWh){
+ if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){
tt.locate(10,10);
printf("%4d gids \n",gids);
tt.locate(10,40);
@@ -102,9 +102,9 @@
tt.set_font((unsigned char*) SCProSB31x55);
tt.foreground(Green);
tt.locate(60,96);
- printf("%4.1f mi \n",mpkWh[9]*((float)(gids-5)*.075)); // Use 1 minute average
+ printf("%4.1f mi \n",mpkWh[dtePeriod]*((float)(gids-5)*.075));
lgids=gids;
- lmpkWh-mpkWh[9];
+ lmpkWh=mpkWh[dtePeriod];
tt.foreground(Yellow);
tt.set_font((unsigned char*) Arial28x28);
}
@@ -727,45 +727,90 @@
}
}
-void dteDisplay(bool force, bool showButtons){
- unsigned short i,x,y,lx,ly;
+void dteDisplay(bool force, bool showButtons, bool showMiles){
+ unsigned short i,x,y,lx,ly,gids,radius,color;
+ static unsigned short lgids=0;
+ static unsigned char leff[39]={0};
+ CANMessage msg;
+
+ msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
+ gids = (msg.data[0]<<2)+(msg.data[1]>>6);
+ if(gids==0){
+ gids=281;
+ }
+
tt.background(Navy);
tt.foreground(Yellow);
- if(force||updateDTE){
+ if(force||lgids!=gids){
tt.cls();
tt.set_font((unsigned char*) Arial12x12);
for(i=0;i<10;i++){
y=200-i*20;
tt.locate(10,y-8);
- printf("%d.0\n",i);
- tt.line(40,y,280,y,LightGrey);
+ if (showMiles){
+ printf("%3.0f\n",i*((float)(gids-5)*.075));
+ }else{
+ printf("%d.0\n",i);
+ }
+ tt.line(40,y,280,y,DarkGrey);
}
x=50+0*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("sec\n");
- tt.line(x,10,x,220,LightGrey);
+ tt.line(x,10,x,220,DarkGrey);
x=50+9*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("min\n");
- tt.line(x,10,x,220,LightGrey);
+ tt.line(x,10,x,220,DarkGrey);
x=50+18*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("hour\n");
- tt.line(x,10,x,220,LightGrey);
+ tt.line(x,10,x,220,DarkGrey);
x=50+25*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("day\n");
- tt.line(x,10,x,220,LightGrey);
+ tt.line(x,10,x,220,DarkGrey);
x=50+32*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("mon\n");
- tt.line(x,10,x,220,LightGrey);
+ tt.line(x,10,x,220,DarkGrey);
x=50+38*6;
- tt.locate(x-8,226);
+ tt.locate(x-6,226);
printf("year\n");
- tt.line(x,10,x,220,LightGrey);
-
+ tt.line(x,10,x,220,DarkGrey);
+ lgids=gids;
+ }
+ if(force||updateDTE){
+ for(i=0;i<10;i++){
+ y=200-i*20;
+ if (y>60){
+ tt.line(40,y,280,y,DarkGrey);
+ } else {
+ tt.line(40,y,150,y,DarkGrey);
+ }
+ }
+
+ x=50+0*6;
+ tt.line(x,10,x,220,DarkGrey);
+ x=50+9*6;
+ tt.line(x,10,x,220,DarkGrey);
+ x=50+18*6;
+ tt.line(x,10,x,220,DarkGrey);
+ x=50+25*6;
+ tt.line(x,180,x,220,DarkGrey);
+ x=50+32*6;
+ tt.line(x,180,x,220,DarkGrey);
+ x=50+38*6;
+ tt.line(x,180,x,220,DarkGrey);
+ tt.set_font((unsigned char*) SCProSB31x55);
+ tt.foreground(Green);
+ tt.locate(180,10);
+ if (showMiles){
+ printf("%4.1f\n",mpkWh[dtePeriod]*((float)(gids-5)*.075));
+ } else {
+ printf("%3.1f\n",mpkWh[dtePeriod]);
+ }
lx=50;
ly=mpkWh[0]*20;
if(ly<200) {
@@ -773,7 +818,15 @@
}else{
ly=0;
}
- tt.fillcircle(lx,ly,4,Green);
+ if(dtePeriod==0){
+ radius=4;
+ color=Magenta;
+ }else{
+ radius=2;
+ color=Green;
+ }
+ tt.fillcircle(lx,leff[0],radius,Navy);
+ tt.fillcircle(lx,ly,radius,color);
for(i=1;i<39;i++){
x=50+i*6;
@@ -783,12 +836,23 @@
}else{
y=0;
}
- tt.circle(x,y,2,Green);
+ if(i==dtePeriod){
+ radius=4;
+ color=Magenta;
+ }else{
+ radius=2;
+ color=Green;
+ }
+ tt.fillcircle(x,leff[i],radius,Navy);
+ tt.line(x-6,leff[i-1],x,leff[i],Navy);
+ leff[i-1]=ly;
+ tt.fillcircle(x,y,radius,color);
tt.line(lx,ly,x,y,White);
lx=x;
ly=y;
}
- updateDTE=false;
+ leff[i-1]=y;
+ updateDTE=false;
}
}
@@ -807,9 +871,12 @@
braking(changed,(display==whichTouched));
break;
case dteScreen:
- dteDisplay(changed,(display==whichTouched));
+ dteDisplay(changed,(display==whichTouched),true);
break;
- case monitorScreen:
+ case effScreen:
+ dteDisplay(changed,(display==whichTouched),false);
+ break;
+ case monitorScreen:
printLast(changed,(display==whichTouched));
break;
case changedScreen:
@@ -870,6 +937,9 @@
case dteScreen:
sprintf(sTemp2," DTE");
break;
+ case effScreen:
+ sprintf(sTemp2," Eff");
+ break;
case monitorScreen:
sprintf(sTemp2," Monitor");
break;
--- a/displayModes.h Sun Apr 07 08:29:04 2013 +0000
+++ b/displayModes.h Sun Apr 07 16:34:12 2013 +0000
@@ -33,6 +33,7 @@
extern float mpkWh[39];
extern unsigned char whichTouched;
extern unsigned char skin;
+extern unsigned char dtePeriod;
extern bool updateDTE;
extern "C" {
@@ -40,7 +41,7 @@
void printChanged (bool force, bool showButtons);
void printLog (bool force, bool showButtons);
void mainDisplay (bool force, bool showButtons);
- void dteDisplay (bool force, bool showButtons);
+ void dteDisplay (bool force, bool showButtons, bool showMiles);
void braking (bool force, bool showButtons, bool prdata);
void cpData(bool force, bool showButtons);
void cpHistogram(bool force, bool showButtons); // gg - hist
--- a/main.cpp Sun Apr 07 08:29:04 2013 +0000
+++ b/main.cpp Sun Apr 07 16:34:12 2013 +0000
@@ -96,6 +96,7 @@
char data[8];
signed long motorRPM;
unsigned char skin = 0;
+unsigned char dtePeriod = 14; //ten minute averaging interval
float mph[39]={0};
float kW[39]={0};
float mpkWh[39]={0};
@@ -113,7 +114,7 @@
char sTemp[40];
unsigned long secs;
unsigned char i,j,display=0,lwt=0;
- unsigned char sixtySecCount=0;
+ unsigned char minuteCount=0;
point lastTouch;
float average,mph9,kW9;
@@ -154,12 +155,13 @@
t = *localtime(&seconds) ;
strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t);
logMsg(sTemp);
- sprintf(sTemp,"CANary firmware rev49\n");
+ sprintf(sTemp,"CANary firmware rev50\n");
logMsg(sTemp);
// Look for new binary on thumbdrive
// Can't make this work right now since USB doesn't attach the right timestamp (so new binary isn't loaded)
/*cfile = fopen("/usb/CANary.bin", "rb");
+ lastDMode[whichTouched]=99;//force refresh
if (cfile!=NULL){ //found a new binary on the thumbdrive so copy it over
sprintf(sTemp,"New binary found.\n");
logMsg(sTemp);
@@ -230,7 +232,7 @@
//sprintf(sTemp,"Using file %s\n",fileName);
//logMsg(sTemp);
file = fopen(fileName, "ab");
-
+ lastDMode[whichTouched]=99;//force refresh
if(file==NULL){
sprintf(sTemp,"\nUnable to open %s\n\n\n\n",fileName);
logMsg(sTemp);
@@ -432,12 +434,15 @@
if(!playbackOpen){
if(!logOpen){
file = fopen("/usb/playback.alc", "rb");
+ lastDMode[whichTouched]=99;//force refresh
if(file==NULL){
sprintf(sTemp,"Unable to open /usb/playback.alc\n");
logMsg(sTemp);
spkr.beep(1000,0.25);
} else {
playbackOpen = true;
+ playbackEn=true;
+ playback.attach(&playbackISR,playbackInt);
sprintf(sTemp,"Starting playback\n");
logMsg(sTemp);
spkr.beep(2000,0.25);
@@ -452,11 +457,11 @@
playback.detach();
fclose(file);
playbackOpen=false;
+ playbackEn=false;
can1.attach(&recieve1);// Restore CAN data recieve
can2.attach(&recieve2);
lastDMode[whichTouched]=99;
}
- playbackEn=false;
} else if (dMode[whichTouched]==dateScreen){
upDate(dtMode,true);
lastDMode[whichTouched]=99;
@@ -559,28 +564,28 @@
mph9=mph[i]/timeConstant[i];
mph[i]-=mph9;
mph[i]+=mph[0];
- mpkWh[i]=mph9;
kW9=kW[i]/timeConstant[i];
kW[i]-=kW9;
kW[i]+=kW[0];
- mpkWh[i]/=kW9;
+ mpkWh[i]=mph[i];
+ mpkWh[i]/=kW[i];
if (mpkWh[i]<0) {
mpkWh[i]=99;// negative means inf.
}
//mpkWh[i]=floor(mpkWh[i]*10+0.5)/10; // Round to nearest 10th
}
// The rest are updated each minute
- if(++sixtySecCount>59){ //
- sixtySecCount=0;
+ if(++minuteCount>59){ //
+ minuteCount=0;
for(i=10;i<39;i++){
average=mph[i]/timeConstant[i];
mph[i]-=average;
mph[i]+=mph9;
- mpkWh[i]=average;
average=kW[i]/timeConstant[i];
kW[i]-=average;
kW[i]+=kW9;
- mpkWh[i]/=average;
+ mpkWh[i]=mph[i];
+ mpkWh[i]/=kW[i];
if (mpkWh[i]<0) {
mpkWh[i]=99;// negative means inf.
}
@@ -612,6 +617,7 @@
}else{
fclose(file); // restart
file = fopen("/usb/playback.alc", "rb");
+ lastDMode[whichTouched]=99;//force refresh
spkr.beep(2000,0.25);
}
}
--- a/utility.cpp Sun Apr 07 08:29:04 2013 +0000
+++ b/utility.cpp Sun Apr 07 16:34:12 2013 +0000
@@ -103,7 +103,11 @@
lasti=i; //remember the msb to detect rollover next time around
i+=bdi;
//if(i==22) logCP=true; //Turbo3
- if( (i==22) && (yesBattLog) ) logCP=true; // only if enabled gg - Batt Log
+ //if( (i==22) && (yesBattLog) ) logCP=true; // only if enabled gg - Batt Log
+ if(i==22){
+ logCP=yesBattLog; // Only log is logging enabled
+ showCP=true; // Always show
+ }
i*=7;
if(i<0xfa){ // Is there a better way to do this?
battData[i+0]=canRXmsg.data[1];
@@ -246,6 +250,7 @@
fprintf(cfile,"pollInt %d\r\n",pollInt);
fprintf(cfile,"scale12V %4.2f\r\n",scale12V);
fprintf(cfile,"skin %d\r\n",skin);
+ fprintf(cfile,"dtePeriod %d\r\n",dtePeriod);
fclose(cfile);
}
@@ -288,6 +293,7 @@
}
if(ff>2){
fscanf(cfile, "skin %d\r\n", &skin ) ;
+ fscanf(cfile, "dtePeriod %d\r\n", &dtePeriod ) ;
}
fclose(cfile);
if(ff<3){//If not latest format, save as latest format
--- a/utility.h Sun Apr 07 08:29:04 2013 +0000
+++ b/utility.h Sun Apr 07 16:34:12 2013 +0000
@@ -44,6 +44,7 @@
extern signed long motorRPM;
extern unsigned short numSsamples;
extern unsigned char skin;
+extern unsigned char dtePeriod;
extern "C" {
void mbed_reset();
