thermal: added support for procfs and coretemp
Widget type now takes the thermal zone as an argument, or a table with 1st field as thermal zone and 2nd field as data source. Available data sources are: "proc" (procfs ACPI), "sys" (sysfs like before) and "core" (sysfs coretemp). When only the thermal zone is provided widget defaults to "sys".
This commit is contained in:
parent
355c838555
commit
6c34e8532e
7
README
7
README
|
@ -148,8 +148,11 @@ vicious.widgets.cpufreq
|
||||||
governor state
|
governor state
|
||||||
|
|
||||||
vicious.widgets.thermal
|
vicious.widgets.thermal
|
||||||
- provides temperature levels of ACPI thermal zones
|
- provides temperature levels of ACPI and coretemp thermal zones
|
||||||
- takes the thermal zone as an argument, i.e. "thermal_zone0"
|
- takes the thermal zone as an argument, i.e. "thermal_zone0", or a
|
||||||
|
table with 1st field as thermal zone and 2nd as data source -
|
||||||
|
available data sources are "proc", "core" and "sys" - which is the
|
||||||
|
default when only the zone is provided
|
||||||
- returns 1st value as temperature of requested thermal zone
|
- returns 1st value as temperature of requested thermal zone
|
||||||
|
|
||||||
vicious.widgets.uptime
|
vicious.widgets.uptime
|
||||||
|
|
26
thermal.lua
26
thermal.lua
|
@ -4,22 +4,36 @@
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
|
local type = type
|
||||||
|
local tonumber = tonumber
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
local string = { match = string.match }
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
-- Thermal: provides temperature levels of ACPI thermal zones
|
-- Thermal: provides temperature levels of ACPI and coretemp thermal zones
|
||||||
module("vicious.thermal")
|
module("vicious.thermal")
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Thermal widget type
|
-- {{{ Thermal widget type
|
||||||
local function worker(format, thermal_zone)
|
local function worker(format, warg)
|
||||||
local thermal = helpers.pathtotable("/sys/class/thermal/"..thermal_zone)
|
-- Known temperature data sources
|
||||||
|
local zone = {
|
||||||
|
["sys"] = {"/sys/class/thermal/", file = "temp", div = 1000},
|
||||||
|
["core"] = {"/sys/devices/platform/", file = "temp1_input",div = 1000},
|
||||||
|
["proc"] = {"/proc/acpi/thermal_zone/",file = "temperature"}
|
||||||
|
} -- Default to /sys/class/thermal
|
||||||
|
local warg = type(warg) == "table" and warg or {warg, "sys"}
|
||||||
|
local thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
|
||||||
|
|
||||||
-- Get ACPI thermal zone
|
-- Get temperature from thermal zone
|
||||||
if thermal.temp then
|
if thermal[zone[warg[2]].file] then
|
||||||
return {thermal.temp / 1000}
|
if zone[warg[2]].div then
|
||||||
|
return {thermal[zone[warg[2]].file] / zone[warg[2]].div}
|
||||||
|
else -- /proc/acpi "temperature: N C"
|
||||||
|
return {tonumber(string.match(thermal[zone[warg[2]].file], "[%d]+"))}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {0}
|
return {0}
|
||||||
|
|
Loading…
Reference in New Issue