From 92be5fbae59b5d63c09f35f435a2738cdcb3a953 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 11 Nov 2009 02:57:30 +0100 Subject: 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 --- README | 2 +- thermal.lua | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README b/README index 845e647..f9febff 100644 --- a/README +++ b/README @@ -149,7 +149,7 @@ vicious.widgets.cpufreq vicious.widgets.thermal - provides temperature levels of ACPI thermal zones - - takes the thermal zone as an argument, i.e. "TZS0" + - takes the thermal zone as an argument, i.e. "thermal_zone0" - returns 1st value as temperature of requested thermal zone vicious.widgets.load 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 -- }}} -- cgit v1.2.3