2017-12-01 00:21:33 -06:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local type = type
|
|
|
|
local tonumber = tonumber
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = { match = string.match }
|
|
|
|
local helpers = require("vicious.helpers")
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Thermal: provides temperature levels of ACPI and coretemp thermal zones
|
|
|
|
-- vicious.widgets.thermal
|
|
|
|
local thermal = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ Thermal widget type
|
|
|
|
local function worker(format, warg)
|
2018-05-18 22:36:34 -05:00
|
|
|
if not warg then return end
|
2017-12-17 12:06:39 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
local zone = { -- Known temperature data sources
|
2017-12-17 12:06:39 -06:00
|
|
|
["sys"] = {"/sys/class/thermal/", file = "temp", div = 1000},
|
|
|
|
["core"] = {"/sys/devices/platform/", file = "temp2_input",div = 1000},
|
|
|
|
["proc"] = {"/proc/acpi/thermal_zone/",file = "temperature"}
|
2018-05-18 22:36:34 -05:00
|
|
|
} -- Default to /sys/class/thermal
|
|
|
|
warg = type(warg) == "table" and warg or { warg, "sys" }
|
2017-12-17 12:06:39 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Get temperature from thermal zone
|
|
|
|
local _thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
|
2017-12-17 12:06:39 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
local data = warg[3] and _thermal[warg[3]] or _thermal[zone[warg[2]].file]
|
|
|
|
if data then
|
2017-12-17 12:06:39 -06:00
|
|
|
if zone[warg[2]].div then
|
2018-05-18 22:36:34 -05:00
|
|
|
return {data / zone[warg[2]].div}
|
2017-12-17 12:06:39 -06:00
|
|
|
else -- /proc/acpi "temperature: N C"
|
2018-05-18 22:36:34 -05:00
|
|
|
return {tonumber(string.match(data, "[%d]+"))}
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
2018-05-18 22:36:34 -05:00
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
return {0}
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return setmetatable(thermal, { __call = function(_, ...) return worker(...) end })
|