[patch] addon-hid-ups.c : battery.present is mandatory for HAL spec

Richard Hughes hughsient at gmail.com
Tue May 10 12:01:20 PDT 2005


On Tue, 2005-05-10 at 14:35 -0400, David Zeuthen wrote:
> Oh, sorry, I missed this one. I would just create a function
> 
>  double util_compute_time_remaining (const char *id,
>                                      double curRate,
>                                      double curLevel,
>                                      bool is_charging);
> 
> then we can always swap in another function that may do more interesting
> stuff in the future.

Can I disagree? We need more variables than that:

double util_compute_time_remaining (const char *id,
                                     double curRate,
                                     double curLevel,
                                     double curLevelLastFull,
                                     bool is_discharging,
                                     bool is_charging);

Which makes a bit of a wieldy prototype (and means we have to 
look up all the values even if we don't use them in the calculation.)

I was thinking of something minimal like this:

static void
battery_calculate_minutes (HalDevice *d)
{
	int chargeRate, chargeLevel, chargeLastFull;
	int secondsRemaining;

	/* work out minutesRemaining as value is not provided by ACPI */
	chargeRate = hal_device_property_get_int (d, "battery.charge_level.rate");
	if (chargeRate =< 0)
		return;

	if (hal_device_property_get_bool (d, "battery.rechargeable.is_discharging")) {
		chargeLevel = hal_device_property_get_int (d, "battery.charge_level.current");
		secondsRemaining = ((double) chargeLevel / (double) chargeRate) * 60 * 60;
		hal_device_property_set_int (d, "battery.remaining_time", secondsRemaining);
		return;
	}

	if (hal_device_property_get_bool (d, "battery.rechargeable.is_charging")) {
		chargeLevel = hal_device_property_get_int (d, "battery.charge_level.current");
		chargeLastFull = hal_device_property_get_int (d, "battery.charge_level.last_full");
		secondsRemaining = ((double) (chargeLastFull - chargeLevel) / (double) chargeRate) * 60 * 60;
		hal_device_property_set_int (d, "battery.remaining_time", secondsRemaining);
		return;
	}
}

Which only does the needed lookups and could easily be replaced in the future with a different algorithm.

Is this the sort of thing you mean?

> 
> > Another question, 
> > 
> > hal_device_property_set_int (d, "foo", 6);
> > 
> > Will I get 5 lots of DBUS traffic, and if not there a big overhead
> > anyway?
> 
> One way is to try it together with lshal --monitor :-). 

Bugger. :-)

> The answer is
> that we hal_device_property_set_* refuses to send a notification if
> nothing changes.

That's what I thought. Goodie good.

Richard.

_______________________________________________
hal mailing list
hal at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/hal



More information about the Hal mailing list