2013-07-24 06:14:12 +00:00
|
|
|
require "ui/widget/container"
|
2013-04-14 13:17:52 +00:00
|
|
|
require "ui/device"
|
|
|
|
|
|
|
|
ReaderFrontLight = InputContainer:new{
|
|
|
|
steps = {0,1,2,3,4,5,6,7,8,9,10},
|
|
|
|
intensity = nil,
|
2013-07-23 17:40:26 +00:00
|
|
|
ld = nil,
|
2013-04-14 13:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderFrontLight:init()
|
|
|
|
local dev_mod = Device:getModel()
|
|
|
|
if dev_mod == "KindlePaperWhite" then
|
|
|
|
require "liblipclua"
|
|
|
|
self.lipc_handle = lipc.init("com.github.koreader")
|
2013-04-20 03:08:12 +00:00
|
|
|
if self.lipc_handle then
|
|
|
|
self.intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
|
|
|
|
end
|
2013-07-23 17:40:26 +00:00
|
|
|
self.ges_events = {
|
|
|
|
Adjust = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_pan",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
},
|
|
|
|
rate = 2.0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if Device:isKobo() then
|
|
|
|
self.ld = kobolight.open()
|
2013-04-14 13:17:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:onAdjust(arg, ges)
|
2013-04-20 03:08:12 +00:00
|
|
|
if self.lipc_handle and self.intensity ~=nil then
|
2013-04-14 13:17:52 +00:00
|
|
|
local rel_proportion = ges.distance / Screen:getWidth()
|
2013-07-22 12:23:58 +00:00
|
|
|
local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps]
|
2013-04-14 13:17:52 +00:00
|
|
|
local msg = ""
|
|
|
|
if ges.direction == "north" then
|
|
|
|
msg = _("Increase front light intensity to ")
|
|
|
|
self.intensity = self.intensity + delta_int
|
|
|
|
self:setIntensity(self.intensity, msg)
|
|
|
|
elseif ges.direction == "south" then
|
|
|
|
msg = _("Decrease front light intensity to ")
|
|
|
|
self.intensity = self.intensity - delta_int
|
|
|
|
self:setIntensity(self.intensity, msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:setIntensity(intensity, msg)
|
|
|
|
if self.lipc_handle then
|
|
|
|
intensity = intensity < 0 and 0 or intensity
|
|
|
|
intensity = intensity > 24 and 24 or intensity
|
2013-07-22 12:23:58 +00:00
|
|
|
self.intensity = intensity
|
2013-04-14 13:17:52 +00:00
|
|
|
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg..intensity,
|
|
|
|
timeout = 1
|
|
|
|
})
|
|
|
|
end
|
2013-07-23 17:40:26 +00:00
|
|
|
if Device:isKobo() then
|
|
|
|
if self.ld == nil then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
self.intensity = intensity
|
|
|
|
self.ld:setBrightness(intensity)
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFrontLight:toggle()
|
|
|
|
if Device:isKobo() then
|
|
|
|
if self.ld == nil then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
self.ld:toggle()
|
|
|
|
end
|
2013-04-14 13:17:52 +00:00
|
|
|
return true
|
|
|
|
end
|