cpufreq: widget rewritten, governor symbols enabled

This commit is contained in:
Adrian C. (anrxc) 2009-11-11 03:15:56 +01:00
parent 5f9818f9d3
commit a99c1cf118
1 changed files with 20 additions and 34 deletions

View File

@ -5,12 +5,9 @@
-- {{{ Grab environment -- {{{ Grab environment
local tonumber = tonumber local tonumber = tonumber
local io = { open = io.open }
local setmetatable = setmetatable local setmetatable = setmetatable
local string = { local string = { match = string.match }
find = string.find, local helpers = require("vicious.helpers")
match = string.match
}
-- }}} -- }}}
@ -20,50 +17,39 @@ module("vicious.cpufreq")
-- {{{ CPU frequency widget type -- {{{ CPU frequency widget type
local function worker(format, cpuid) local function worker(format, cpuid)
--local governor_state = { local cpufreq = setmetatable(
-- ["ondemand"] = "↯", { _path = "/sys/devices/system/cpu/"..cpuid.."/cpufreq"},
-- ["powersave"] = "⌁", helpers.pathtotable
-- ["userspace"] = "°", )
-- ["performance"] = "⚡",
-- ["conservative"] = "↯"
--}
local governor_state = {
["ondemand\n"] = "",
["powersave\n"] = "",
["userspace\n"] = "@",
["performance\n"] = "",
["conservative\n"] = ""
}
-- Default voltage values -- Default voltage values
local voltage = { v = "N/A", mv = "N/A" } local voltage = { v = "N/A", mv = "N/A" }
-- Get the current frequency -- Get the current frequency
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_cur_freq") local freq = tonumber(cpufreq.scaling_cur_freq)
local freq = f:read("*line")
f:close()
-- Calculate MHz and GHz -- Calculate MHz and GHz
local freqmhz = freq / 1000 local freqmhz = freq / 1000
local freqghz = freqmhz / 1000 local freqghz = freqmhz / 1000
-- Get the current voltage -- Get the current voltage
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_voltages") if cpufreq.scaling_voltages then
if f then for line in f:lines() do voltage.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
if string.find(line, "^"..freq) then
voltage.mv = tonumber(string.match(line, "[%d]+[%s]([%d]+)"))
break
end
end
f:close()
-- Calculate voltage from mV -- Calculate voltage from mV
voltage.v = voltage.mv / 1000 voltage.v = voltage.mv / 1000
end end
-- Get the current governor -- Get the current governor
local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_governor") local governor = cpufreq.scaling_governor
local governor = f:read("*line")
f:close()
-- Represent the governor as a symbol -- 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} return {freqmhz, freqghz, voltage.mv, voltage.v, governor}
end end