Debian Codegraph @

vicious/widgets/thermal_linux.lua

raw symbols SCIP
1 -- temperature widget type for GNU/Linux
2 -- Copyright (C) 2010 Adrian C. <[email protected]>
3 -- Copyright (C) 2017 mutlusun <[email protected]>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
21 local type = type
22 local tonumber = tonumber
23 local string = { match = string.match }
24 local math = { floor = math.floor }
25 local helpers = require("vicious.helpers")
26 -- }}}
27
28 -- {{{ Thermal widget type
29 return helpers.setcall(function (format, warg)
30 if not warg then return end
31
32 local zone = { -- Known temperature data sources
33 ["sys"] = {"/sys/class/thermal/", file = "temp", div = 1000},
34 ["core"] = {"/sys/devices/platform/", file = "temp2_input",div = 1000},
35 ["hwmon"] = {"/sys/class/hwmon/", file = "temp1_input",div = 1000},
36 ["proc"] = {"/proc/acpi/thermal_zone/",file = "temperature"}
37 } -- Default to /sys/class/thermal
38 warg = type(warg) == "table" and warg or { warg, "sys" }
39
40 -- Get temperature from thermal zone
41 local _thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
42
43 local data = warg[3] and _thermal[warg[3]] or _thermal[zone[warg[2]].file]
44 if data then
45 if zone[warg[2]].div then
46 return {math.floor(data / zone[warg[2]].div)}
47 else -- /proc/acpi "temperature: N C"
48 return {tonumber(string.match(data, "[%d]+"))}
49 end
50 end
51
52 return {0}
53 end)
54 -- }}}