2013-09-07 12:06:42 +02:00
|
|
|
--[[
|
2017-09-04 12:43:00 +02:00
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
2017-09-11 06:51:52 +02:00
|
|
|
* (c) 2013, Luca CPZ
|
2017-09-04 12:43:00 +02:00
|
|
|
|
2013-09-07 12:06:42 +02:00
|
|
|
--]]
|
|
|
|
|
2022-03-22 19:45:38 +01:00
|
|
|
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
2017-04-02 19:35:03 +02:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local tonumber = tonumber
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2019-05-29 16:28:38 +02:00
|
|
|
-- {thermal,core} temperature info
|
2017-02-08 14:15:48 +01:00
|
|
|
-- lain.widget.temp
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2017-02-08 20:45:11 +01:00
|
|
|
local function factory(args)
|
2020-11-29 22:48:32 +01:00
|
|
|
args = args or {}
|
|
|
|
|
2020-10-31 18:11:29 +01:00
|
|
|
local temp = { widget = args.widget or wibox.widget.textbox() }
|
2019-05-29 16:28:38 +02:00
|
|
|
local timeout = args.timeout or 30
|
|
|
|
local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp"
|
2022-03-15 17:17:01 +01:00
|
|
|
local format = args.format or "%.1f"
|
2019-05-29 16:28:38 +02:00
|
|
|
local settings = args.settings or function() end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2017-01-27 14:35:27 +01:00
|
|
|
function temp.update()
|
2019-08-27 18:08:37 +02:00
|
|
|
helpers.async({"find", "/sys/devices", "-type", "f", "-name", "*temp*"}, function(f)
|
2019-05-27 14:12:00 +02:00
|
|
|
temp_now = {}
|
2019-05-29 16:28:38 +02:00
|
|
|
local temp_fl, temp_value
|
2019-05-27 14:12:00 +02:00
|
|
|
for t in f:gmatch("[^\n]+") do
|
2019-05-29 16:28:38 +02:00
|
|
|
temp_fl = helpers.first_line(t)
|
|
|
|
if temp_fl then
|
|
|
|
temp_value = tonumber(temp_fl)
|
|
|
|
temp_now[t] = temp_value and temp_value/1e3 or temp_fl
|
2019-05-27 14:12:00 +02:00
|
|
|
end
|
|
|
|
end
|
2022-03-26 18:58:50 +01:00
|
|
|
if temp_now[tempfile] then
|
2022-06-11 11:26:23 +02:00
|
|
|
coretemp_now = string.format(format, temp_now[tempfile])
|
2022-03-26 18:58:50 +01:00
|
|
|
else
|
|
|
|
coretemp_now = "N/A"
|
|
|
|
end
|
2019-05-27 14:12:00 +02:00
|
|
|
widget = temp.widget
|
|
|
|
settings()
|
|
|
|
end)
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2019-05-27 14:12:00 +02:00
|
|
|
helpers.newtimer("thermal", timeout, temp.update)
|
2016-03-03 12:40:49 +01:00
|
|
|
|
2017-01-25 17:13:14 +01:00
|
|
|
return temp
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2017-04-02 19:35:03 +02:00
|
|
|
return factory
|