MPGuino Supporter
Join Date: Oct 2010
Location: Hungary
Posts: 1,807
iNXS - '10 Opel Zafira 111 Anniversary Suzi - '02 Suzuki Swift GL
Thanks: 830
Thanked 708 Times in 456 Posts
|
Quote:
Originally Posted by skybolt
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
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.
|