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 184:5ca7b78297fe, committed 2014-05-06
- Comitter:
- TickTock
- Date:
- Tue May 06 14:43:58 2014 +0000
- Parent:
- 183:a1fba6f76e69
- Child:
- 185:69cc7adc29a3
- Commit message:
- Increased Heater alarm on/off threshold (turns on slightly during AC use).
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 Sun Mar 30 03:31:37 2014 +0000
+++ b/displayModes.cpp Tue May 06 14:43:58 2014 +0000
@@ -37,14 +37,20 @@
if (useable_kWh<0){
useable_kWh=0;
}
- //tt.locate(181,4);
- tt.locate(170,4); //LAJ temp
- if (useable_kWh<9.95){
- //printf("%3.2fkWh\n",useable_kWh);
- printf("%3.2f %3.2f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp
- } else {
- //printf("%3.1fkWh\n",useable_kWh);
- printf("%3.1f %3.1f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp
+ if(debugMode){
+ tt.locate(165,4);
+ if (useable_kWh<9.95){
+ printf("%3.2f %3.2f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp
+ } else {
+ printf("%3.1f %3.1f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp
+ }
+ }else{
+ tt.locate(181,4);
+ if (useable_kWh<9.95){
+ printf("%3.2fkWh\n",useable_kWh);
+ } else {
+ printf("%3.1fkWh\n",useable_kWh);
+ }
}
}
if(force||SOC_x10!=lSOC){
@@ -1427,7 +1433,7 @@
}
void whpgDisplay(bool force, bool showButtons, bool showWh){
- unsigned short maxGid, minGid, i, y, delta;
+ unsigned short maxGid, minGid, i, y, maxWg;
static unsigned short lmg;
tt.foreground(White);
@@ -1436,13 +1442,12 @@
maxGid=0;
minGid=9999;
- delta=0;
if(force){
lmg=281;
}
- // find max/min/delta
+ // find max/min/maxWg
if(showWh){
for(i=0; i<300; i++){
if(wh[i]>0){
@@ -1450,7 +1455,7 @@
if(i<minGid) minGid=i;
}
}
- delta = (wh[maxGid]-wh[minGid]);
+ maxWg = wh[maxGid];
}else{
for(i=0; i<300; i++){
if(whpg[i]>0){
@@ -1458,7 +1463,7 @@
if(i<minGid) minGid=i;
}
}
- delta = (whpg[minGid]-whpg[maxGid]);
+ maxWg = whpg[minGid];
}
if (force||(minGid<lmg)){ //update if new data
@@ -1505,25 +1510,29 @@
// plot
if( maxGid >= minGid ) {
tt.locate( xWinMin+4, yWinMin+4);
- printf("%3.1f avg\n", (float) delta/(maxGid-minGid) );
+ printf("%3.1f avg\n", (float) maxWg/(maxGid-minGid+1) );
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]);
+ if(showWh){
+ printf("minwh=%3.1f; maxwh=%3.1f\n", wh[minGid],wh[maxGid]);
+ }else{
+ printf("minwhpg=%d; maxwhpg=%d\n", whpg[minGid],whpg[maxGid]);
+ }
}
- for( i=4; i<=286; i++) {
+ for( i=3; i<=287; i++) {
if(showWh){
y = wh[i]-wh[i-1];
tt.fillcircle(i+xWinMin,yWinMax-y,2,Green);
}else{
- if((whpg[i-4]>0)&&(whpg[i+4]>0)){
- y = (whpg[i-4]-whpg[i+4])/8;
+ if((whpg[i-3]>0)&&(whpg[i+3]>0)){
+ y = (whpg[i-3]-whpg[i+3])/6;
}else{
- y = whpg[i];
+ y = 0;
}
- if( (y>20) && (y<180) && whpg[i]>0){
+ if((y>0) && (y<180)){
tt.fillcircle(i+xWinMin,yWinMax-y,2,Yellow);
}
}
--- a/main.cpp Sun Mar 30 03:31:37 2014 +0000
+++ b/main.cpp Tue May 06 14:43:58 2014 +0000
@@ -10,8 +10,8 @@
// * 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)
-// rev183
-// * Fix wrong whpg bug when charging away from home (now update and clear on each charge)
+// rev184
+// Fixed wh adjustment algorithm
#include "mbed.h"
#include "CAN.h"
@@ -22,7 +22,7 @@
#include "displayModes.h"
#include "TOUCH_TFTx2.h"
-char revStr[7] = "183";
+char revStr[7] = "184";
unsigned long maxTarget = 1000;
FATFS USBdrive;
LocalFileSystem local("local");
@@ -515,6 +515,9 @@
maxTripEff = 0;
minTripEff = 5;
beep(2000,0.25);
+ for(i=0;i<300;i++){ // initialize wh lookup
+ wh[i]=i*kWperGid*1000;
+ }
} else if (dMode[whichTouched]==playbackScreen) { // pause/unpause
playbackEn=!playbackEn;
if(playbackEn){
@@ -536,8 +539,6 @@
sMode=0;
} else if (dMode[whichTouched]==configScreen) {
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
@@ -555,6 +556,8 @@
fclose(hfile);
}
beep(2000,0.25);
+ saveConfig();
+ beep(2000,0.25);
} else if (dMode[whichTouched]==config2Screen) {
showHealth = !showHealth;
} else if (dMode[whichTouched]==playbackScreen) { // faster
@@ -830,7 +833,7 @@
if(heaterOn){
lHeaterOn=true; // Only indicate heater once per power cycle
}
- heaterOn =((lastMsg[indexLastMsg[0x54f]].data[5]&0x3f)>0)?true:false;
+ heaterOn =((lastMsg[indexLastMsg[0x54f]].data[5]&0x3f)>2)?true:false;
if(heaterMon && heaterOn && !lHeaterOn){ //Heat on alarm
beep3(800,0.25,1200,0.25,1600,0.25);
//beep(1600,0.5);
@@ -886,44 +889,36 @@
seconds = time(NULL);
t = *localtime(&seconds);
if(miles_trip[1]<1){ // charged since last trip
+
+ // Adjust wh lookup with whpg data
maxWhpg=0;
minWh=0;
whOff=0;
- // Adjust wh lookup with whpg data weighted 20%
for(i=1;i<300;i++){
- if(whpg[i]>maxWhpg){
- maxWhpg=whpg[i];
- minWh=wh[i];
+ if(whpg[i]>maxWhpg){ //Find maxWhpg and associated Wh
+ maxWhpg = (float) whpg[i];
+ minWh = wh[i];
if(debugMode){
- sprintf(sTemp,"maxWhpg=%3.1f;minWh=%3.1f\n", maxWhpg,minWh);
- printMsg(sTemp); // revision
+ sprintf(sTemp,"maxWhpg=%3.1f; minWh=%3.1f\n", maxWhpg, minWh);
+ printMsg(sTemp);
}
}
- 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(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;
- wh[i] += maxWhpg;
- wh[i] -= (float) whpg[i];
+ if(whpg[i]>0){ // Compute adjustment to measured range
+ whOff = (maxWhpg-(float)whpg[i])-(wh[i]-minWh);
+ }else if(whpg[i-1]>0){ // Compute final offset for rest of range
+ whOff = maxWhpg-(wh[i]-minWh);
+ if(debugMode){
+ sprintf(sTemp,"whOff=%3.1f\n", whOff);
+ printMsg(sTemp);
}
- wh[i] /= 5;
}
+ wh[i] += 0.1*whOff; // Add offset; use last known good offset when no data
+ whpg[i-1]=0;
}
- for(i=0;i<300;i++){ // clear array
- whpg[i]=0;
- }
+ whpg[299]=0;
+
+ // Check and reset daily efficiency if charged since last trip and at least 24 hours has past
if((t.tm_yday>lt.tm_yday)&&(t.tm_hour>effCheckTime)){
- // Check and reset daily efficiency if charged since last trip and at least 24 hours has past
if (!ignoreDayData&&(miles_trip[3]>15)){ // Ignore low mileage data
curEff = miles_trip[3]/kWh_trip[3]; // Get current daily efficiency
if (maxTripEff<curEff) {
@@ -985,7 +980,11 @@
}
if((cgids>0)&&(cgids<300)){
if(cgids!=lgids){
- whpg[cgids] = (unsigned short) (1000*(kWh_trip[1]+CCkWh_trip[1])); // Save kWh for each gid since last charge
+ if((kWh_trip[1]+CCkWh_trip[1])>0){
+ whpg[cgids] = (unsigned short) (1000*(kWh_trip[1]+CCkWh_trip[1])); // Save kWh for each gid since last charge
+ }else{
+ whpg[cgids] = 0;
+ }
lgids=cgids;
}
}
