Update kobolight plugin to support kindle (#2587)

pull/2556/head
Hzj_jie 7 years ago committed by Qingping Hou
parent 4fce69d18d
commit 7fb2dc8d5c

@ -46,6 +46,7 @@ function Kindle:usbPlugIn()
end
function Kindle:intoScreenSaver()
self.powerd:beforeSuspend()
if self.charging_mode == false and self.screen_saver_mode == false then
self.screen:saveCurrentBB()
self.screen_saver_mode = true
@ -74,6 +75,7 @@ function Kindle:outofScreenSaver()
self.powerd:refreshCapacity()
end
self.screen_saver_mode = false
self.powerd:afterResume()
end
function Kindle:usbPlugOut()

@ -8,6 +8,8 @@ local KindlePowerD = BasePowerD:new{
battCapacity = nil,
is_charging = nil,
lipc_handle = nil,
is_fl_on = false,
}
function KindlePowerD:init()
@ -16,31 +18,39 @@ function KindlePowerD:init()
self.lipc_handle = lipc.init("com.github.koreader.kindlepowerd")
end
if self.device.hasFrontlight() then
-- 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
self.fl_intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
else
self.fl_intensity = self:read_int_file(self.fl_intensity_file)
self.fl_intensity = self:_readFLIntensity()
end
self:_set_fl_on()
end
end
function KindlePowerD:toggleFrontlight()
local sysint = self:read_int_file(self.fl_intensity_file)
if sysint == 0 then
-- NOTE: We want to bypass setIntensity's shenanigans and simply restore the light as-is
if not self.device.hasFrontlight() then
return
end
if self:_readFLIntensity() == 0 then
self:setIntensityHW()
else
-- NOTE: We want to really kill the light, so do it manually (asking lipc to set it to 0 would in fact set it to 1)...
os.execute("echo -n 0 > " .. self.fl_intensity_file)
self:_turnOffFL()
end
end
function KindlePowerD:setIntensityHW()
if self.lipc_handle ~= nil then
if self.lipc_handle ~= nil and self.fl_intensity > 0 then
-- NOTE: We want to bypass setIntensity's shenanigans and simply restore the light as-is
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.fl_intensity)
else
-- NOTE: when fl_intensity is 0, We want to really kill the light, so do it manually
-- (asking lipc to set it to 0 would in fact set it to 1)...
os.execute("echo -n ".. self.fl_intensity .." > " .. self.fl_intensity_file)
end
self:_set_fl_on()
end
function KindlePowerD:getCapacityHW()
@ -68,4 +78,31 @@ function KindlePowerD:__gc()
end
end
function KindlePowerD:_turnOffFL()
-- NOTE: We want to really kill the light, so do it manually (asking lipc to set it to 0 would in fact set it to 1)...
os.execute("echo -n 0 > " .. self.fl_intensity_file)
self.is_fl_on = false
end
function KindlePowerD:_readFLIntensity()
return self:read_int_file(self.fl_intensity_file)
end
function KindlePowerD:_set_fl_on()
self.is_fl_on = (self.fl_intensity > 0)
end
function KindlePowerD:afterResume()
if not self.device.hasFrontlight() then
return
end
if self.is_fl_on then
-- Kindle stock software should turn on the front light automatically. The follow statement
-- ensure the consistency of intensity.
self:setIntensityHW()
else
self:_turnOffFL()
end
end
return KindlePowerD

@ -1,6 +1,6 @@
local Device = require("device")
if not (Device:isKobo() and Device:hasFrontlight()) then
if not ((Device:isKindle() or Device:isKobo()) and Device:hasFrontlight()) then
return { disabled = true, }
end
@ -17,10 +17,19 @@ local swipe_touch_zone_ratio = { x = 0, y = 1/8, w = 1/10, h = 7/8, }
local KoboLight = WidgetContainer:new{
name = 'kobolight',
steps = { 0, 1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, },
steps = { 0.1, 0.1, 0.2, 0.4, 0.7, 1.1, 1.6, 2.2, 2.9, 3.7, 4.6, 5.6, 6.7, 7.9, 9.2, 10.6, },
gestureScale = nil, -- initialized in self:resetLayout()
}
function KoboLight:init()
local powerd = Device:getPowerDevice()
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
for i = 1, #self.steps, 1
do
self.steps[i] = math.ceil(self.steps[i] * scale)
end
end
function KoboLight:onReaderReady()
self:setupTouchZones()
self:resetLayout()

Loading…
Cancel
Save