Several fixes in frontlight logic (#2991)

* Use PluginShare to exchange data between plugins

* Remove legacy code in reader.lua and kobo/device.lua, and move KOBO_LIGHT_ON_START to kobo/powerd.lua

* A better sync config logic

* Consider kobo without hardware frontlight toggle

* update frontlight widget once toggle is tapped.
pull/2996/head
Hzj_jie 7 years ago committed by Frans de Jonge
parent 9b557ed15a
commit a4d5165f7a

@ -125,7 +125,7 @@ end
function BasePowerD:setIntensity(intensity)
if not self.device.hasFrontlight() then return false end
if intensity == self.fl_intensity then return false end
if intensity == self:frontlightIntensity() then return false end
self.fl_intensity = self:normalizeIntensity(intensity)
self:_decideFrontlightState()
logger.dbg("set light intensity", self.fl_intensity)

@ -182,38 +182,6 @@ function Kobo:init()
self:initEventAdjustHooks()
end
end
-- TODO: get rid of KOBO_LIGHT_ON_START
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
if kobo_light_on_start then
local new_intensity
local is_frontlight_on
if kobo_light_on_start > 0 then
new_intensity = math.min(kobo_light_on_start, 100)
is_frontlight_on = true
elseif kobo_light_on_start == 0 then
is_frontlight_on = false
elseif kobo_light_on_start == -2 then
local NickelConf = require("device/kobo/nickel_conf")
new_intensity = NickelConf.frontLightLevel.get()
is_frontlight_on = NickelConf.frontLightState:get()
if is_frontlight_on == nil then
-- this device does not support frontlight toggle,
-- we set the value based on frontlight intensity.
if new_intensity > 0 then
is_frontlight_on = true
else
is_frontlight_on = false
end
end
end
-- Since this is kobo-specific, we save all values in settings here
-- and let the code (reader.lua) pick it up later during bootstrap.
if new_intensity then
G_reader_settings:saveSetting("frontlight_intensity", new_intensity)
end
G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on)
end
end
function Kobo:initNetworkManager(NetworkMgr)

@ -104,7 +104,9 @@ function NickelConf._write_kobo_conf(re_Match, key, value, dont_create)
kobo_conf:close()
end
if not found and dont_create ~= true then
if not found then
if dont_create then return true end
if not correct_section then
lines[#lines + 1] = "[PowerOptions]"
end

@ -14,40 +14,68 @@ local KoboPowerD = BasePowerD:new{
is_charging_file = batt_state_folder .. "status",
}
-- TODO: Remove KOBO_LIGHT_ON_START
function KoboPowerD:_syncKoboLightOnStart()
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
if kobo_light_on_start then
local new_intensity
local is_frontlight_on
if kobo_light_on_start > 0 then
new_intensity = math.min(kobo_light_on_start, 100)
is_frontlight_on = true
elseif kobo_light_on_start == 0 then
new_intensity = 0
is_frontlight_on = false
elseif kobo_light_on_start == -2 then
return
else -- if kobo_light_on_start == -1 or other unexpected value then
-- TODO(Hzj-jie): Read current frontlight states from OS.
return
end
NickelConf.frontLightLevel.set(new_intensity)
NickelConf.frontLightState.set(is_frontlight_on)
end
end
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
if NickelConf.frontLightState.get() ~= nil then
self.has_fl_state_cfg = true
else
self.has_fl_state_cfg = false
end
self:_syncKoboLightOnStart()
end
end
end
function KoboPowerD:_syncIntensity(intensity)
if NickelConf.frontLightLevel.get() ~= intensity then
NickelConf.frontLightLevel.set(intensity)
end
end
function KoboPowerD:_syncNickelConf()
if self.has_fl_state_cfg and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
NickelConf.frontLightState.set(self:isFrontlightOn())
NickelConf.frontLightLevel.set(self.fl_intensity)
if not KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then return end
if NickelConf.frontLightState.get() == nil then
self:_syncIntensity(self:frontlightIntensity())
else
if NickelConf.frontLightState.get() ~= self:isFrontlightOn() then
NickelConf.frontLightState.set(self:isFrontlightOn())
end
self:_syncIntensity(self.fl_intensity)
end
end
function KoboPowerD:frontlightIntensityHW()
if self.has_fl_state_cfg then
return NickelConf.frontLightLevel.get()
end
return 20
return NickelConf.frontLightLevel.get()
end
function KoboPowerD:isFrontlightOnHW()
if self.has_fl_state_cfg then
return NickelConf.frontLightState.get()
local result = NickelConf.frontLightState.get()
if result == nil then
return self.fl_intensity > 0
end
return BasePowerD.isFrontlightOnHW(self)
return result
end
function KoboPowerD:turnOffFrontlightHW() self:_setIntensity(0) end

@ -188,6 +188,7 @@ function FrontLightWidget:setProgress(num, step)
callback = function()
local powerd = Device:getPowerDevice()
powerd:toggleFrontlight()
self:setProgress(powerd:frontlightIntensity(), step)
end,
}
local empty_space = HorizontalSpan:new{

@ -136,30 +136,6 @@ if G_reader_settings:readSetting("night_mode") then
Device.screen:toggleNightMode()
end
-- restore kobo frontlight settings and probe kobo touch coordinates
if Device:isKobo() then
if Device:hasFrontlight() then
local powerd = Device:getPowerDevice()
if powerd then
-- UIManager:init() should have sanely set up the frontlight_stuff by this point
local intensity = G_reader_settings:readSetting("frontlight_intensity")
powerd.fl_intensity = intensity or powerd.fl_intensity
local is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on")
if is_frontlight_on then
-- default powerd.is_fl_on is false, turn it on
powerd:toggleFrontlight()
else
-- the light can still be turned on manually outside of KOReader
-- or Nickel. so we always set the intensity to 0 here to keep it
-- in sync with powerd.is_fl_on (false by default)
-- NOTE: we cant use setIntensity method here because for Kobo the
-- min intensity is 1 :(
powerd.fl:setBrightness(0)
end
end
end
end
if Device:needsTouchScreenProbe() then
Device:touchScreenProbe()
end

Loading…
Cancel
Save