FIX weird blackout when certin batteries start discharging
This commit is contained in:
parent
96734cd328
commit
882ac46259
|
@ -26,6 +26,8 @@ return function(update_freq, config, common, width, point)
|
|||
|
||||
local mk_rate_plot = function(label, address, y)
|
||||
local read_joules = sys.intel_powercap_reader(address)
|
||||
local read_joules0 = function() return read_joules() or 0 end
|
||||
local read_joulesNA = function() return read_joules() or 'N/A' end
|
||||
local obj = common.make_rate_timeseries(
|
||||
point.x,
|
||||
y,
|
||||
|
@ -38,12 +40,12 @@ return function(update_freq, config, common, width, point)
|
|||
label,
|
||||
0,
|
||||
update_freq,
|
||||
read_joules()
|
||||
read_joules0()
|
||||
)
|
||||
return common.mk_acc(
|
||||
width,
|
||||
plot_height + plot_sec_break,
|
||||
function(_) common.update_rate_timeseries(obj, read_joules()) end,
|
||||
function(_) common.update_rate_timeseries(obj, read_joulesNA()) end,
|
||||
mk_static(obj),
|
||||
mk_dynamic(obj)
|
||||
)
|
||||
|
@ -65,8 +67,11 @@ return function(update_freq, config, common, width, point)
|
|||
local mk_bat = function(y)
|
||||
local _read_battery_power = sys.battery_power_reader(config.battery)
|
||||
|
||||
-- TODO this is actually telling the plot to say it is on AC when the
|
||||
-- battery status can't be read (in which case it should say ERROR or
|
||||
-- something)
|
||||
local read_battery_power = function(is_using_ac)
|
||||
return is_using_ac and 0 or _read_battery_power()
|
||||
return is_using_ac and 0 or (_read_battery_power() or 0)
|
||||
end
|
||||
local read_bat_status = sys.battery_status_reader(config.battery)
|
||||
local obj = common.make_tagged_scaled_timeseries(
|
||||
|
|
17
src/sys.lua
17
src/sys.lua
|
@ -13,7 +13,12 @@ local dirname = function(s)
|
|||
end
|
||||
|
||||
local read_micro = function(path)
|
||||
return i_o.read_file(path, nil, '*n') * 0.000001
|
||||
local j = i_o.read_file(path, nil, '*n')
|
||||
if j == nil then
|
||||
return nil
|
||||
else
|
||||
return j * 0.000001
|
||||
end
|
||||
end
|
||||
|
||||
local gmatch_to_table1 = function(pat, s)
|
||||
|
@ -110,7 +115,15 @@ end
|
|||
M.battery_power_reader = function(battery)
|
||||
local current = format_power_path(battery, 'current_now')
|
||||
local voltage = format_power_path(battery, 'voltage_now')
|
||||
return function() return read_micro(current) * read_micro(voltage) end
|
||||
return function()
|
||||
local c = read_micro(current)
|
||||
local v = read_micro(voltage)
|
||||
if c == nil or v == nil then
|
||||
return nil
|
||||
else
|
||||
return c * v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.battery_status_reader = function(battery)
|
||||
|
|
Loading…
Reference in New Issue