diff --git a/widgets/cpufreq.lua b/widgets/cpufreq.lua index 11949da..4a58ec2 100644 --- a/widgets/cpufreq.lua +++ b/widgets/cpufreq.lua @@ -27,28 +27,25 @@ local function worker(format, warg) ["performance\n"] = "⚡", ["conservative\n"] = "⊚" } - -- Default voltage values - local voltage = { v = "N/A", mv = "N/A" } - local freqmhz = "N/A" - local freqghz = "N/A" - + -- Default frequency and voltage values + local freqv = { + ["mhz"] = "N/A", ["ghz"] = "N/A", + ["v"] = "N/A", ["mv"] = "N/A", + } -- Get the current frequency local freq = tonumber(cpufreq.scaling_cur_freq) -- Calculate MHz and GHz - if freq then - freqmhz = freq / 1000 - freqghz = freqmhz / 1000 + freqv.mhz = freq / 1000 + freqv.ghz = freqv.mhz / 1000 end - - -- Get the current voltage - if cpufreq.scaling_voltages then - voltage.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)")) + if cpufreq.scaling_voltages and freq then + freqv.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)")) -- Calculate voltage from mV - voltage.v = voltage.mv / 1000 + freqv.v = freqv.mv / 1000 end -- Get the current governor @@ -56,7 +53,7 @@ local function worker(format, warg) -- Represent the governor as a symbol governor = governor_state[governor] or governor or "N/A" - return {freqmhz, freqghz, voltage.mv, voltage.v, governor} + return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor} end -- }}}