[cpufreq_freebsd][fanspeed_freebsd] Deprecate syncronous sysctl

This commit is contained in:
mutlusun 2019-07-31 18:22:49 +02:00
parent 04e8a49d2e
commit d6e21f71d0
No known key found for this signature in database
GPG Key ID: C0AF8F434E1AB79B
3 changed files with 33 additions and 22 deletions

View File

@ -20,7 +20,7 @@ Fixed:
- Deprecate the use of `io.popen` in following widgets:
* wifi_linux, wifiiw_linux, hwmontemp_linux, hddtemp_linux
* bat_freebsd, mem_freebsd, net_freebsd, thermal_freebsd, uptime_freebsd,
cpu_freebsd
cpu_freebsd, cpufreq_freebsd, fanspeed_freebsd
* volume, gmail, mdir, mpd, fs
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
- [pkg,weather,contrib/btc] Allow function call without Awesome

View File

@ -1,6 +1,5 @@
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local helpers = require("vicious.helpers")
-- }}}
@ -11,24 +10,24 @@ local cpufreq_freebsd = {}
-- {{{ CPU frequency widget type
local function worker(format, warg)
if not warg then return end
function cpufreq_freebsd.async(format, warg, callback)
if not warg then return callback({}) end
-- Default frequency and voltage values
local freqv = {
["mhz"] = "N/A", ["ghz"] = "N/A",
["v"] = "N/A", ["mv"] = "N/A",
["governor"] = "N/A",
}
local freq = tonumber(helpers.sysctl("dev.cpu." .. warg .. ".freq"))
helpers.sysctl_async({ "dev.cpu." .. warg .. ".freq" }, function(ret)
freqv.mhz = tonumber(ret["dev.cpu." .. warg .. ".freq"])
freqv.ghz = freqv.mhz / 1000
freqv.mhz = freq
freqv.ghz = freq / 1000
return callback({freqv.mhz, freqv.ghz, freqv.mv, freqv.v, freqv.governor})
end)
local governor = "N/A"
return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor}
end
-- }}}
return setmetatable(cpufreq_freebsd, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall(cpufreq_freebsd)

View File

@ -1,5 +1,4 @@
-- {{{ Grab environment
local setmetatable = setmetatable
local helpers = require("vicious.helpers")
local tonumber = tonumber
-- }}}
@ -10,19 +9,32 @@ local tonumber = tonumber
-- expects one (1) full sysctl string to entry
-- e.g.: "dev.acpi_ibm.0.fan_speed"
-- fanspeed: provides speed level of main fan
-- vicious.widgets.fanspeed
--
-- expects one (1) full sysctl string to entry
-- e.g.: "dev.acpi_ibm.0.fan_speed"
local fanspeed_freebsd = {}
local function worker(format, warg)
if not warg then return end
-- {{{ fanspeed widget type
function fanspeed_freebsd.async(format, warg, callback)
if not warg then return callback({}) end
if type(warg) ~= "table" then warg = { warg } end
local fanspeed = helpers.sysctl(warg)
helpers.sysctl_async(warg, function(ret)
local fanspeed = {}
if not fanspeed then
-- use negative fanspeed to indicate error
return {-1}
else
return {tonumber(fanspeed)}
end
for i=1,#warg do
if ret[warg[i]] ~= nil then
fanspeed[i] = tonumber(ret[warg[i]])
else
fanspeed[i] = "N/A"
end
end
callback(fanspeed)
end)
end
-- }}}
return setmetatable(fanspeed_freebsd, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall(fanspeed_freebsd)