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_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 10:ebc6326d9bd6
- Parent:
- 9:c7857e87dd07
- Child:
- 11:e9d155aad4e2
--- a/main.cpp Sat Feb 23 05:25:35 2013 +0000
+++ b/main.cpp Wed Feb 27 02:59:11 2013 +0000
@@ -24,10 +24,10 @@
PwmOut dled(p24);
InterruptIn touchpad(p17);
-CAN can1(p30, p29); // CAN1 uses pins 30 and 29 (rx, tx) and pin 28 (rs)
+CAN can1(p9, p10); // CAN2 uses pins 9 and 10 (rx, tx) and pin 27 (rs)
+DigitalOut can2SleepMode(p8); // Use pin 8 to control the sleep mode of can2
+CAN can2(p30, p29); // CAN1 uses pins 30 and 29 (rx, tx) and pin 28 (rs)
DigitalOut can1SleepMode(p28); // Use pin 28 to control the sleep mode of can1
-CAN can2(p9, p10); // CAN2 uses pins 9 and 10 (rx, tx) and pin 27 (rs)
-DigitalOut can2SleepMode(p8); // Use pin 8 to control the sleep mode of can2
bool logEn = true,logOpen = false;
FILE *rfile;
FILE *file;
@@ -43,12 +43,13 @@
volatile bool canIdle = false, userIdle = false;
bool getXY=0; //flag to read touchscreen
char counter = 0;
-unsigned char dMode[2] = {4,2}; //display mode
+unsigned char dMode[2] = {7,2}; //display mode
unsigned char sMode = 0; // setup mode
unsigned char lastDMode[2] = {0,0}; //last screen mode
char displayLog[20][40];
unsigned char displayLoc = 0;
unsigned char indexOffset = 1;
+bool showCP = false;
TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset
@@ -399,16 +400,44 @@
}
void cpData(bool force){
- tt.foreground(White);
- tt.background(Maroon);
- tt.set_font((unsigned char*) Arial12x12_prop); // select the font
- if(force) tt.cls();
- tt.locate(0,6);
- printf("cellpair temperatures: %dC %dC %dC %dC\ncellpair voltages (mV):\n\n",battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
- if(force) tt.cls(); // Just clear screen if forced - always update display
- for(int i=0; i<16; i++){
- //printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n",i*6,i*6+5,(battData[i*12+5]<<8)+battData[i*12+4],(battData[i*12+7]<<8)+battData[i*12+6],(battData[i*12+9]<<8)+battData[i*12+8],(battData[i*12+11]<<8)+battData[i*12+10],(battData[i*12+13]<<8)+battData[i*12+12],(battData[i*12+15]<<8)+battData[i*12+14]);
- printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n",i*6,i*6+5,(battData[i*12+3]<<8)+battData[i*12+4],(battData[i*12+5]<<8)+battData[i*12+6],(battData[i*12+7]<<8)+battData[i*12+8],(battData[i*12+9]<<8)+battData[i*12+10],(battData[i*12+11]<<8)+battData[i*12+12],(battData[i*12+13]<<8)+battData[i*12+14]);
+ short unsigned max, min, jv, i, bd;
+ unsigned avg;
+ if(force){
+ tt.foreground(White);
+ tt.background(Maroon);
+ tt.set_font((unsigned char*) Arial12x12_prop); // select the font
+ max=0;
+ min=9999;
+ avg=0;
+ //battData[4]=2;
+ //battData[38]=8;
+ //battData[79]=3;
+ 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;
+ jv=avg-(max-avg)*2.5;
+ tt.cls();
+ tt.locate(0,6);
+ //printf("cellpair temperatures: %dC %dC %dC %dC\ncellpair voltages (mV):\n\n",battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
+ printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %dC %dC %dC %dC\n\n",max,min,avg,jv,battData[224+5],battData[224+8],battData[224+11],battData[224+14]);
+ tt.locate(0,36);
+ for(i=0; i<16; i++){
+ printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n",i*6+1,i*6+6,(battData[i*12+3]<<8)+battData[i*12+4],(battData[i*12+5]<<8)+battData[i*12+6],(battData[i*12+7]<<8)+battData[i*12+8],(battData[i*12+9]<<8)+battData[i*12+10],(battData[i*12+11]<<8)+battData[i*12+12],(battData[i*12+13]<<8)+battData[i*12+14]);
+ }
+ for(i=0; i<96; i++){
+ bd=(battData[i*2+3]<<8)+battData[i*2+4];
+ if(bd>0){
+ if(bd==max) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Green);
+ if(bd==avg) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,White);
+ if(bd==min) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Yellow);
+ if(bd<jv) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Red);
+ }
+ }
+ showCP=false;
}
}
@@ -436,7 +465,7 @@
printChanged(changed);
break;
case cpMode:
- cpData(changed);
+ cpData(changed||showCP);
break;
default:
tt.background(Black);
@@ -651,6 +680,8 @@
sendCPreq(); // send cellpair data request.
wait_ms(16);
sendTreq(); //send temperature request
+ wait_ms(16);
+ showCP=true;
}
}
} //top of screen
