File: statusd_batt.lua

package info (click to toggle)
ion3-scripts 20050418-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 300 kB
  • ctags: 153
  • sloc: makefile: 18
file content (50 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- statusd_batt.lua
-- 
-- Copyright (c) Relu Patrascu 2004.
--
-- Ion is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation; either version 2.1 of the License, or
-- (at your option) any later version.
--
-- Nov. 5, 2004
-- Disclaimer
-- Neither am I a lua expert nor do I have the time to invest in writing
-- better code here.  I simply needed this utility and it works OK for me.
-- I give no guarantees of any kind for this code.  Suggestions for
-- improvement are welcome.
-- ikoflexer at gmail dot com

local settings={
    interval=10*1000,
}

local battInfoStr
local function get_batt_procapm()
    local f=io.open('/proc/apm', 'r')
    if not f then
        return ""
    end
    local s=f:read('*l')
    f:close()
    local st, en, battInfoStr = string.find(s, '(%d+%% [-]*%d+ [%?]*[%a]*)$')
    battInfoStr = string.gsub(battInfoStr, '-1.*',"-(= ")
    return tostring(battInfoStr)
end

local function get_batt_fn()
	return get_batt_procapm
end

local get_batt, batt_timer

local function update_batt()
    statusd.inform("batt", get_batt())
    batt_timer:set(settings.interval, update_batt)
end

-- Init
get_batt=get_batt_fn()
batt_timer=statusd.create_timer()
update_batt()