Refactor min/max handling in BaseFrontLight; use getFrontlight() in ReaderFrontLight for consistency

pull/212/head
Paulo Matias 11 years ago
parent 3f3fba2fdf
commit 81facc2ce9

@ -8,13 +8,17 @@ Device = {
frontlight = nil,
}
BaseFrontLight = {}
KindleFrontLight = {
min = 0, max = 24,
kpw_fl = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity",
intensity = nil,
lipc_handle = nil,
}
KoboFrontLight = {
min = 1, max = 100,
intensity = nil,
fl = nil,
}
@ -187,6 +191,12 @@ function Device:getFrontlight()
return self.frontlight
end
function BaseFrontLight:intensityCheckBounds(intensity)
intensity = intensity < self.min and self.min or intensity
intensity = intensity > self.max and self.max or intensity
self.intensity = intensity
end
function KindleFrontLight:init()
require "liblipclua"
self.lipc_handle = lipc.init("com.github.koreader")
@ -206,12 +216,12 @@ function KindleFrontLight:toggle()
end
end
KindleFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds
function KindleFrontLight:setIntensity(intensity)
if self.lipc_handle ~= nil then
intensity = intensity < 0 and 0 or intensity
intensity = intensity > 24 and 24 or intensity
self.intensity = intensity
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity)
self:intensityCheckBounds(intensity)
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.intensity)
end
end
@ -230,11 +240,11 @@ function KoboFrontLight:toggle()
end
end
KoboFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds
function KoboFrontLight:setIntensity(intensity)
if self.fl ~= nil then
intensity = intensity < 1 and 1 or intensity
intensity = intensity > 100 and 100 or intensity
self.fl:setBrightness(intensity)
self.intensity = intensity
self:intensityCheckBounds(intensity)
self.fl:setBrightness(self.intensity)
end
end

@ -26,7 +26,7 @@ function ReaderFrontLight:init()
end
function ReaderFrontLight:onAdjust(arg, ges)
local fl = Device.frontlight
local fl = Device:getFrontlight()
if fl.intensity ~= nil then
local rel_proportion = ges.distance / Screen:getWidth()
local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps]
@ -59,17 +59,17 @@ function ReaderFrontLight:addToMainMenu(tab_item_table)
end
function ReaderFrontLight:onShowFlDialog()
DEBUG("show fldial dialog")
local fl = Device:getFrontlight()
self.fl_dialog = InputDialog:new{
title = _("Frontlight Level"),
input_hint = Device:isKobo() and "(1 - 100)" or "(0 - 24)",
input_hint = ("(%d - %d)"):format(fl.min, fl.max),
buttons = {
{
{
text = _("Toggle"),
enabled = true,
callback = function()
Device.frontlight:toggle()
fl:toggle()
end,
},
{
@ -100,13 +100,13 @@ end
function ReaderFrontLight:close()
self.fl_dialog:onClose()
G_reader_settings:saveSetting("frontlight_intensity", Device.frontlight.intensity)
G_reader_settings:saveSetting("frontlight_intensity", Device:getFrontlight().intensity)
UIManager:close(self.fl_dialog)
end
function ReaderFrontLight:fldialIntensity()
local number = tonumber(self.fl_dialog:getInputText())
if number ~= nil then
Device.frontlight:setIntensity(number)
Device:getFrontlight():setIntensity(number)
end
end

Loading…
Cancel
Save