On (really old) Kindles, don't crash if there's no sysfs entry to read for battery capacity (#5161)

Parse gasgaucge-info's output instead.

Fix #5159
pull/5162/head
NiLuJe 5 years ago committed by GitHub
parent b1b98c5733
commit 53adb9d0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,8 +46,17 @@ end
function KindlePowerD:getCapacityHW()
if self.lipc_handle ~= nil then
return self.lipc_handle:get_int_property("com.lab126.powerd", "battLevel")
else
elseif self.batt_capacity_file then
return self:read_int_file(self.batt_capacity_file)
else
local std_out = io.popen("gasgauge-info -c 2>/dev/null", "r")
if std_out then
local result = std_out:read("*all"):match("%d+")
std_out:close()
return result and tonumber(result) or 0
else
return 0
end
end
end

Loading…
Cancel
Save