[fix] Update AutoWarmth state on resume (#4901)

Regression since #4871
Fix #4895

* Hide the "Configure" button in the FL/NL widget on devices where it
won't do anything

(i.e., those w/ a NL mixer).
pull/4911/head
NiLuJe 5 years ago committed by Frans de Jonge
parent 74e14a927c
commit f63ca005c6

@ -50,6 +50,7 @@ local Cervantes = Generic:new{
-- currently only Cervantes 4 has coloured frontlight
hasNaturalLight = no,
hasNaturalLightMixer = no,
}
-- Cervantes Touch
local CervantesTouch = Cervantes:new{
@ -131,6 +132,12 @@ end
function Cervantes:init()
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
-- Automagically set this so we never have to remember to do it manually ;p
if self:hasNaturalLight() and self.frontlight_settings and self.frontlight_settings.frontlight_mixer then
self.hasNaturalLightMixer = yes
end
self.powerd = require("device/cervantes/powerd"):new{device = self}
self.input = require("device/input"):new{
device = self,

@ -38,6 +38,7 @@ local Kobo = Generic:new{
internal_storage_mount_point = "/mnt/onboard/",
-- currently only the Aura One and Forma have coloured frontlights
hasNaturalLight = no,
hasNaturalLightMixer = no,
-- HW inversion is generally safe on Kobo, except on a few baords/kernels
canHWInvert = yes,
}
@ -255,6 +256,12 @@ function Kobo:init()
logger.info("Enabling Kobo @ 32bpp BGR tweaks")
self.hasBGRFrameBuffer = yes
end
-- Automagically set this so we never have to remember to do it manually ;p
if self:hasNaturalLight() and self.frontlight_settings and self.frontlight_settings.frontlight_mixer then
self.hasNaturalLightMixer = yes
end
self.powerd = require("device/kobo/powerd"):new{device = self}
-- NOTE: For the Forma, with the buttons on the right, 193 is Top, 194 Bottom.
self.input = require("device/input"):new{

@ -141,6 +141,10 @@ function KoboPowerD:init()
-- See discussion in https://github.com/koreader/koreader/issues/3118#issuecomment-334995879
-- for the reasoning behind this bit of insanity.
if self:isFrontlightOnHW() then
-- On devices with a mixer, setIntensity will *only* set the FL, so, ensure we honor the warmth, too.
if self.device:hasNaturalLightMixer() then
self:setWarmth(self.fl_warmth)
end
-- Use setIntensity to ensure it sets fl_intensity, and because we don't want the ramping behavior of turnOn
self:setIntensity(self:frontlightIntensityHW())
else
@ -253,6 +257,18 @@ function KoboPowerD:calculateAutoWarmth()
self.fl_warmth = math.max(100 - 50 * (22 - diff_time), 0)
end
self.fl_warmth = math.floor(self.fl_warmth + 0.5)
-- Make sure sysfs_light actually picks that new value up without an explicit setWarmth call...
-- This avoids having to bypass the ramp-up on resume w/ an explicit setWarmth call on devices where brightness & warmth
-- are linked (i.e., when there's no mixer) ;).
-- NOTE: A potentially saner solution would be to ditch the internal sysfs_light current_* values,
-- and just pass it a pointer to this powerd instance, so it has access to fl_warmth & hw_intensity.
-- It seems harmless enough for warmth, but brightness might be a little trickier because of the insanity
-- that is hw_intensity handling because we can't actually *read* the frontlight status...
-- (Technically, we could, on Mk. 7 devices, but we don't,
-- because this is already messy enough without piling on special cases.)
if self.fl then
self.fl.current_warmth = self.fl_warmth
end
-- Enable background job for setting Warmth, if not already done.
if not self.autowarmth_job_running then
table.insert(PluginShare.backgroundJobs, {
@ -320,6 +336,14 @@ end
-- Restore front light state after resume.
function KoboPowerD:afterResume()
if self.fl == nil then return end
-- Update AutoWarmth state
if self.fl_warmth ~= nil and self.auto_warmth then
self:calculateAutoWarmth()
-- And we need an explicit setWarmth if the device has a mixer, because turnOn won't touch the warmth on those ;).
if self.device:hasNaturalLightMixer() then
self:setWarmth(self.fl_warmth)
end
end
-- Turn the frontlight back on
self:turnOnFrontlight()
end

@ -52,7 +52,8 @@ function FrontLightWidget:init()
self.steps = self.steps + 1
end
self.steps = math.min(self.steps, steps_fl)
self.natural_light = (Device:isCervantes() or Device:isKobo()) and Device:hasNaturalLight()
self.natural_light = Device:hasNaturalLight()
self.has_nl_mixer = Device:hasNaturalLightMixer()
-- Handle Warmth separately, because it may use a different scale
if self.natural_light then
self.nl_min = self.powerd.fl_warmth_min
@ -256,21 +257,23 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
table.insert(vertical_group, button_group_down)
table.insert(vertical_group, padding_span)
if self.natural_light then
-- If the device supports natural light, add the widgets for 'warmth'
-- and a 'Configure' button
-- If the device supports natural light, add the widgets for 'warmth',
-- as well as a 'Configure' button for devices *without* a mixer
self:addWarmthWidgets(num_warmth, step, vertical_group)
self.configure_button = Button:new{
text = _("Configure"),
margin = Size.margin.small,
radius = 0,
width = self.screen_width * 0.20,
enabled = not self.nl_configure_open,
show_parent = self,
callback = function()
UIManager:show(NaturalLight:new{fl_widget = self})
end,
}
table.insert(vertical_group, self.configure_button)
if not self.has_nl_mixer then
self.configure_button = Button:new{
text = _("Configure"),
margin = Size.margin.small,
radius = 0,
width = self.screen_width * 0.20,
enabled = not self.nl_configure_open,
show_parent = self,
callback = function()
UIManager:show(NaturalLight:new{fl_widget = self})
end,
}
table.insert(vertical_group, self.configure_button)
end
end
table.insert(self.fl_container, vertical_group)
-- Reset container height to what it actually contains

Loading…
Cancel
Save