From fbd91c9b37f7006b14d62aa7d9403b0028c6560b Mon Sep 17 00:00:00 2001 From: mutlusun Date: Wed, 25 Jan 2017 17:49:37 +0100 Subject: [PATCH] port cpufreq widget to freebsd --- widgets/cpufreq_freebsd.lua | 34 ++++++++++++++++++++++ widgets/{cpufreq.lua => cpufreq_linux.lua} | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 widgets/cpufreq_freebsd.lua rename widgets/{cpufreq.lua => cpufreq_linux.lua} (93%) diff --git a/widgets/cpufreq_freebsd.lua b/widgets/cpufreq_freebsd.lua new file mode 100644 index 0000000..351cc68 --- /dev/null +++ b/widgets/cpufreq_freebsd.lua @@ -0,0 +1,34 @@ +-- {{{ Grab environment +local tonumber = tonumber +local setmetatable = setmetatable +local helpers = require("vicious.helpers") +-- }}} + + +-- Cpufreq: provides freq, voltage and governor info for a requested CPU +-- vicious.widgets.cpufreq +local cpufreq_freebsd = {} + + +-- {{{ CPU frequency widget type +local function worker(format, warg) + if not warg then return end + + -- Default frequency and voltage values + local freqv = { + ["mhz"] = "N/A", ["ghz"] = "N/A", + ["v"] = "N/A", ["mv"] = "N/A", + } + + local freq = tonumber(helpers.sysctl("dev.cpu." .. warg .. ".freq")) + + freqv.mhz = freq + freqv.ghz = freq / 1000 + + local governor = "N/A" + + return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor} +end +-- }}} + +return setmetatable(cpufreq_freebsd, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpufreq.lua b/widgets/cpufreq_linux.lua similarity index 93% rename from widgets/cpufreq.lua rename to widgets/cpufreq_linux.lua index 39470a4..4cac998 100644 --- a/widgets/cpufreq.lua +++ b/widgets/cpufreq_linux.lua @@ -13,7 +13,7 @@ local helpers = require("vicious.helpers") -- Cpufreq: provides freq, voltage and governor info for a requested CPU -- vicious.widgets.cpufreq -local cpufreq = {} +local cpufreq_linux = {} -- {{{ CPU frequency widget type @@ -58,4 +58,4 @@ local function worker(format, warg) end -- }}} -return setmetatable(cpufreq, { __call = function(_, ...) return worker(...) end }) +return setmetatable(cpufreq_linux, { __call = function(_, ...) return worker(...) end })