View Single Post
Old 07-22-2009, 12:19 AM   #11 (permalink)
skelly
EcoModding Lurker
 
Join Date: Apr 2009
Location: Clarkston, MI
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by arlo View Post
skelly,
Where have you posted this code? I really wanted to check out distance to empty. I made a function for it, but it takes up too much memory and won't fit.
Thanks
Hi arlo,

I have not figured out a place to put the code yet. Any ideas?

I did not try

Here is essentially the code for DTE. You will need to add a #define somewhere:
Code:
#define DTE_CFG                    1  /* 0=Off 1=On        */
My call to "doDisplayBigDTE" here:

Code:
pFunc displayFuncs[] ={
   doDisplayCustom,
   doDisplayInstantCurrent,
   doDisplayInstantTank,
   doDisplayBigInstant,
   doDisplayBigCurrent,
   doDisplayBigTank,
   doDisplayCurrentTripData,
   doDisplayTankTripData,
   doDisplayEOCIdleData,
   doDisplaySystemInfo,
#if (BARGRAPH_DISPLAY_CFG == 1)
   doDisplayBigPeriodic,
   doDisplayBarGraph,
#endif
#if (DTE_CFG == 1)
   doDisplayBigDTE,
#endif
};
Also you need to add a label to it:
Code:
   displayFuncNames[x++]=  PSTR("Custom  ");
   displayFuncNames[x++]=  PSTR("Instant/Current ");
   displayFuncNames[x++]=  PSTR("Instant/Tank ");
   displayFuncNames[x++]=  PSTR("BIG Instant ");
   displayFuncNames[x++]=  PSTR("BIG Current ");
   displayFuncNames[x++]=  PSTR("BIG Tank ");
   displayFuncNames[x++]=  PSTR("Current ");
   displayFuncNames[x++]=  PSTR("Tank ");
   displayFuncNames[x++]=  PSTR("EOC mi/Idle gal ");
   displayFuncNames[x++]=  PSTR("CPU Monitor ");
#if (BARGRAPH_DISPLAY_CFG == 1)
   displayFuncNames[x++]=  PSTR("BIG Periodic ");
   displayFuncNames[x++]=  PSTR("Bargraph ");
#endif
#if (DTE_CFG == 1)
   displayFuncNames[x++]=  PSTR("BIG DTE ");
#endif

And here is the function. The 'safety factor' there is if you want to subtract a gallon or so to ensure that even when DTE says zero, you still maybe have a gallon left.

Code:
#if (DTE_CFG == 1)
void doDisplayBigDTE(void) {
   unsigned long dte;
   signed long gals_remaining;
   /* TODO: user configurable safety factor see minus zero below */
   gals_remaining = (parms[tankSizeIdx] - tank.gallons()) - 0;
   gals_remaining = MAX(gals_remaining, 0);
   dte = gals_remaining * (tank.mpg()/100);
   dte /= 10; /* divide by 10 here to avoid precision loss */
   /* dividing a signed long by 10 for some reason adds 100 bytes to program size?
    * otherwise I would've divided gals by 10 earlier! */
   bigNum(dte, "DIST", "TO E");
}
You need this supporting macro "MAX":

Code:
#define MAX(value2, value1)\
    (((value1)>=(value2)) ? (value1) : (value2))

  Reply With Quote