massive update, probably broken
[dotfiles/.git] / .config / awesome / lain / widget / temp.lua
1 --[[
2
3      Licensed under GNU General Public License v2
4       * (c) 2013, Luca CPZ
5
6 --]]
7
8 local helpers  = require("lain.helpers")
9 local wibox    = require("wibox")
10 local tonumber = tonumber
11
12 -- {thermal,core} temperature info
13 -- lain.widget.temp
14
15 local function factory(args)
16     local temp     = { widget = wibox.widget.textbox() }
17     local args     = args or {}
18     local timeout  = args.timeout or 30
19     local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp"
20     local settings = args.settings or function() end
21
22     function temp.update()
23         helpers.async({"find", "/sys/devices", "-type", "f", "-name", "*temp*"}, function(f)
24             temp_now = {}
25             local temp_fl, temp_value
26             for t in f:gmatch("[^\n]+") do
27                 temp_fl = helpers.first_line(t)
28                 if temp_fl then
29                     temp_value = tonumber(temp_fl)
30                     temp_now[t] = temp_value and temp_value/1e3 or temp_fl
31                 end
32             end
33             coretemp_now = temp_now[tempfile] or "N/A"
34             widget = temp.widget
35             settings()
36         end)
37     end
38
39     helpers.newtimer("thermal", timeout, temp.update)
40
41     return temp
42 end
43
44 return factory