aboutsummaryrefslogtreecommitdiff
path: root/widgets/cpufreq.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-14 01:55:33 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-14 01:55:33 +0100
commit237470c8f45190b213e3a173ce6ae1a74b3e11fe (patch)
tree7f53c8144761947d4bde20715bcad34f4be0d6c0 /widgets/cpufreq.lua
parent9a82d4113a8271b7dfc7506f2b07379e3ede89a8 (diff)
downloadvicious-legacy-237470c8f45190b213e3a173ce6ae1a74b3e11fe.tar.xz
API: transform widgets namespace table to a directory
Diffstat (limited to 'widgets/cpufreq.lua')
-rw-r--r--widgets/cpufreq.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/widgets/cpufreq.lua b/widgets/cpufreq.lua
new file mode 100644
index 0000000..7f60f5a
--- /dev/null
+++ b/widgets/cpufreq.lua
@@ -0,0 +1,54 @@
+---------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
+---------------------------------------------------
+
+-- {{{ Grab environment
+local tonumber = tonumber
+local setmetatable = setmetatable
+local string = { match = string.match }
+local helpers = require("vicious.helpers")
+-- }}}
+
+
+-- Cpufreq: provides freq, voltage and governor info for a requested CPU
+module("vicious.widgets.cpufreq")
+
+
+-- {{{ CPU frequency widget type
+local function worker(format, cpuid)
+ local cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..cpuid.."/cpufreq")
+ local governor_state = {
+ ["ondemand\n"] = "↯",
+ ["powersave\n"] = "⌁",
+ ["userspace\n"] = "¤",
+ ["performance\n"] = "⚡",
+ ["conservative\n"] = "↯"
+ }
+ -- Default voltage values
+ local voltage = { v = "N/A", mv = "N/A" }
+
+
+ -- Get the current frequency
+ local freq = tonumber(cpufreq.scaling_cur_freq)
+ -- Calculate MHz and GHz
+ local freqmhz = freq / 1000
+ local freqghz = freqmhz / 1000
+
+ -- Get the current voltage
+ if cpufreq.scaling_voltages then
+ voltage.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
+ -- Calculate voltage from mV
+ voltage.v = voltage.mv / 1000
+ end
+
+ -- Get the current governor
+ local governor = cpufreq.scaling_governor
+ -- Represent the governor as a symbol
+ governor = governor_state[governor] or governor
+
+ return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })