From 53adb9d0e152250c4afa5a7f25fe57c197f9352f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 1 Aug 2019 18:45:30 +0200 Subject: [PATCH] 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 --- frontend/device/kindle/powerd.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/device/kindle/powerd.lua b/frontend/device/kindle/powerd.lua index e6225c1b6..144f4bb20 100644 --- a/frontend/device/kindle/powerd.lua +++ b/frontend/device/kindle/powerd.lua @@ -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