Rockbox mail archive
Subject: Re: Rockbox for the player
From: Paul Suade (paul.suade_at_laposte.net)
Date: 2002-09-12
Well, maybe using an average for a short time might flat the flickering
value; I mean using a small array like a ring to put your battery level and
computing the average that way :
int compute_vbatt_average (int new_vbatt) {
static int vbatt_top;
static int vbatt_sum;
static int vbatt_num;
static short vbatt_ring[VBATT_RING_SIZE];
// consider the sum of a ring (window) of 'vbatt_num' values,
// so just substract the old value before adding the new value
vbatt_sum += new_vbatt - vbatt_ring[vbatt_top];
// replace the old value with the new value
vbatt_ring[vbatt_top] = new_vbatt;
if (vbatt_num < BATT_AVG_SIZE)
vbatt_num++;
// advance or wrap the pointer
if (vbatt_top < BATT_AVG_SIZE)
vbatt_top++;
else
vbatt_top = 0;
// compute the average battery level
return vbatt_sum/vbatt_num;
}
This algo is O(1).
----- Original Message -----
From: "Chris Pimlott" <rockbox_at_chris.pimlott.net>
To: <rockbox_at_cool.haxx.se>
Sent: Wednesday, September 11, 2002 7:35 PM
Subject: Re: Rockbox for the player
> On Wed, Sep 11, 2002 at 02:10:54PM +0100, Stuart Tedford wrote:
>
> > In Rockbox, the battery indicator is very accurate.
>
> One minor quibble - over the course of an evening testing out
> code, I was amused to notice that sometimes the the battery meter
> sometimes went back up from a lower level to a higher level (without
> being plugged in). I know that you can never really get an *exact*
> reading on the battery level but it would be nice to see the minor
> fluctuations taken care of.
>
> Perhaps we can use a different scale as change goes up and down,
> i.e. when change drops from below 3V, lower it to 2 bars and don't raise
> it to 3 bars until it climbs above 3.1V. This way, if it first reads
> 2.99 then 3.01, the meter won't flicker between 2 and 3 bars.
>
> Chris Pimlott
Page was last modified "Jan 10 2012" The Rockbox Crew
|