2014-10-30 18:42:18 +00:00
|
|
|
local BasePowerD = require("device/generic/powerd")
|
2014-01-04 13:38:07 +00:00
|
|
|
-- liblipclua, see require below
|
|
|
|
|
|
|
|
local KindlePowerD = BasePowerD:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
fl_min = 0, fl_max = 24,
|
2014-07-04 18:10:38 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
lipc_handle = nil,
|
2014-01-04 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
function KindlePowerD:init()
|
2015-09-26 23:02:37 +00:00
|
|
|
local haslipc, lipc = pcall(require, "liblipclua")
|
|
|
|
if haslipc and lipc then
|
2014-07-04 18:10:38 +00:00
|
|
|
self.lipc_handle = lipc.init("com.github.koreader.kindlepowerd")
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2017-06-14 17:32:16 +00:00
|
|
|
function KindlePowerD:frontlightIntensityHW()
|
|
|
|
if not self.device.hasFrontlight() then return 0 end
|
|
|
|
-- Kindle stock software does not use intensity file directly, so we need to read from its
|
|
|
|
-- lipc property first.
|
|
|
|
if self.lipc_handle ~= nil then
|
|
|
|
return self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2017-06-14 17:32:16 +00:00
|
|
|
return self:_readFLIntensity()
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2017-06-14 17:32:16 +00:00
|
|
|
function KindlePowerD:setIntensityHW(intensity)
|
|
|
|
if self.lipc_handle ~= nil and intensity > 0 then
|
2017-02-26 10:19:20 +00:00
|
|
|
-- NOTE: We want to bypass setIntensity's shenanigans and simply restore the light as-is
|
2017-06-14 17:32:16 +00:00
|
|
|
self.lipc_handle:set_int_property(
|
2017-06-15 22:27:04 +00:00
|
|
|
"com.lab126.powerd", "flIntensity", intensity)
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2017-06-14 17:32:16 +00:00
|
|
|
-- NOTE: when intensity is 0, We want to really kill the light, so do it manually
|
2017-02-26 10:19:20 +00:00
|
|
|
-- (asking lipc to set it to 0 would in fact set it to 1)...
|
2017-06-14 17:32:16 +00:00
|
|
|
os.execute("echo -n ".. intensity .." > " .. self.fl_intensity_file)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:getCapacityHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.lipc_handle ~= nil then
|
2017-03-24 06:36:15 +00:00
|
|
|
return self.lipc_handle:get_int_property("com.lab126.powerd", "battLevel")
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2017-03-24 06:36:15 +00:00
|
|
|
return self:read_int_file(self.batt_capacity_file)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:isChargingHW()
|
2017-03-24 06:36:15 +00:00
|
|
|
local is_charging
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.lipc_handle ~= nil then
|
2017-03-24 06:36:15 +00:00
|
|
|
is_charging = self.lipc_handle:get_int_property("com.lab126.powerd", "isCharging")
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2017-03-24 06:36:15 +00:00
|
|
|
is_charging = self:read_int_file(self.is_charging_file)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2017-03-24 06:36:15 +00:00
|
|
|
return is_charging == 1
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
function KindlePowerD:__gc()
|
2014-07-04 18:10:38 +00:00
|
|
|
if self.lipc_handle then
|
|
|
|
self.lipc_handle:close()
|
2014-10-30 18:42:18 +00:00
|
|
|
self.lipc_handle = nil
|
2014-07-04 18:10:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-26 10:19:20 +00:00
|
|
|
function KindlePowerD:_readFLIntensity()
|
|
|
|
return self:read_int_file(self.fl_intensity_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:afterResume()
|
|
|
|
if not self.device.hasFrontlight() then
|
|
|
|
return
|
|
|
|
end
|
2017-06-14 17:32:16 +00:00
|
|
|
if self:isFrontlightOn() then
|
2017-02-26 10:19:20 +00:00
|
|
|
-- Kindle stock software should turn on the front light automatically. The follow statement
|
|
|
|
-- ensure the consistency of intensity.
|
2017-06-15 22:27:04 +00:00
|
|
|
self:turnOnFrontlightHW()
|
2017-02-26 10:19:20 +00:00
|
|
|
else
|
2017-06-14 17:32:16 +00:00
|
|
|
self:turnOffFrontlightHW()
|
2017-02-26 10:19:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
return KindlePowerD
|