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 mbed
Fork of CANary by
Revision 35:5acbd8a64a89, committed 2013-03-21
- Comitter:
- TickTock
- Date:
- Thu Mar 21 12:05:22 2013 +0000
- Parent:
- 34:4751a8259b18
- Child:
- 36:dbd39c315258
- Commit message:
- Added 12V monitor; configurable 12V adjustment & dled brightness (via config file); new config file format 2; fixed reset on select bug
Changed in this revision
--- a/common.h Wed Mar 20 13:57:00 2013 +0000 +++ b/common.h Thu Mar 21 12:05:22 2013 +0000 @@ -13,4 +13,4 @@ #define maxBufLen 768 #define canTimeout 5 -#define userTimeout 10 +#define userTimeout 15
--- a/displayModes.cpp Wed Mar 20 13:57:00 2013 +0000
+++ b/displayModes.cpp Thu Mar 21 12:05:22 2013 +0000
@@ -85,7 +85,7 @@
tt.set_font((unsigned char*) Arial28x28);
tt.locate(10,10);
printf("%4d gids\n",gids);
- tt.locate(10,200);
+ tt.locate(20,40);
printf("%4.1f kWh\n",(float)gids*0.08);
tt.set_font((unsigned char*) SCProSB31x55);
tt.foreground(Green);
@@ -107,6 +107,12 @@
printf("%4.1fV\n",(float)packV/2);
lpackV=packV;
}
+ if(force||tick){
+ tt.foreground(Yellow);
+ tt.set_font((unsigned char*) Arial28x28);
+ tt.locate(20,200);
+ printf("%4.2fV \n",accV);
+ }
}
void braking (bool force, bool prdata=false){
--- a/displayModes.h Wed Mar 20 13:57:00 2013 +0000
+++ b/displayModes.h Thu Mar 21 12:05:22 2013 +0000
@@ -24,6 +24,8 @@
extern unsigned char sMode;
extern TOUCH_TFTx2 tt;
extern unsigned char dtMode;
+extern float accV;
+extern bool tick;
extern "C" {
void printLast (bool force);
--- a/main.cpp Wed Mar 20 13:57:00 2013 +0000
+++ b/main.cpp Thu Mar 21 12:05:22 2013 +0000
@@ -1,7 +1,6 @@
// main.cpp
//To Do:
-// * Auto-poll cellpair data (user selectable)
// * Log file playback (to enable testing of new passive display modes without having to drive around)
// * USB device detect
// * Ability to update binary from the thumb-drive (requires file timestamp)
@@ -9,7 +8,6 @@
// * Audible friction brake feedback
// * User-configurable watchpoint
// * Immediately turn off when car is turned off and logging
-// * 12V monitor
// * Better graphical DTE display with historic efficiency information considered and displayed
// * Add 50% charge option
// * Tire Pressure Sensor display
@@ -30,10 +28,9 @@
LocalFileSystem local("local");
// to write to USB Flash Drives, or equivalent (SD card in Reader/Writer)
-MSCFileSystem fs("fs"); // to write to a USB Flash Drive
+MSCFileSystem fs("usb"); // to write to a USB Flash Drive
time_t seconds ;
-Beep spkr(p21);
Ticker ticker;
Timer timer;
@@ -43,15 +40,15 @@
DigitalOut led3(LED3);
DigitalOut led4(LED4);
-PwmOut dled(p23);
-
InterruptIn touchpad(p17);
CAN can1(p9, p10); // CAN1 (EV) uses pins 9 and 10 (rx, tx) and pin 8 (rs)
DigitalOut can1SleepMode(p8); // Use pin 8 to control the sleep mode of can2
CAN can2(p30, p29); // CAN2 (CAR) uses pins 30 and 29 (rx, tx) and pin 28 (rs)
DigitalOut can2SleepMode(p28); // Use pin 28 to control the sleep mode of can1
-
+AnalogIn mon12V(p15);
TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset
+PwmOut dled(p23);
+Beep spkr(p21);
bool logEn = false,logOpen = false;
FILE *cfile;
@@ -82,6 +79,12 @@
bool repeatPoll = false;
bool headlights = false;
bool tick = false;
+float ledHi = 0.8; // Bright LED value (until config file read)
+float ledLo = 0.1; // Dim LED value (until config file read)
+unsigned short pollInt = 300; // polling interval=5 minutes (until config file read)
+bool accOn = false; // Accessories on
+float scale12V = 16.2; // R1:R2 ratio
+float accV = 0;
int main() {
int readPointer=0;
@@ -131,7 +134,7 @@
// 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("/fs/CANary.bin", "rb");
+ /*cfile = fopen("/usb/CANary.bin", "rb");
if (cfile!=NULL){ //found a new binary on the thumbdrive so copy it over
sprintf(sTemp,"New binary found.\n");
logMsg(sTemp);
@@ -158,7 +161,7 @@
}
fclose(cfile);
fclose(file);
- remove("/fs/CANary.bin"); // delete original
+ remove("/usb/CANary.bin"); // delete original
mbed_reset(); //restart
}
}*/
@@ -176,7 +179,7 @@
if(logEn){ //logging enable
seconds = time(NULL);
t = *localtime(&seconds) ;
- strftime(fileName, 32, "/fs/%m%d%H%M.alc", &t); //mmddhhmm.alc
+ strftime(fileName, 32, "/usb/%m%d%H%M.alc", &t); //mmddhhmm.alc
//sprintf(sTemp,"Using file %s\n",fileName);
//logMsg(sTemp);
file = fopen(fileName, "ab");
@@ -332,7 +335,7 @@
if (dMode[i]==config1Screen) {
repeatPoll = !repeatPoll&&logEn;
if (repeatPoll) {
- ticker.attach(&tickerISR,300);
+ ticker.attach(&tickerISR,pollInt);
} else {
ticker.detach();
}
@@ -355,7 +358,6 @@
case 12:
case 42:
secsNoTouch = userTimeout; // immediately exit config mode
- if (dMode[i]==config1Screen) mbed_reset();
break;
case 22:
case 52:
@@ -394,10 +396,14 @@
}
if(tick){ // Executes once a second
- if(!headlights){
- dled = 0.75;
+ accV=mon12V*scale12V;
+ accOn=(accV>5)?true:false;
+ if(!accOn&&!logEn&&userIdle){
+ dled = 0; // turn off display if car off and logging disabled and no user activity
+ }else if(!headlights){
+ dled = ledHi;
}else{
- dled = 0.1;
+ dled = ledLo;
}
tick=false;
}
--- a/utility.cpp Wed Mar 20 13:57:00 2013 +0000
+++ b/utility.cpp Thu Mar 21 12:05:22 2013 +0000
@@ -27,7 +27,7 @@
void touch_ISR(){
LPC_GPIOINT->IO2IntClr = (LPC_GPIOINT->IO2IntStatR | LPC_GPIOINT->IO2IntStatF);
- touched=true; // jsut set flag - touch screen algorythm is long and we don't want to block other interrupts
+ touched=true; // just set flag - touch screen algorythm is long and we don't want to block other interrupts
}
unsigned short getTimeStamp() {
@@ -193,7 +193,7 @@
void saveConfig(){
FILE *cfile;
cfile = fopen("/local/config.txt", "w");
- fprintf(cfile,"format 1\r\n");
+ fprintf(cfile,"format 2\r\n");
fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
@@ -211,6 +211,10 @@
fprintf(cfile,"dMode1 %d\r\n",dteScreen);
else
fprintf(cfile,"dMode1 %d\r\n",dMode[1]);
+ fprintf(cfile,"ledHi %4.3f\r\n",ledHi);
+ fprintf(cfile,"ledLo %4.3f\r\n",ledLo);
+ fprintf(cfile,"pollInt %d\r\n",pollInt);
+ fprintf(cfile,"scale12V %4.2f\r\n",scale12V);
fclose(cfile);
}
@@ -243,7 +247,20 @@
fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ;
fscanf(cfile, "dMode0 %d\r\n", &dMode[0] ) ;
fscanf(cfile, "dMode1 %d\r\n", &dMode[1] ) ;
+ if(ff>1){
+ fscanf(cfile, "ledHi %4.3f\r\n", &ledHi ) ;
+ fscanf(cfile, "ledLo %4.3f\r\n", &ledLo ) ;
+ fscanf(cfile, "pollInt %d\r\n", &pollInt ) ;
+ fscanf(cfile, "scale12V %4.2f\r\n", &scale12V ) ;
+ }else{ //old format - set defaults
+ ledHi = 0.8;
+ ledLo = 0.1;
+ pollInt = 300;
+ scale12V = 16.2;
+ }
fclose(cfile);
+ if(ff<2) //If not latest format, save as latest format
+ saveConfig();
}
}
--- a/utility.h Wed Mar 20 13:57:00 2013 +0000
+++ b/utility.h Thu Mar 21 12:05:22 2013 +0000
@@ -28,6 +28,10 @@
extern bool tick;
extern bool headlights;
extern TOUCH_TFTx2 tt;
+extern float ledHi;
+extern float ledLo;
+extern unsigned short pollInt;
+extern float scale12V;
extern "C" {
void mbed_reset();
