]> git.madduck.net Git - etc/awesome.git/blob - widgets/temp.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

#293: eradicate proxy widget
[etc/awesome.git] / widgets / temp.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6                                                   
7 --]]
8
9 local helpers      = require("lain.helpers")
10 local wibox        = require("wibox")
11 local io           = { open = io.open }
12 local tonumber     = tonumber
13 local setmetatable = setmetatable
14
15 -- coretemp
16 -- lain.widgets.temp
17 local temp = {}
18
19 local function worker(args)
20     local args     = args or {}
21     local timeout  = args.timeout or 2
22     local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp"
23     local settings = args.settings or function() end
24
25     temp.widget = wibox.widget.textbox()
26
27     function update()
28         local f = io.open(tempfile)
29         if f then
30             coretemp_now = tonumber(f:read("*all")) / 1000
31             f:close()
32         else
33             coretemp_now = "N/A"
34         end
35
36         widget = temp.widget
37         settings()
38     end
39
40     helpers.newtimer("coretemp", timeout, update)
41
42     return temp
43 end
44
45 return setmetatable(temp, { __call = function(_, ...) return worker(...) end })