temp.lua 1.2 KB

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