1 -- Authors: Greg Steuck, Darrin Chandler <dwchandler@stilyagin.com>
2 -- License: Public domain
3 -- Last Changed: 2006-10-28
5 -- Adds capability for OpenBSD APM info in ion3 statusbar.
7 -- Originally written by Greg Steuck and released into the Public Domain
8 -- 2006-10-28 modified by Darrin Chandler <dwchandler@stilyagin.com>
9 -- to work with OpenBSD 4.0 apm output.
12 -- Save this file as ~/.ion3/statusd_apm.lua,
13 -- Change ~/.ion3/cfg_statusbar.lua like so:
14 -- Add "apm={}," to mod_statusbar.launch_statusd,
15 -- Modify "template" to include %apm_ variables
16 -- e.g. template="[ %date || load:% %>load || bat: %apm_pct%%, A/C %apm_ac ],"
18 -- Available variables:
19 -- %apm_state high, low, critical
20 -- %apm_pct battery life (in percent)
21 -- %apm_estimate battery life (in minutes)
22 -- %apm_ac External A/C charger state
23 -- %apm_mode Adjustment mode (manual, auto, cool running)
24 -- %apm_speed CPU speed
26 local unknown
= "?", "?", "?", "?", "?", "?"
29 local f
=io
.popen('/usr/sbin/apm', 'r')
33 local s
=f
:read('*all')
35 local _
, _
, state
, pct
, estimate
, ac
, mode
, speed
=
36 string.find(s
, "Battery state: (%S+), "..
37 "(%d+)%% remaining, "..
38 "([0-9]*) minutes life estimate\n"..
39 "A/C adapter state: ([^\n]*)\n"..
40 "Performance adjustment mode:%s(.+)%s"..
47 return state
, pct
, estimate
, ac
, mode
, speed
50 local function inform(key
, value
)
51 statusd
.inform("apm_"..key
, value
)
56 local function update_apm()
57 local state
, pct
, estimate
, ac
, mode
, speed
= get_apm()
59 if statusd
~= nil then
60 inform("state", state
)
62 inform("estimate", estimate
)
63 if state
== "high" then
65 elseif state
== "low" then
71 inform("state_hint", hint
)
72 inform("pct_hint", hint
)
73 inform("estimate_hint", hint
)
76 if ac
== "connected" then
81 inform("ac_hint", hint
)
83 inform("speed", speed
)
84 apm_timer
:set(30*1000, update_apm
)
86 io
.stdout
:write("Batt: "..pct
.."% ("..state
..
87 ", "..estimate
.." mins)\n"..
89 "Mode: "..mode
.."\n"..
90 "CPU Speed: "..speed
.."\n"
95 if statusd
~= nil then
96 apm_timer
= statusd
.create_timer()