From 3ee2c758ec1a581e74a7a13a8e29d8f7f58ee7c0 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 28 Dec 2013 14:30:23 +0800 Subject: [PATCH] fix lost of frontlight intensity after exiting kobo This should fix #243. --- frontend/ui/device.lua | 7 +++---- frontend/ui/device/basefrontlight.lua | 8 ++++++++ frontend/ui/device/kindlefrontlight.lua | 4 +--- frontend/ui/device/kobofrontlight.lua | 4 +--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index b1b125151..1665cfc7c 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -221,13 +221,12 @@ function Device:getFrontlight() elseif self:hasFrontlight() then local model = self:getModel() if model == "KindlePaperWhite" or model == "KindlePaperWhite2" then - self.frontlight = KindleFrontLight + self.frontlight = KindleFrontLight:new() elseif self:isKobo() then - self.frontlight = KoboFrontLight + self.frontlight = KoboFrontLight:new() else -- emulated FrontLight - self.frontlight = BaseFrontLight + self.frontlight = BaseFrontLight:new() end - self.frontlight:init() end return self.frontlight end diff --git a/frontend/ui/device/basefrontlight.lua b/frontend/ui/device/basefrontlight.lua index b6d889661..444b661a1 100644 --- a/frontend/ui/device/basefrontlight.lua +++ b/frontend/ui/device/basefrontlight.lua @@ -3,6 +3,14 @@ local BaseFrontLight = { intensity = nil, } +function BaseFrontLight:new(o) + local o = o or {} + setmetatable(o, self) + self.__index = self + if o.init then o:init() end + return o +end + function BaseFrontLight:init() end function BaseFrontLight:toggle() end function BaseFrontLight:setIntensityHW() end diff --git a/frontend/ui/device/kindlefrontlight.lua b/frontend/ui/device/kindlefrontlight.lua index 98cd9545a..5315b16f2 100644 --- a/frontend/ui/device/kindlefrontlight.lua +++ b/frontend/ui/device/kindlefrontlight.lua @@ -1,7 +1,7 @@ local BaseFrontLight = require("ui/device/basefrontlight") -- liblipclua, see require below -local KindleFrontLight = { +local KindleFrontLight = BaseFrontLight:new{ min = 0, max = 24, -- FIXME: Check how to handle this on the PW2, initial reports on IRC suggest that this isn't possible anymore kpw_fl = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity", @@ -28,8 +28,6 @@ function KindleFrontLight:toggle() end end -KindleFrontLight.setIntensity = BaseFrontLight.setIntensity - function KindleFrontLight:setIntensityHW() if self.lipc_handle ~= nil then self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.intensity) diff --git a/frontend/ui/device/kobofrontlight.lua b/frontend/ui/device/kobofrontlight.lua index 6877071b5..436f5cc36 100644 --- a/frontend/ui/device/kobofrontlight.lua +++ b/frontend/ui/device/kobofrontlight.lua @@ -1,6 +1,6 @@ local BaseFrontLight = require("ui/device/basefrontlight") -local KoboFrontLight = { +local KoboFrontLight = BaseFrontLight:new{ min = 1, max = 100, intensity = 20, restore_settings = true, @@ -17,8 +17,6 @@ function KoboFrontLight:toggle() end end -KoboFrontLight.setIntensity = BaseFrontLight.setIntensity - function KoboFrontLight:setIntensityHW() if self.fl ~= nil then self.fl:setBrightness(self.intensity)