aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNormal Ra <normalrawr@gmail.com>2013-12-22 13:09:16 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2013-12-22 13:14:46 +0100
commit946271c41d70e7ce5633380b4114dcd775fb73bb (patch)
treed210abfa6bc04c7856f6a44f16a9bfa587f02749
parent76269896fc4db8f6243a59465f9af9994f72c47c (diff)
downloadvicious-legacy-946271c41d70e7ce5633380b4114dcd775fb73bb.tar.xz
bat: expose information on battery wear and tear
Modern batteries should expose information about their design capacity which we can compare to current capacity and deduce how much 'wear' the battery got and expose that as a negative value percentage. Feature sent in August took a while to convince the maintainer many modern batteries provide this information. Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
-rw-r--r--README7
-rw-r--r--widgets/bat.lua18
2 files changed, 15 insertions, 10 deletions
diff --git a/README b/README
index 5f4cdd9..4f1ff50 100644
--- a/README
+++ b/README
@@ -159,11 +159,12 @@ vicious.widgets.uptime
for 5 minutes and 6th for 15 minutes
vicious.widgets.bat
- - provides state, charge, and remaining time for a requested battery
+ - provides state, charge, remaining time and wear for a requested
+ battery
- takes battery ID as an argument, i.e. "BAT0"
- returns 1st value as state of requested battery, 2nd as charge
- level in percent and 3rd as remaining (charging or discharging)
- time
+ level in percent, 3rd as remaining (charging or discharging)
+ time and 4th as the wear level in percent
vicious.widgets.mem
- provides RAM and Swap usage statistics
diff --git a/widgets/bat.lua b/widgets/bat.lua
index 76a9d4c..454e43f 100644
--- a/widgets/bat.lua
+++ b/widgets/bat.lua
@@ -1,6 +1,7 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
+-- * (c) 2013, NormalRa <normalrawr@gmail.com>
---------------------------------------------------
-- {{{ Grab environment
@@ -15,7 +16,7 @@ local math = {
-- }}}
--- Bat: provides state, charge, and remaining time for a requested battery
+-- Bat: provides state, charge, remaining time, and wear for a requested battery
-- vicious.widgets.bat
local bat = {}
@@ -35,7 +36,7 @@ local function worker(format, warg)
-- Check if the battery is present
if battery.present ~= "1\n" then
- return {battery_state["Unknown\n"], 0, "N/A"}
+ return {battery_state["Unknown\n"], 0, "N/A", 0}
end
@@ -45,14 +46,17 @@ local function worker(format, warg)
-- Get capacity information
if battery.charge_now then
remaining, capacity = battery.charge_now, battery.charge_full
+ capacity_design = battery.charge_full_design or capacity
elseif battery.energy_now then
remaining, capacity = battery.energy_now, battery.energy_full
+ capacity_design = battery.energy_full_design or capacity
else
- return {battery_state["Unknown\n"], 0, "N/A"}
+ return {battery_state["Unknown\n"], 0, "N/A", 0}
end
- -- Calculate percentage (but work around broken BAT/ACPI implementations)
+ -- Calculate capacity and wear percentage (but work around broken BAT/ACPI implementations)
local percent = math.min(math.floor(remaining / capacity * 100), 100)
+ local wear = math.floor(100 - capacity / capacity_design * 100)
-- Get charge information
@@ -61,7 +65,7 @@ local function worker(format, warg)
elseif battery.power_now then
rate = tonumber(battery.power_now)
else
- return {state, percent, "N/A"}
+ return {state, percent, "N/A", wear}
end
-- Calculate remaining (charging or discharging) time
@@ -73,7 +77,7 @@ local function worker(format, warg)
elseif state == "-" then
timeleft = tonumber(remaining) / tonumber(rate)
else
- return {state, percent, time}
+ return {state, percent, time, wear}
end
-- Calculate time
@@ -83,7 +87,7 @@ local function worker(format, warg)
time = string.format("%02d:%02d", hoursleft, minutesleft)
end
- return {state, percent, time}
+ return {state, percent, time, wear}
end
-- }}}