107
106
hal_device_property_set_bool (d, "battery.rechargeable.is_charging", flags & PMU_BATT_CHARGING);
108
107
/* we're discharging if, and only if, we are not plugged into the wall */
110
char buf[HAL_PATH_MAX];
111
snprintf (buf, sizeof (buf), "%s/pmu/info", get_hal_proc_path ());
112
hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", buf, "",
109
hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", "/proc/pmu/info", "",
113
110
"AC Power", 0, "0", FALSE);
130
127
last_full = hal_device_property_get_int (d, "battery.charge_level.last_full");
132
129
/* TODO: could read some pmu file? */
133
remaining_time = util_compute_time_remaining (
134
hal_device_get_udi (d),
135
hal_device_property_get_int (d, "battery.charge_level.rate"),
138
hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
139
hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
140
hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
141
remaining_percentage = util_compute_percentage_charge (hal_device_get_udi (d), current, last_full);
143
* Only set keys if no error (signified with negative return value)
144
* Scrict checking is needed to ensure that the values presented by HAL
147
if (remaining_time > 0)
148
hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
150
hal_device_property_remove (d, "battery.remaining_time");
151
if (remaining_percentage > 0)
152
hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
154
hal_device_property_remove (d, "battery.charge_level.percentage");
130
device_pm_calculate_time (d);
131
device_pm_calculate_percentage (d);
156
133
device_property_atomic_update_end ();
158
135
device_property_atomic_update_begin ();
159
hal_device_property_remove (d, "battery.is_rechargeable");
160
hal_device_property_remove (d, "battery.rechargeable.is_charging");
161
hal_device_property_remove (d, "battery.rechargeable.is_discharging");
162
/*hal_device_property_remove (d, "battery.charge_level.unit");*/
163
hal_device_property_remove (d, "battery.charge_level.current");
164
hal_device_property_remove (d, "battery.charge_level.last_full");
165
hal_device_property_remove (d, "battery.charge_level.design");
136
device_pm_remove_optional_props (d);
166
137
device_property_atomic_update_end ();
355
325
hal_device_property_set_string (computer, "power_management.type", "pmu");
358
snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
359
pmu_synthesize_item (path, PMU_TYPE_AC_ADAPTER);
328
pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_AC_ADAPTER);
362
snprintf (path, sizeof (path), "%s/pmu", get_hal_proc_path ());
363
dir = g_dir_open (path, 0, &error);
331
dir = g_dir_open ("/proc/pmu", 0, &error);
364
332
if (dir != NULL) {
366
334
while ((f = g_dir_read_name (dir)) != NULL) {
367
335
gchar buf[HAL_PATH_MAX];
370
snprintf (buf, sizeof (buf), "%s/pmu/%s", get_hal_proc_path (), f);
338
snprintf (buf, sizeof (buf), "/proc/pmu/%s", f);
371
339
if (sscanf (f, "battery_%d", &battery_num) == 1) {
372
340
has_battery_bays = TRUE;
373
341
pmu_synthesize_item (buf, PMU_TYPE_BATTERY);
388
356
if (has_battery_bays) {
389
357
/* Add lid button */
390
snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
391
pmu_synthesize_item (path, PMU_TYPE_LID_BUTTON);
358
pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LID_BUTTON);
393
360
/* Add Laptop Panel */
394
snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
395
pmu_synthesize_item (path, PMU_TYPE_LAPTOP_PANEL);
361
pmu_synthesize_item ("/proc/pmu/info", PMU_TYPE_LAPTOP_PANEL);
398
364
/* setup timer for things that we need to poll */