2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Licensed under GNU General Public License v2
|
|
|
|
* (c) 2013, Luke Bonham
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2013-09-10 23:02:11 +02:00
|
|
|
local newtimer = require("lain.helpers").newtimer
|
2013-09-07 12:06:42 +02:00
|
|
|
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
2014-08-08 14:25:21 +02:00
|
|
|
local io = { open = io.open }
|
2013-09-07 12:06:42 +02:00
|
|
|
local tonumber = tonumber
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
|
|
-- coretemp
|
|
|
|
-- lain.widgets.temp
|
|
|
|
local temp = {}
|
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
local function worker(args)
|
2013-09-10 23:02:11 +02:00
|
|
|
local args = args or {}
|
2015-07-12 11:22:10 +02:00
|
|
|
local timeout = args.timeout or 2
|
2014-01-21 16:01:28 +01:00
|
|
|
local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp"
|
2013-09-10 23:02:11 +02:00
|
|
|
local settings = args.settings or function() end
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
temp.widget = wibox.widget.textbox('')
|
2013-09-07 12:06:42 +02:00
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
function update()
|
2014-01-21 16:01:28 +01:00
|
|
|
local f = io.open(tempfile)
|
2014-01-04 12:23:24 +01:00
|
|
|
if f ~= nil
|
|
|
|
then
|
2015-07-26 00:59:23 +02:00
|
|
|
coretemp_now = tonumber(f:read("*all")) / 1000
|
2014-01-04 12:23:24 +01:00
|
|
|
f:close()
|
|
|
|
else
|
|
|
|
coretemp_now = "N/A"
|
|
|
|
end
|
|
|
|
|
2013-09-11 19:39:14 +02:00
|
|
|
widget = temp.widget
|
2013-09-10 23:02:11 +02:00
|
|
|
settings()
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
2013-09-13 00:07:44 +02:00
|
|
|
newtimer("coretemp", timeout, update)
|
2013-09-11 19:39:14 +02:00
|
|
|
return temp.widget
|
2013-09-07 12:06:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(temp, { __call = function(_, ...) return worker(...) end })
|