kobo: always keep intensity value and is_fl_on in sync

pull/1863/head
Qingping Hou 8 years ago committed by NiLuJe
parent 08b08d69f7
commit 8b7658b8cd

@ -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

@ -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

Loading…
Cancel
Save