[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Battery levels
From: |
Bastien Nocera |
Subject: |
Re: Battery levels |
Date: |
Thu, 01 Nov 2007 10:46:19 +0000 |
Hey Daniele,
On Thu, 2007-11-01 at 10:47 +0100, Daniele Forsi wrote:
> Bastien Nocera wrote:
>
> > I'm currently using some code similar to what's in xgnokii in
> > gnome-phone-manager:
> > http://svn.gnome.org/viewvc/phonemgr/trunk/libgsm/phonemgr-listener.c?view=
> >markup (see phonemgr_listener_battery_poll ())
>
> I think that multply by 25 comes from 100 / 4 because max_battery_level == 4
> in the only drivers that use GN_BU_Arbitrary except a (rare) special case at
> common/phones/nk6100.c:589 where it is set to 1
>
> > Daniele's example code uses phone.max_battery_level from the driver:
> > http://www.forsi.it/gnobatmon
>
> I was wrong because it returns a valid percentage value only with drivers
> setting battery_level as GN_BU_Arbitrary, namely nk3110.c nk6100.c nk6160.c
> (I should have noted that I actually tested it only with nk6100.c)
>
> the formula used in common/phones/nk6510.c is probably what I copied without
> undestanding the two different battery_unit settings:
> 3563: *(data->battery_level) = message[9] * 100 /
> state->driver.phone.max_battery_level;
To be fair, I didn't really understand those values either.
> > Which is correct? In my testing Daniele's option gave me thousands of
> > percents using the nk6510 driver.
>
> the most intuitive way to avoid the magic number 25 could be something like
> this (not yet tested, guessed from looking at the sources for the drivers)
>
> if (data->battery_unit == GN_BU_Percentage) {
> percent = data->battery_level;
> } else {
> percent = data->battery_level * 100 /
> state->driver.phone.max_battery_level;
> }
I fixed gnome-phone-manager to do that now. Thanks.
> Thanks to your question I noticed that the gnapplet driver had a wrong value
> for battery_unit (corrected to GN_BU_Percentage since gnapplet.c revision
> 1.34)
Code review is always good :)
Thanks!