View Single Post
Old 10-03-2010, 08:02 AM   #2 (permalink)
FalconFour
EcoModding Lurker
 
FalconFour's Avatar
 
Join Date: Sep 2010
Location: Fresno, CA
Posts: 78

LEAF - '11 Nissan LEAF
Thanks: 4
Thanked 9 Times in 7 Posts
Tank MPG is the easiest. Right now, for testing, it starts with a fixed value of 17.9999999 MPG to test rounding functions (I wasn't quite sure how the code worked yet, but I'm getting the hang of it now), but that value is discarded as soon as tank MPG moves away from 0.00. It calculates against the configured (but currently unused) tank capacity setting.

It uses its own "screen" which I currently call "F4 edit" due to all the comments I made in the code indicating where I patched it ("// ** F4 edit: blah blah"). The screen has both RemMiles and Time (clock).

Here's the code:
Put this somewhere around the screen routines. I put mine after doDisplaySystemInfo.
Code:
void doDisplayRem(void) {
  LCD::gotoXY(0,0);
  unsigned long remMPG = tank.mpg(); // may need to change this below
  unsigned long remMiles = parms[tankSizeIdx]; // final value
  if (remMPG < 50) remMPG = 17999; // if unreasonably low, make more reasonable
  LCD::print("Rem miles:");
  remMiles -= tank.gallons(); // subtract used gallons from total tank gallons
  remMiles *= remMPG; // multiply available gallons by tank mpg
  remMiles /= 1000; // since we multiplied two *1000 vals, knock down a notch
  LCD::print(format(remMiles));
  LCD::gotoXY(0,1);
  LCD::print("                ");
}
Add a new displayFuncName:
Code:
        displayFuncNames[x++] = PSTR("Rem tank miles ");
And add a new displayFuncs to the position where you added the displayFuncName (if at the top of the stack, add it to beginning of list; if at bottom, add to end):
Code:
doDisplayRem,
And that should pretty much be that. You can also use the computation above to add it to any other screen you want (custom is nice), but real estate there is limited. So if you want to replace Current MPG on the Custom screen, you could do this:
Code:
void doDisplayCustom() {
  unsigned long remMPG = tank.mpg(); // may need to change this below
  unsigned long remMiles = parms[tankSizeIdx]; // final value
  if (remMPG < 50) remMPG = 17999; // if unreasonably low, make more reasonable
  remMiles -= tank.gallons(); // subtract used gallons from total tank gallons
  remMiles *= remMPG; // multiply available gallons by tank mpg
  remMiles /= 1000; // since we multiplied two *1000 vals, knock down a notch
	displayTripCombo("MG","LK", instantmpg(), " S"," S",  instantmph(), "GH","LH",
			instantgph(), "RM",  remMiles);
}
(I think. I haven't tried that... and I removed the metric functionality from mine, so I had to add that back above too.)

As they say... enjoy!

Last edited by FalconFour; 10-04-2010 at 10:09 AM.. Reason: fixed maths bugs
  Reply With Quote