diff --git a/Changes.md b/Changes.md index de6da4a..403d325 100644 --- a/Changes.md +++ b/Changes.md @@ -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 diff --git a/widgets/cpufreq_freebsd.lua b/widgets/cpufreq_freebsd.lua index 351cc68..c53e2d7 100644 --- a/widgets/cpufreq_freebsd.lua +++ b/widgets/cpufreq_freebsd.lua @@ -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) diff --git a/widgets/fanspeed_freebsd.lua b/widgets/fanspeed_freebsd.lua index 774b0da..b8d1a60 100644 --- a/widgets/fanspeed_freebsd.lua +++ b/widgets/fanspeed_freebsd.lua @@ -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)