View Single Post
Old 02-08-2017, 09:58 AM   #81 (permalink)
t vago
MPGuino Supporter
 
t vago's Avatar
 
Join Date: Oct 2010
Location: Cedar Rapids, IA
Posts: 1,766

The Karen-Mobile - '05 Dodge Magnum SXT
Team Dodge
90 day: 26.72 mpg (US)

Fiat Dakota - '00 Dodge Dakota SLT RWD Quad Cab
90 day: 16.67 mpg (US)

The Red Sled - '01 Dodge Durango SLT 4WD
90 day: 16.96 mpg (US)
Thanks: 799
Thanked 681 Times in 437 Posts
Quote:
Originally Posted by skybolt View Post
The following is based on:
Code:
const char overFlowStr[] PROGMEM = "999999";


Code:
  reserveQuantity = doCalculate(instantIdx, tFuelEcon); //instant fuel economy
  if (doCalculate(instantIdx, tFuelEcon) > 999999) {
    text::stringOut(devLogSerial, PSTR("999999\",\n")); //infinte fuel economy, good for overflow and reasonable for anything above 999,999 (current overflow is 4,294,967.295 or (2^32)-1), check decimals is 999999 999.999 vs 999999.000? 
  } else {
  doOutputNumberJSON(reserveQuantity, 3, PSTR("\",\n")); // instantaneous fuel economy    
  }
I modified the formatDecimal() routine a little, to replace the overflow dashes with a string of '9's, if the calling routine specifies this in the procedure call. Now, doOutputJSON() and doOutputDataLog() both use this modification, and everything else still uses dashes.

Quote:
Originally Posted by skybolt View Post
Code:
  doOutputNumberJSON(2 * doCalculate(tankIdx, tFuelEcon) / 3, 3, PSTR(",")); // 2/3  tank fuel economy 
   doOutputNumberJSON(3 * doCalculate(tankIdx, tFuelEcon) / 3, 3, PSTR(",")); //  tank fuel economy, helps user differentiate current trip measure vs tank measure, with goal to keep current measure and instant marker above tank range
   doOutputNumberJSON(5 * doCalculate(tankIdx, tFuelEcon) / 3, 3, PSTR("],\n")); // 5/3 tank fuel economy

  text::stringOut(devLogSerial, PSTR("\"measures\":["));

//  min comparison keeps measure bars from extending past range, even if values in text are shown larger than range
  doOutputNumberJSON(min(doCalculate(currentIdx, tFuelEcon),5 * doCalculate(tankIdx, tFuelEcon) / 3), 3, PSTR(",")); //return lower of current trip mpg or range high bound
  doOutputNumberJSON(min(doCalculate(tankIdx, tFuelEcon),5 * doCalculate(tankIdx, tFuelEcon) / 3), 3, PSTR("],\n")); //return lower of tank mpg or range high bound
  
  text::stringOut(devLogSerial, PSTR("\"markers\":["));
//min compare keeps white marker from extending past range 
  doOutputNumberJSON(min(doCalculate(instantIdx, tFuelEcon),(5 * doCalculate(tankIdx, tFuelEcon)) / 3), 3, PSTR("]\xfd")); //
This certainly works, but the purist in me doesn't like it. min() has to calculate both terms first, then make the comparison. While SWEET64 is much faster now, than when we first tackled doOutputJSON() back in November, it's still kind of a computation hog. Let me chew on this a bit - I might come up with a SWEET64 solution that does this thing.

__________________
The Fiat Dakota


The Karen-mobile


The Red Sled
  Reply With Quote