[PATCH] extended current version of the battery plugin

0 views
Skip to first unread message

que...@gmail.com

unread,
Oct 23, 2008, 5:03:47 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <qu...@informatik.uni-oldenburg.de>

- added displaying of the current charging/discharging rate
- calculate and display remaining charging/discharging time
---
plugins/battery.lua | 26 +++++++++++++++++++++++++-
1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/plugins/battery.lua b/plugins/battery.lua
index c5eec45..e3bcf89 100644
--- a/plugins/battery.lua
+++ b/plugins/battery.lua
@@ -244,7 +244,31 @@ local function update_single_battery ( battery )
batt_state = "v"
end

- printout = batt_state .. string.format("%.0f",batt_percent) .. batt_state
+ local batt_rate = batt:match('present rate:%s+(%d+)') * 1
+
+ local batt_time = "inf"
+ if batt_rate > 0 then
+ if batt_state == "^" then
+ batt_time = (battinfo:match('last full capacity:%s+(%d+)') - batt:match('remaining capacity:%s+(%d+)')) / batt_rate
+ else
+ batt_time = batt:match('remaining capacity:%s+(%d+)') / batt_rate
+ end
+ local hour = string.format("%d",batt_time)
+ local min = (batt_time - hour) * 60
+
+ if min > 59 then
+ min = min - 60
+ hour = hour + 1
+ end
+ if min < 0 then
+ min = 0
+ end
+ batt_time = hour .. ':'
+ batt_time = batt_time .. string.format("%.2d",min)
+ end
+
+ batt_rate = batt_rate/1000
+ printout = string.format("%.2f",batt_rate) .. 'W -> ' .. batt_time .. '(' .. batt_state .. string.format("%.0f",batt_percent) .. batt_state .. ')'

battery["widget"]:show(printout, colors)
end
--
1.6.0.2

Bart Trojanowski

unread,
Oct 23, 2008, 8:56:21 PM10/23/08
to wmii...@googlegroups.com, Jan-David Quesel
* que...@gmail.com <que...@gmail.com> [081023 05:03]:

> - added displaying of the current charging/discharging rate
> - calculate and display remaining charging/discharging time

I really like this, but I think it's too verbose to display the wattage.

Could we have that configurable? Can we drop the -> ?

> + batt_time = (battinfo:match('last full capacity:%s+(%d+)') - batt:match('remaining capacity:%s+(%d+)')) / batt_rate

When I first read this I was going to say: please add some error
checking.

> + batt_time = batt:match('remaining capacity:%s+(%d+)') / batt_rate

It even divides by 0 :)

Thanks,
-Bart

--
WebSig: http://www.jukie.net/~bart/sig/

Jan-David Quesel

unread,
Oct 24, 2008, 8:32:32 AM10/24/08
to wmii...@googlegroups.com

it doesnt. there is a check if batt_rate is greater than zero
before that line. otherwise it just displays inf.

mfg
Jan

--
Jan-David Quesel
Carl von Ossietzky Universität Oldenburg
Department of Computing Science
Correct System Design
D-26111 Oldenburg, Germany

Phone: +49 (0)441 798-2376
Fax: +49 (0)441 798-2965

Reply all
Reply to author
Forward
0 new messages