Created
April 20, 2009 17:18
-
-
Save Voker57/98627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- statusd_eee.lua | |
-- | |
-- Public domain | |
-- | |
-- Uses the /proc/acpi interface to get eeePC devices' status | |
-- b is for bluetooth, c is for camera, w is for wifi | |
-- uppercase letter means that device is on, lowercase - off | |
local defaults={ | |
update_interval = 10*1000, | |
} | |
local settings=table.join(statusd.get_config("eee"), defaults) | |
function check_if_one(filename,letter) | |
local f=io.open(filename) | |
if not f then | |
return '' | |
end | |
local statefile=f:read('*a') | |
if not statefile then | |
return '' | |
end | |
f:close() | |
if string.match(statefile, "1") then | |
return string.upper(letter) | |
else | |
return string.lower(letter) | |
end | |
end | |
function get_eee() | |
local result = "" | |
result = result..check_if_one('/sys/class/rfkill/rfkill0/state','w') | |
result = result..check_if_one('/sys/devices/platform/eeepc/camera','c') | |
result = result..check_if_one('/sys/class/rfkill/rfkill1/state','b') | |
return result; | |
end | |
function update_eee() | |
local state = get_eee() | |
statusd.inform("eee", state) | |
eee_timer:set(settings.update_interval, update_eee) | |
end | |
eee_timer = statusd.create_timer() | |
update_eee() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- statusd_linuxbatt.lua | |
-- | |
-- Public domain | |
-- | |
-- Uses the /proc/acpi interface to get battery percentage. | |
-- | |
-- Use the key "linuxbatt" to get the battery percentage; use | |
-- "linuxbatt_state" to get a symbol indicating charging "+", | |
-- discharging "-", or charged " ". | |
-- | |
-- Now uses lua functions instead of bash, awk, dc. MUCH faster! | |
-- | |
-- Hacked to make it work with new kernels (with interface moved to /sys) | |
-- Rename to statusd_linuxbatt.lua to use | |
-- | |
-- The "bat" option to the statusd settings for linuxbatt modifies which | |
-- battery we look at. | |
local defaults={ | |
update_interval=15*1000, | |
bat=0, | |
important_threshold=30, | |
critical_threshold=10, | |
} | |
local settings=table.join(statusd.get_config("linuxbatt"), defaults) | |
function linuxbatt_do_find_capacity() | |
local f=io.open('/sys/class/power_supply/BAT'.. settings.bat ..'/charge_full') | |
local infofile=f:read('*a') | |
f:close() | |
local i, j, capacity = string.find(infofile, '(%d+)') | |
return capacity | |
end | |
local capacity = linuxbatt_do_find_capacity() | |
function get_linuxbatt() | |
local f=io.open('/sys/class/power_supply/BAT'.. settings.bat ..'/charge_now') | |
local statefile = f:read('*a') | |
f:close(); | |
local i, j, remaining = string.find(statefile, '(%d+)') | |
local percent = math.floor( remaining * 100 / capacity ) | |
f=io.open('/sys/class/power_supply/BAT'.. settings.bat ..'/status') | |
local statename=f:read('*a') | |
f:close() | |
if statename == "Charging\n" then | |
return percent, "+" | |
elseif statename == "Discharging\n" then | |
return percent, "-" | |
else | |
return percent, " " | |
end | |
end | |
function update_linuxbatt() | |
local perc, state = get_linuxbatt() | |
statusd.inform("linuxbatt", tostring(perc)) | |
statusd.inform("linuxbatt_state", state) | |
if perc < settings.critical_threshold | |
then statusd.inform("linuxbatt_hint", "critical") | |
elseif perc < settings.important_threshold | |
then statusd.inform("linuxbatt_hint", "important") | |
else statusd.inform("linuxbatt_hint", "normal") | |
end | |
linuxbatt_timer:set(settings.update_interval, update_linuxbatt) | |
end | |
linuxbatt_timer = statusd.create_timer() | |
update_linuxbatt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment