diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-02 20:21:21 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-10-02 20:21:21 +0200 |
commit | 44f95c3651b145c9df9154c639412d66b8439439 (patch) | |
tree | df588cb8651f51eeaddb53250e8a7043298cc0e4 | |
parent | aed924512e0c6a2adc967e624ce14a99c546485b (diff) | |
download | vicious-legacy-44f95c3651b145c9df9154c639412d66b8439439.tar.xz |
cpufreq: widget type rewritten
It also won't break anymore when voltage support is missing since it
happens so often. But there are no handlers for the frequency or
governors - if you don't have those what the hell are you doing with
this widget anyway?
-rw-r--r-- | cpufreq.lua | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/cpufreq.lua b/cpufreq.lua index bce60e8..0cd68eb 100644 --- a/cpufreq.lua +++ b/cpufreq.lua @@ -27,10 +27,14 @@ local function worker(format, cpuid) -- ["conservative"] = "↯" --} + -- Default voltage values + local voltage = { v = "N/A", mv = "N/A" } + + -- Get the current frequency - local ffreq = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_cur_freq") - local freq = ffreq:read("*line") - ffreq:close() + local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_cur_freq") + local freq = f:read("*line") + f:close() -- Calculate MHz and GHz local freqmhz = freq / 1000 @@ -38,28 +42,29 @@ local function worker(format, cpuid) -- Get the current voltage - local fvolt = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_voltages") - for line in fvolt:lines() do + local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_voltages") + if f then for line in f:lines() do if line:find("^"..freq) then - voltagemv = line:match("[%d]+[%s]([%d]+)") + voltage.mv = line:match("[%d]+[%s]([%d]+)") break end - end - fvolt:close() + end + f:close() - -- Calculate voltage from mV - local voltagev = voltagemv / 1000 + -- Calculate voltage from mV + voltage.v = voltage.mv / 1000 + end -- Get the current governor - local fgov = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_governor") - local governor = fgov:read("*line") - fgov:close() + local f = io.open("/sys/devices/system/cpu/"..cpuid.."/cpufreq/scaling_governor") + local governor = f:read("*line") + f:close() -- Represent the governor as a symbol --local governor = governor_state[governor] or governor - return {freqmhz, freqghz, voltagemv, voltagev, governor} + return {freqmhz, freqghz, voltage.mv, voltage.v, governor} end -- }}} |