From 8b7658b8cd9a9754ba66d959274190daddebb25f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:59:48 -0800 Subject: [PATCH] kobo: always keep intensity value and is_fl_on in sync --- frontend/device/generic/powerd.lua | 9 +++++---- frontend/device/kobo/powerd.lua | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/frontend/device/generic/powerd.lua b/frontend/device/generic/powerd.lua index dad7a9788..c0dae784e 100644 --- a/frontend/device/generic/powerd.lua +++ b/frontend/device/generic/powerd.lua @@ -1,9 +1,9 @@ local BasePowerD = { - fl_min = 0, -- min frontlight intensity - fl_max = 10, -- max frontlight intensity - fl_intensity = nil, -- frontlight intensity + fl_min = 0, -- min frontlight intensity + fl_max = 10, -- max frontlight intensity + fl_intensity = nil, -- frontlight intensity battCapacity = nil, -- battery capacity - device = nil, -- device object + device = nil, -- device object capacity_pulled_count = 0, capacity_cached_count = 10, @@ -57,6 +57,7 @@ function BasePowerD:normalizeIntensity(intensity) end function BasePowerD:setIntensity(intensity) + if intensity == self.fl_intensity then return end self.fl_intensity = self:normalizeIntensity(intensity) self:setIntensityHW() end diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 7b218e934..6aec18b53 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -11,8 +11,12 @@ local KoboPowerD = BasePowerD:new{ fl_intensity = 20, restore_settings = true, fl = nil, - -- this attribute should be synced with nickel's FrontLightState config + + -- We will set this value for all kobo models. but it will only be synced + -- with nickel's FrontLightState config if the current model has a + -- frontlight toggle button. is_fl_on = false, + batt_capacity_file = batt_state_folder .. "capacity", is_charging_file = batt_state_folder .. "status", battCapacity = nil, @@ -23,7 +27,14 @@ function KoboPowerD:init() if self.device.hasFrontlight() then local kobolight = require("ffi/kobolight") local ok, light = pcall(kobolight.open) - if ok then self.fl = light end + if ok then + self.fl = light + if NickelConf.frontLightState.get() ~= nil then + self.has_fl_toggle_btn = true + else + self.has_fl_toggle_btn = false + end + end end end @@ -35,7 +46,7 @@ function KoboPowerD:toggleFrontlight() self.fl:setBrightness(self.fl_intensity) end self.is_fl_on = not self.is_fl_on - if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightState.set(self.is_fl_on) end end @@ -47,6 +58,19 @@ function KoboPowerD:setIntensityHW() if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then NickelConf.frontLightLevel.set(self.fl_intensity) end + -- also keep self.is_fl_on in sync with intensity if needed + local is_fl_on + if self.fl_intensity > 0 then + is_fl_on = true + else + is_fl_on = false + end + if self.is_fl_on ~= is_fl_on then + self.is_fl_on = is_fl_on + if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then + NickelConf.frontLightState.set(self.is_fl_on) + end + end end end