1
1
/***************************************************************************
4
* utili_pm.c - Various Powermanagement related utilities
3
* util_pm.c - Various power management related utilities that do not need
4
* to use HalDevice. This is suitable to use in addons and probers.
6
6
* Copyright (C) 2005 Richard Hughes <richard@hughsie.com>
7
7
* Copyright (C) 2005 Danny Kukawka <danny.kukawka@web.de>
70
70
strcasecmp (type, "pbac") == 0) {
71
71
return "lead-acid";
73
if (strcasecmp (type, "lip") == 0) {
73
if (strcasecmp (type, "lip") == 0 ||
74
strcasecmp (type, "lipo") == 0) {
74
75
return "lithium-polymer";
76
77
if (strcasecmp (type, "nimh") == 0) {
77
78
return "nickel-metal-hydride";
80
if (strcasecmp (type, "lifo") == 0) {
81
return "lithium-iron-phosphate";
83
* util_compute_percentage_charge:
84
* @id: Optional ID given to this battery. Unused at present.
85
* @chargeLevel: The current charge level of the battery (typically mWh)
86
* @chargeLastFull: The last "full" charge of the battery (typically mWh)
87
* Returns: Percentage, -1 if invalid
89
* Given all the required parameters, this function will return the percentage
90
* charge remaining. There are lots of checks here as ACPI is often broken.
93
util_compute_percentage_charge (const char *id,
98
/* make sure we have chargelevel */
99
if (chargeLevel <= 0) {
100
HAL_WARNING (("chargeLevel %i, returning -1!", chargeLevel));
103
/* make sure not division by zero */
104
if (chargeLastFull > 0)
105
percentage = ((double) chargeLevel / (double) chargeLastFull) * 100;
107
HAL_WARNING (("chargeLastFull %i, percentage returning -1!", chargeLastFull));
110
/* Some bios's will report this higher than 100, limit it here */
111
if (percentage > 100) {
112
HAL_WARNING (("Percentage %i, returning 100!", percentage));
115
/* Something really isn't right if we get a negative... */
116
if (percentage < 0) {
117
HAL_WARNING (("Percentage %i, returning -1!", percentage));
124
87
* util_compute_time_remaining:
125
88
* @id: Optional ID given to this battery. Unused at present.
126
89
* @chargeRate: The "rate" (typically mW)