aboutsummaryrefslogtreecommitdiff
path: root/thermal.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-11 02:57:30 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-11 02:57:30 +0100
commit92be5fbae59b5d63c09f35f435a2738cdcb3a953 (patch)
tree001075aea0ad4c075daf09896d8b1e734c937ede /thermal.lua
parent46d52face802ee3b29f1b85455e59fb19442eada (diff)
downloadvicious-legacy-92be5fbae59b5d63c09f35f435a2738cdcb3a953.tar.xz
thermal: widget rewritten for sysfs
Default path is set to /sys/class/thermal but at least it's easier to switch to /sys/class/hwmon (i.e. coretemp) now without much code modification. Note; zone IDs are probably different than those in /proc/acpi/thermal_zone
Diffstat (limited to 'thermal.lua')
-rw-r--r--thermal.lua21
1 files changed, 10 insertions, 11 deletions
diff --git a/thermal.lua b/thermal.lua
index 6eff3d0..f8b174e 100644
--- a/thermal.lua
+++ b/thermal.lua
@@ -4,10 +4,8 @@
---------------------------------------------------
-- {{{ Grab environment
-local tonumber = tonumber
-local io = { open = io.open }
local setmetatable = setmetatable
-local string = { match = string.match }
+local helpers = require("vicious.helpers")
-- }}}
@@ -17,16 +15,17 @@ module("vicious.thermal")
-- {{{ Thermal widget type
local function worker(format, thermal_zone)
- -- Get an ACPI thermal zone
- local f = io.open("/proc/acpi/thermal_zone/"..thermal_zone.."/temperature")
- -- Handler for incompetent users
- if not f then return {0} end
- local line = f:read("*line")
- f:close()
+ local thermal = setmetatable(
+ { _path = "/sys/class/thermal/" .. thermal_zone },
+ helpers.pathtotable
+ )
- local temperature = tonumber(string.match(line, "[%d]?[%d]?[%d]"))
+ -- Get ACPI thermal zone
+ if thermal.temp then
+ return {thermal.temp / 1000}
+ end
- return {temperature}
+ return {0}
end
-- }}}