1N/A/*************************************************************************** 1N/A * Copyright (C) 2005 Richard Hughes <richard@hughsie.com> 1N/A * Copyright (C) 2005 Danny Kukawka <danny.kukawka@web.de> 1N/A * Licensed under the Academic Free License version 2.1 1N/A * This program is free software; you can redistribute it and/or modify 1N/A * it under the terms of the GNU General Public License as published by 1N/A * the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * This program is distributed in the hope that it will be useful, 1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A * GNU General Public License for more details. 1N/A * You should have received a copy of the GNU General Public License 1N/A * along with this program; if not, write to the Free Software 1N/A * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1N/A **************************************************************************/ 1N/A/** Convert the hardware reported value into a few sane choices 1N/A * This is needed as ACPI does not specify the description text for a 1N/A * battery, and so we have to calculate it from the hardware output 1N/A * @param type The battery type recieved from the hardware 1N/A * @return The battery technology which is one of: 1N/A * unknown, lithium-ion or lead-acid 1N/A /* every case combination of Li-Ion is commonly used.. */ 1N/A return "lithium-ion";
1N/A return "lithium-polymer";
1N/A return "nickel-metal-hydride";
1N/A/** Given all the required parameters, this function will return the percentage 1N/A * charge remaining. There are lots of checks here as ACPI is often broken. 1N/A * @param id Optional ID given to this battery. Unused at present. 1N/A * @param chargeLevel The current charge level of the battery (typically mWh) 1N/A * @param chargeLastFull The last "full" charge of the battery (typically mWh) 1N/A * @return Percentage, -1 if invalid 1N/A /* make sure we have chargelevel */ 1N/A /* make sure not division by zero */ 1N/A /* Some bios's will report this higher than 100, limit it here */ 1N/A /* Something really isn't right if we get a negative... */ 1N/A/** Given all the required parameters, this function will return the number 1N/A * of seconds until the battery is charged (if charging) or the number 1N/A * of seconds until empty (if discharging) 1N/A * @param id Optional ID given to this battery. Unused at present. 1N/A * @param chargeRate The "rate" (typically mW) 1N/A * @param chargeLevel The current charge level of the battery (typically mWh) 1N/A * @param chargeLastFull The last "full" charge of the battery (typically mWh) 1N/A * @param isDischarging If battery is discharging 1N/A * @param isCharging If battery is charging 1N/A * @param guessChargeRate If ignore chargeRate and guess them. 1N/A * @return Number of seconds, or -1 if invalid 1N/A /* should not get negative values */ 1N/A HAL_WARNING ((
"chargeRate, chargeLevel or chargeLastFull < 0, returning -1"));
1N/A /* batteries cannot charge and discharge at the same time */ 1N/A * Some laptops don't supply any rate info, but that's no reason for HAL not 1N/A * to. We use the current and previous chargeLevel to estimate the rate. 1N/A * The info is stored in a GHashTable because there could be more than one battery. 1N/A /* Initialize the save_battery_info GHashTable */ 1N/A /* check this to prevent division by zero */ 1N/A /* if we can't calculate because nothing changed, use last 1N/A * chargeRate to prevent removing battery.remaining_time. 1N/A * During discharging chargeRate would be negative, which would 1N/A * mess up the the calculation below, so we make sure it's always 1N/A * Some ACPI BIOS's don't update chargeLastFull, 1N/A * so return 0 as we don't know how much more there is left 1N/A /* This shouldn't happen, but check for completeness */ 1N/A /* Battery life cannot be above 60 hours */