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 169:84d790ac18a2, committed 2013-12-17
- Comitter:
- TickTock
- Date:
- Tue Dec 17 15:25:41 2013 +0000
- Parent:
- 168:9227024c4e3a
- Child:
- 170:7ee98e3611bc
- Commit message:
- // Added trip meter including climate control impact; // Pulled updateConfig to dedicated procedure
Changed in this revision
--- a/displayModes.cpp Wed Dec 04 12:45:39 2013 +0000
+++ b/displayModes.cpp Tue Dec 17 15:25:41 2013 +0000
@@ -69,8 +69,9 @@
lkW=total_kW;
if(CCon){
tt.set_font((unsigned char*) Arial12x12);
- tt.locate(231,64);
- printf(" %3.2fkW\n",CCkW);
+ tt.locate(228,64);
+ tt.foreground(GreenYellow);
+ printf(" -%3.2fkW\n",CCkW);
tt.set_font((unsigned char*) Arial28x28);
}
}
@@ -112,25 +113,20 @@
// No Climate Control DTE
tt.set_font((unsigned char*) Arial24x23);
- tt.foreground(Green);
if(CCon) {
dte=convertDistance((mpkWh_noCC-mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion
if(dte>199){
dte=199;
}
- tt.locate(130,134);
- printf("+%2.1f \n",dte);
- /*// " "=13, "."=5, #=17
- if(dte>=99.5){
- tt.locate(120,134);
- printf(" %3.0f\n",dte);
- }else if(dte>=9.5){
- tt.locate(111,134);
- printf(" %2.0f\n",dte);
+ tt.foreground(GreenYellow);
+ if(dte>=9.5){
+ tt.locate(130,134);
+ printf("+%2.0f \n",dte);
}else{
- tt.locate(111,134);
- printf(" %2.1f\n",dte);
- }*/
+ tt.locate(130,134);
+ printf("+%2.1f \n",dte);
+ }
+
lmaxTemp=0; //force battery termperature refresh (sometimes overlaps)
}
// best-case DTE
@@ -344,11 +340,15 @@
tt.foreground(Navy);
tt.set_font((unsigned char*) Arial28x28);
tt.locate(6,210);
+ printf("kWh : %s : Eff\n",distanceUnit());
+ tt.set_font((unsigned char*) Arial12x12);
+ tt.locate(260,220);
if(inclCC){
- printf("kWh : %s : Eff (+CC)\n",distanceUnit());
+ printf(" (+CC)\n");
} else {
- printf("kWh : %s : Eff (noCC)\n",distanceUnit());
+ printf("(noCC)\n");
}
+ tt.set_font((unsigned char*) Arial28x28);
for(int i=0; i<3; i++){
kWh_f = kWh_trip[i];
if(inclCC){
@@ -1000,7 +1000,13 @@
//-------- top row --------
showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
showButton(1,0," Reset","Max/Min",4,4);
-
+ if (showHealth) {
+ sprintf(sTemp1," Hide");
+ } else {
+ sprintf(sTemp1," Show");
+ }
+ showButton(2,0,sTemp1," Health",4,4);
+
// a button to step to the next skin
unsigned int nextSkin = skin + 1 ;
if( nextSkin > maxSkin ) nextSkin = 0 ;
@@ -1028,13 +1034,8 @@
}
showButton(0,2,sTemp1," tSync",4,4);
showButton(1,2," Set"," Time",4,4);
- if (showHealth) {
- sprintf(sTemp1," Hide");
- } else {
- sprintf(sTemp1," Show");
- }
- showButton(2,2,sTemp1," Health",4,4);
- showButton(3,2,"Update","Firmware",4,4);
+ showButton(2,2," Update"," Config",4,4);
+ showButton(3,2," Update","Firmware",4,4);
}
void pbScreen(bool force, bool showButtons){
@@ -1234,7 +1235,7 @@
printf(" %2.1f\n",miles);
}
if(CCon) {
- tt.foreground(Green);
+ tt.foreground(GreenYellow);
tt.set_font((unsigned char*) Arial24x23);
miles = (mpkWh_noCC-mpkWh[dtePeriod])*((float)(gids-5)*.075);
miles = convertDistance(miles); // LM - Metric support
@@ -1251,7 +1252,7 @@
tt.locate(200,1);
printf("%3.1f \n",mpkWh[dtePeriod]);
if(CCon) {
- tt.foreground(Green);
+ tt.foreground(GreenYellow);
tt.set_font((unsigned char*) Arial24x23);
tt.locate(190,52);
printf(" +%2.1f \n",(mpkWh_noCC-mpkWh[dtePeriod]));
@@ -1381,6 +1382,7 @@
tt.locate(170,90+(i/2)*30);
}
if(clearTest){
+ maxPS=0;
oldData[i]=uData[i];
tt.foreground(Yellow);
tt.background(Navy);
--- a/main.cpp Wed Dec 04 12:45:39 2013 +0000
+++ b/main.cpp Tue Dec 17 15:25:41 2013 +0000
@@ -9,9 +9,11 @@
// * 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
// * Add climate control impact to main max/min dte and new trip display
+// * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
// rev168
// Added trip meter including climate control impact
+// Pulled updateConfig to dedicated procedure
#include "mbed.h"
#include "CAN.h"
@@ -472,6 +474,7 @@
if (dMode[whichTouched]==changedScreen) {
for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data
lastDMode[whichTouched]=99;//force refresh
+ sMode=0;
} else if (dMode[whichTouched] == indexScreen) { // gg - index
sMode=0;
dMode[whichTouched] = brakeScreen ; // GoTo Brake Screen
@@ -513,6 +516,22 @@
dMode[whichTouched]=mainScreen;
saveConfig();
beep(2000,0.25);
+ //write efficiency history data
+ hfile = fopen("/local/ehist.cny", "w");
+ if (hfile!=NULL){ // found a efficiency history file
+ for(i=0;i<39;i++){
+ fprintf(hfile,"%f %f\r\n",mph[i],kW[i]);
+ }
+ fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min
+ fprintf(hfile,"%f \r\n",Resr); // Save series resistance
+ fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min
+ fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min
+ fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min
+ fclose(hfile);
+ }
+ beep(2000,0.25);
+ } else if (dMode[whichTouched]==config2Screen) {
+ showHealth = !showHealth;
} else if (dMode[whichTouched]==playbackScreen) { // faster
if(playbackInt>.002){
playbackInt/=2;
@@ -541,7 +560,7 @@
} else if (dMode[whichTouched] == indexScreen) { // gg - index
dMode[whichTouched] = healthScreen ; // Goto health screen
sMode=0;
- } else if (dMode[whichTouched] == testScreen) { // gg - index
+ } else if (dMode[whichTouched] == testScreen) { // gg -
clearTest=true;
} else { // top-right corner always mute/unmute unless used by specific screen
enableSound = !enableSound;
@@ -677,10 +696,13 @@
case 22: // right-middle col, bottom row (not nav)
if (dMode[whichTouched]==indexScreen) { // gg - index
dMode[whichTouched] = logScreen ;
+ sMode=0;
} else if (dMode[whichTouched]==configScreen) {
heaterMon = !heaterMon;
} else if (dMode[whichTouched]==config2Screen) {
- showHealth = !showHealth;
+ updateConfig();
+ lastDMode[whichTouched]=99;//force refresh
+ sMode=0;
} else {
lastDMode[whichTouched]=99;//repaint to clear highlight
}
@@ -698,6 +720,7 @@
lastDMode[whichTouched]=99;//repaint to clear highlight
} else if (dMode[whichTouched]==indexScreen) {
dMode[whichTouched] = tripScreen ;
+ sMode=0;
} else if (dMode[whichTouched]==dateScreen){
autoSync=!autoSync; // toggle autoSync mode
lastDMode[whichTouched]=99;
--- a/utility.cpp Wed Dec 04 12:45:39 2013 +0000
+++ b/utility.cpp Tue Dec 17 15:25:41 2013 +0000
@@ -960,46 +960,6 @@
tt.foreground(Yellow);
tt.locate(0,10);
tt.cls();
- // Check for config file on USB drive
- sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);
- if(sfr == FR_OK)
- {
- printf("Copy config file from USB\n");
- lfile = fopen("/local/CONFIG.TXT", "w");
- if(lfile != NULL) {
- while (!f_eof(&efile))
- {
- sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
- fwrite(buffer, 1, bytesRW, lfile);
- }
- fflush(lfile);
- fclose(lfile);
- }
- f_close(&efile);
- int fwc_tmp = fwCount;
- readConfig();
- fwCount = fwc_tmp; // Do no overwrite fwcount when loading new config
- //wait(2);
- }
-
- // Check for history file on USB drive
- sfr = f_open(&efile,"ehist.cny",FA_READ|FA_OPEN_EXISTING);
- if(sfr == FR_OK)
- {
- printf("Copy ehist file from USB\n");
- lfile = fopen("/local/ehist.cny", "w");
- if(lfile != NULL) {
- while (!f_eof(&efile))
- {
- sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
- fwrite(buffer, 1, bytesRW, lfile);
- }
- fflush(lfile);
- fclose(lfile);
- }
- f_close(&efile);
- //wait(2);
- }
sfr = f_open(&efile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);
if(sfr != FR_OK)
@@ -1070,6 +1030,59 @@
mbed_reset();
}
+void updateConfig()
+{
+ FIL efile; // external usb file
+ FRESULT sfr; // external file access flags
+ unsigned int bytesRW;
+ char sTemp[40];
+ const int bufSize = 2048;
+ char buffer[bufSize];
+ FILE *lfile;
+
+ tt.set_font((unsigned char*) Arial12x12);
+ tt.background(Blue);
+ tt.foreground(Yellow);
+ tt.locate(0,10);
+ tt.cls();
+ // Check for config file on USB drive
+ sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);
+ if(sfr == FR_OK){
+ printf("Copy config file from USB\n");
+ lfile = fopen("/local/CONFIG.TXT", "w");
+ if(lfile != NULL) {
+ while (!f_eof(&efile)){
+ sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+ fwrite(buffer, 1, bytesRW, lfile);
+ }
+ fflush(lfile);
+ fclose(lfile);
+ }
+ f_close(&efile);
+ int fwc_tmp = fwCount;
+ readConfig();
+ fwCount = fwc_tmp; // Do no overwrite fwcount when loading new config
+ }
+
+ // Check for history file on USB drive
+ sfr = f_open(&efile,"ehist.cny",FA_READ|FA_OPEN_EXISTING);
+ if(sfr == FR_OK){
+ printf("Copy ehist file from USB\n");
+ lfile = fopen("/local/ehist.cny", "w");
+ if(lfile != NULL) {
+ while (!f_eof(&efile)){
+ sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+ fwrite(buffer, 1, bytesRW, lfile);
+ }
+ fflush(lfile);
+ fclose(lfile);
+ }
+ f_close(&efile);
+ }
+ printf("Succesful.\n\n");
+ wait(5);
+}
+
bool detectUSB(void){
FIL tfile; // external usb file
bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK);
--- a/utility.h Wed Dec 04 12:45:39 2013 +0000
+++ b/utility.h Tue Dec 17 15:25:41 2013 +0000
@@ -109,6 +109,7 @@
void logPackVoltages(); // Turbo3
void tripLog(); // Turbo3
void updateFirmware(); // LM - Update firmware off USB
+ void updateConfig();
bool detectUSB();
void chirp();
void beep(float freq, float time);
