1 -- Authors: Relu Patrascu
2 -- License: LGPL, version 2.1 or later
3 -- Last Changed: 2004-11-05
7 -- Copyright (c) Relu Patrascu 2004.
9 -- Ion is free software; you can redistribute it and/or modify it under
10 -- the terms of the GNU Lesser General Public License as published by
11 -- the Free Software Foundation; either version 2.1 of the License, or
12 -- (at your option) any later version.
16 -- Neither am I a lua expert nor do I have the time to invest in writing
17 -- better code here. I simply needed this utility and it works OK for me.
18 -- I give no guarantees of any kind for this code. Suggestions for
19 -- improvement are welcome.
20 -- ikoflexer at gmail dot com
22 if not statusd_batt
then
23 statusd_batt
={ interval
=10*1000 }
27 local function get_batt_procapm()
28 local f
=io
.open('/proc/apm', 'r')
34 local st
, en
, battInfoStr
= string.find(s
, '(%d+%% [-]*%d+ [%?]*[%a]*)$')
35 battInfoStr
= string.gsub(battInfoStr
, '-1.*',"-(= ")
36 return tostring(battInfoStr
)
39 local function get_batt_fn()
40 return get_batt_procapm
43 local get_batt
, batt_timer
45 local function update_batt()
46 statusd
.inform("batt", get_batt())
47 batt_timer
:set(statusd_batt
.interval
, update_batt
)
51 get_batt
=get_batt_fn()
52 batt_timer
=statusd
.create_timer()