From a99c1cf118b4423925473e2f29b75fdbbc2dce87 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Wed, 11 Nov 2009 03:15:56 +0100 Subject: cpufreq: widget rewritten, governor symbols enabled --- cpufreq.lua | 56 +++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'cpufreq.lua') diff --git a/cpufreq.lua b/cpufreq.lua index 1fcd643..7718a52 100644 --- a/cpufreq.lua +++ b/cpufreq.lua @@ -5,12 +5,9 @@ -- {{{ Grab environment local tonumber = tonumber -local io = { open = io.open } local setmetatable = setmetatable -local string = { - find = string.find, - match = string.match -} +local string = { match = string.match } +local helpers = require("vicious.helpers") -- }}} @@ -20,50 +17,39 @@ module("vicious.cpufreq") -- {{{ CPU frequency widget type local function worker(format, cpuid) - --local governor_state = { - -- ["ondemand"] = "↯", - -- ["powersave"] = "⌁", - -- ["userspace"] = "°", - -- ["performance"] = "⚡", - -- ["conservative"] = "↯" - --} - + local cpufreq = setmetatable( + { _path = "/sys/devices/system/cpu/"..cpuid.."/cpufreq"}, + helpers.pathtotable + ) + + 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 f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_cur_freq") - local freq = f:read("*line") - f:close() - + local freq = tonumber(cpufreq.scaling_cur_freq) -- Calculate MHz and GHz local freqmhz = freq / 1000 local freqghz = freqmhz / 1000 - -- Get the current voltage - local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_voltages") - if f then for line in f:lines() do - if string.find(line, "^"..freq) then - voltage.mv = tonumber(string.match(line, "[%d]+[%s]([%d]+)")) - break - end - end - f:close() - - -- Calculate voltage from mV - voltage.v = voltage.mv / 1000 + 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 f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_governor") - local governor = f:read("*line") - f:close() - + local governor = cpufreq.scaling_governor -- Represent the governor as a symbol - --local governor = governor_state[governor] or governor + governor = governor_state[governor] or governor return {freqmhz, freqghz, voltage.mv, voltage.v, governor} end -- cgit v1.2.3