[frontlight, kobo, cervantes] Remove auto_warmth (#8154)

The feature is now provided by the "Auto warmth
and night mode" plugin (#8129).
reviewable/pr8264/r1
zwim 3 years ago committed by GitHub
parent 4a2f519600
commit 0c7d174cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,14 +1,11 @@
local BasePowerD = require("device/generic/powerd")
local SysfsLight = require ("device/sysfs_light")
local PluginShare = require("pluginshare")
local battery_sysfs = "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/"
local CervantesPowerD = BasePowerD:new{
fl = nil,
fl_warmth = nil,
auto_warmth = false,
max_warmth_hour = 23,
fl_min = 0,
fl_max = 100,
@ -23,11 +20,10 @@ function CervantesPowerD:_syncLightOnStart()
-- Use last values stored in koreader settings.
local new_intensity = G_reader_settings:readSetting("frontlight_intensity") or nil
local is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on") or nil
local new_warmth, auto_warmth = nil
local new_warmth = nil
if self.fl_warmth ~= nil then
new_warmth = G_reader_settings:readSetting("frontlight_warmth") or nil
auto_warmth = G_reader_settings:readSetting("frontlight_auto_warmth") or nil
end
if new_intensity ~= nil then
@ -38,15 +34,7 @@ function CervantesPowerD:_syncLightOnStart()
self.initial_is_fl_on = is_frontlight_on
end
local max_warmth_hour =
G_reader_settings:readSetting("frontlight_max_warmth_hour")
if max_warmth_hour then
self.max_warmth_hour = max_warmth_hour
end
if auto_warmth then
self.auto_warmth = true
self:calculateAutoWarmth()
elseif new_warmth ~= nil then
if new_warmth ~= nil then
self.fl_warmth = new_warmth
end
@ -61,7 +49,6 @@ function CervantesPowerD:init()
-- not be called)
self.hw_intensity = 20
self.initial_is_fl_on = true
self.autowarmth_job_running = false
if self.device:hasFrontlight() then
if self.device:hasNaturalLight() then
@ -101,15 +88,11 @@ function CervantesPowerD:saveSettings()
local cur_intensity = self.fl_intensity
local cur_is_fl_on = self.is_fl_on
local cur_warmth = self.fl_warmth
local cur_auto_warmth = self.auto_warmth
local cur_max_warmth_hour = self.max_warmth_hour
-- Save intensity to koreader settings
G_reader_settings:saveSetting("frontlight_intensity", cur_intensity)
G_reader_settings:saveSetting("is_frontlight_on", cur_is_fl_on)
if cur_warmth ~= nil then
G_reader_settings:saveSetting("frontlight_warmth", cur_warmth)
G_reader_settings:saveSetting("frontlight_auto_warmth", cur_auto_warmth)
G_reader_settings:saveSetting("frontlight_max_warmth_hour", cur_max_warmth_hour)
end
end
end
@ -141,10 +124,7 @@ end
function CervantesPowerD:setWarmth(warmth)
if self.fl == nil then return end
if not warmth and self.auto_warmth then
self:calculateAutoWarmth()
end
self.fl_warmth = warmth or self.fl_warmth
self.fl_warmth = warmth
self.fl:setWarmth(self.fl_warmth)
self:stateChanged()
end
@ -154,45 +134,6 @@ function CervantesPowerD:getWarmth()
return self.fl_warmth
end
function CervantesPowerD:calculateAutoWarmth()
local current_time = os.date("%H") + os.date("%M")/60
local max_hour = self.max_warmth_hour
local diff_time = max_hour - current_time
if diff_time < 0 then
diff_time = diff_time + 24
end
if diff_time < 12 then
-- We are before bedtime. Use a slower progression over 5h.
self.fl_warmth = math.max(20 * (5 - diff_time), 0)
elseif diff_time > 22 then
-- Keep warmth at maximum for two hours after bedtime.
self.fl_warmth = 100
else
-- Between 2-4h after bedtime, return to zero.
self.fl_warmth = math.max(100 - 50 * (22 - diff_time), 0)
end
self.fl_warmth = math.floor(self.fl_warmth + 0.5)
-- Enable background job for setting Warmth, if not already done.
if not self.autowarmth_job_running then
table.insert(PluginShare.backgroundJobs, {
when = 180,
repeated = true,
executable = function()
if self.auto_warmth then
self:setWarmth()
end
end,
})
if package.loaded["ui/uimanager"] ~= nil then
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
UIManager:broadcastEvent(Event:new("BackgroundJobsUpdated"))
end
self.autowarmth_job_running = true
end
end
function CervantesPowerD:getCapacityHW()
return self:read_int_file(self.capacity_file)
end
@ -213,9 +154,6 @@ function CervantesPowerD:afterResume()
if self.fl_warmth == nil then
self.fl:setBrightness(self.hw_intensity)
else
if self.auto_warmth then
self:calculateAutoWarmth()
end
self.fl:setNaturalBrightness(self.hw_intensity, self.fl_warmth)
end
end

@ -170,11 +170,6 @@ if Device:hasFrontlight() then
local powerd = Device:getPowerDevice()
if powerd.fl_warmth == nil then return false end
if powerd.auto_warmth then
Notification:notify(_("Warmth is handled automatically."))
return true
end
local delta_int
--received gesture

@ -9,22 +9,17 @@ local NickelConf = {}
NickelConf.frontLightLevel = {}
NickelConf.frontLightState = {}
NickelConf.colorSetting = {}
NickelConf.autoColorEnabled = {}
local kobo_conf_path = '/mnt/onboard/.kobo/Kobo/Kobo eReader.conf'
local front_light_level_str = "FrontLightLevel"
local front_light_state_str = "FrontLightState"
local color_setting_str = "ColorSetting"
local auto_color_enabled_str = "AutoColorEnabled"
-- Nickel will set FrontLightLevel to 0 - 100
local re_FrontLightLevel = "^" .. front_light_level_str .. "%s*=%s*([0-9]+)%s*$"
-- Nickel will set FrontLightState to true (light on) or false (light off)
local re_FrontLightState = "^" .. front_light_state_str .. "%s*=%s*(.+)%s*$"
-- Nickel will set ColorSetting to 1500 - 6400
local re_ColorSetting = "^" .. color_setting_str .. "%s*=%s*([0-9]+)%s*$"
-- AutoColorEnabled is 'true' or 'false'
-- We do not support 'BedTime' (it is saved as QVariant in Nickel)
local re_AutoColorEnabled = "^" .. auto_color_enabled_str .. "%s*=%s*([a-z]+)%s*$"
local re_PowerOptionsSection = "^%[PowerOptions%]%s*"
local re_AnySection = "^%[.*%]%s*"
@ -105,18 +100,6 @@ function NickelConf.colorSetting.get()
end
end
--[[--
Get auto color enabled.
@treturn bool Auto color enabled.
--]]
function NickelConf.autoColorEnabled.get()
local new_autocolor = NickelConf._read_kobo_conf(re_AutoColorEnabled)
if new_autocolor then
return (new_autocolor == "true")
end
end
--[[--
Write Kobo configuration.
@ -237,20 +220,4 @@ dbg:guard(NickelConf.colorSetting, "set",
"Wrong colorSetting value given!")
end)
--[[--
Set auto color enabled.
@bool new_autocolor
--]]
function NickelConf.autoColorEnabled.set(new_autocolor)
return NickelConf._write_kobo_conf(re_AutoColorEnabled,
auto_color_enabled_str,
new_autocolor)
end
dbg:guard(NickelConf.autoColorEnabled, "set",
function(new_autocolor)
assert(type(new_autocolor) == "boolean",
"Wrong type for autocolor (expected boolean)!")
end)
return NickelConf

@ -1,6 +1,5 @@
local BasePowerD = require("device/generic/powerd")
local NickelConf = require("device/kobo/nickel_conf")
local PluginShare = require("pluginshare")
local SysfsLight = require ("device/sysfs_light")
local ffiUtil = require("ffi/util")
local RTC = require("ffi/rtc")
@ -17,8 +16,6 @@ local KoboPowerD = BasePowerD:new{
battery_sysfs = nil,
fl_warmth_min = 0, fl_warmth_max = 100,
fl_warmth = nil,
auto_warmth = false,
max_warmth_hour = 23,
fl_was_on = nil,
}
@ -27,7 +24,6 @@ function KoboPowerD:_syncKoboLightOnStart()
local new_intensity = nil
local is_frontlight_on = nil
local new_warmth = nil
local auto_warmth = nil
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
if kobo_light_on_start then
if kobo_light_on_start > 0 then
@ -47,7 +43,6 @@ function KoboPowerD:_syncKoboLightOnStart()
-- so normalize this to [0,100] on our end.
new_warmth = (100 - math.floor((new_color - 1500) / 49))
end
auto_warmth = NickelConf.autoColorEnabled.get()
end
if is_frontlight_on == nil then
-- this device does not support frontlight toggle,
@ -71,7 +66,6 @@ function KoboPowerD:_syncKoboLightOnStart()
is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on")
if self.fl_warmth ~= nil then
new_warmth = G_reader_settings:readSetting("frontlight_warmth")
auto_warmth = G_reader_settings:readSetting("frontlight_auto_warmth")
end
end
end
@ -83,17 +77,8 @@ function KoboPowerD:_syncKoboLightOnStart()
-- will only be used to give initial state to BasePowerD:_decideFrontlightState()
self.initial_is_fl_on = is_frontlight_on
end
-- This is always read from G_reader_settings, since we do not
-- support reading 'BedTime' from NickelConf.
local max_warmth_hour =
G_reader_settings:readSetting("frontlight_max_warmth_hour")
if max_warmth_hour then
self.max_warmth_hour = max_warmth_hour
end
if auto_warmth then
self.auto_warmth = true
self:calculateAutoWarmth()
elseif new_warmth ~= nil then
if new_warmth ~= nil then
self.fl_warmth = new_warmth
end
@ -113,7 +98,6 @@ function KoboPowerD:init()
-- not be called)
self.hw_intensity = 20
self.initial_is_fl_on = true
self.autowarmth_job_running = false
if self.device:hasFrontlight() then
-- If this device has natural light (currently only KA1 & Forma)
@ -180,15 +164,11 @@ function KoboPowerD:saveSettings()
-- be turned on but we still want to save its state.
local cur_is_fl_on = self.is_fl_on or self.fl_was_on or false
local cur_warmth = self.fl_warmth
local cur_auto_warmth = self.auto_warmth
local cur_max_warmth_hour = self.max_warmth_hour
-- Save intensity to koreader settings
G_reader_settings:saveSetting("frontlight_intensity", cur_intensity)
G_reader_settings:saveSetting("is_frontlight_on", cur_is_fl_on)
if cur_warmth ~= nil then
G_reader_settings:saveSetting("frontlight_warmth", cur_warmth)
G_reader_settings:saveSetting("frontlight_auto_warmth", cur_auto_warmth)
G_reader_settings:saveSetting("frontlight_max_warmth_hour", cur_max_warmth_hour)
end
-- And to "Kobo eReader.conf" if needed
if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
@ -209,9 +189,6 @@ function KoboPowerD:saveSettings()
if NickelConf.colorSetting.get() ~= warmth_rescaled then
NickelConf.colorSetting.set(warmth_rescaled)
end
if NickelConf.autoColorEnabled.get() ~= cur_auto_warmth then
NickelConf.autoColorEnabled.set(cur_auto_warmth)
end
end
end
end
@ -250,10 +227,6 @@ end
function KoboPowerD:setWarmth(warmth)
if self.fl == nil then return end
if not warmth and self.auto_warmth then
self:calculateAutoWarmth()
self:stateChanged()
end
self.fl_warmth = warmth or self.fl_warmth
-- Don't turn the light back on on legacy NaturalLight devices just for the sake of setting the warmth!
-- That's because we can only set warmth independently of brightness on devices with a mixer.
@ -271,58 +244,6 @@ function KoboPowerD:getWarmth()
end
end
-- Sets fl_warmth according to current hour and max_warmth_hour
-- and starts background job if necessary.
function KoboPowerD:calculateAutoWarmth()
local current_time = os.date("%H") + os.date("%M")/60
local max_hour = self.max_warmth_hour
local diff_time = max_hour - current_time
if diff_time < 0 then
diff_time = diff_time + 24
end
if diff_time < 12 then
-- We are before bedtime. Use a slower progression over 5h.
self.fl_warmth = math.max(20 * (5 - diff_time), 0)
elseif diff_time > 22 then
-- Keep warmth at maximum for two hours after bedtime.
self.fl_warmth = 100
else
-- Between 2-4h after bedtime, return to zero.
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, {
when = 180,
repeated = true,
executable = function()
if self.auto_warmth then
self:setWarmth()
end
end,
})
if package.loaded["ui/uimanager"] ~= nil then
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
UIManager:broadcastEvent(Event:new("BackgroundJobsUpdated"))
end
self.autowarmth_job_running = true
end
end
function KoboPowerD:getCapacityHW()
return self:read_int_file(self.batt_capacity_file)
end
@ -405,9 +326,8 @@ function KoboPowerD:afterResume()
if self.fl == nil then return end
-- Don't bother if the light was already off on suspend
if not self.fl_was_on then return end
-- Update AutoWarmth state
if self.fl_warmth ~= nil and self.auto_warmth then
self:calculateAutoWarmth()
-- Update warmth state
if self.fl_warmth ~= nil then
-- 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)

@ -7,7 +7,7 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20210831
local CURRENT_MIGRATION_DATE = 20210925
-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
@ -312,5 +312,12 @@ if last_migration_date < 20210831 then
G_reader_settings:saveSetting("keyboard_layouts", keyboard_layouts_new)
end
-- 20210902, Remove unneeded auto_warmth settings after #8154
if last_migration_date < 20210925 then
logger.info("Performing one-time migration for 20210925")
G_reader_settings:delSetting("frontlight_auto_warmth")
G_reader_settings:delSetting("frontlight_max_warmth_hour")
end
-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)

@ -1,7 +1,6 @@
local Blitbuffer = require("ffi/blitbuffer")
local Button = require("ui/widget/button")
local CenterContainer = require("ui/widget/container/centercontainer")
local CheckButton = require("ui/widget/checkbutton")
local CloseButton = require("ui/widget/closebutton")
local Device = require("device")
local FrameContainer = require("ui/widget/container/framecontainer")
@ -39,7 +38,6 @@ local FrontLightWidget = InputContainer:new{
function FrontLightWidget:init()
self.medium_font_face = Font:getFace("ffont")
self.larger_font_face = Font:getFace("cfont")
self.light_bar = {}
self.screen_width = Screen:getWidth()
self.screen_height = Screen:getHeight()
@ -71,7 +69,6 @@ function FrontLightWidget:init()
local button_margin = Size.margin.tiny
local button_padding = Size.padding.button
local button_bordersize = Size.border.button
self.auto_nl = false
self.button_width = math.floor(self.screen_width * 0.9 / self.steps) -
2 * (button_margin + button_padding + button_bordersize)
@ -285,11 +282,9 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
local button_group_down = HorizontalGroup:new{ align = "center" }
local button_group_up = HorizontalGroup:new{ align = "center" }
local warmth_group = HorizontalGroup:new{ align = "center" }
local auto_nl_group = HorizontalGroup:new{ align = "center" }
local padding_span = VerticalSpan:new{ width = self.span }
local enable_button_plus = true
local enable_button_minus = true
local button_color = Blitbuffer.COLOR_WHITE
if self[1] then
--- @note Don't set the same value twice, to play nice with the update() sent by the swipe handler on the FL bar
@ -298,23 +293,12 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
end
end
if self.powerd.auto_warmth then
enable_button_plus = false
enable_button_minus = false
button_color = Blitbuffer.COLOR_DARK_GRAY
else
if math.floor(num_warmth / self.nl_scale) <= self.nl_min then enable_button_minus = false end
if math.ceil(num_warmth / self.nl_scale) >= self.nl_max then enable_button_plus = false end
end
if self.natural_light and num_warmth then
local curr_warmth_step = math.floor(num_warmth / step)
for i = 0, curr_warmth_step do
table.insert(warmth_group, self.fl_prog_button:new{
text = "",
preselect = curr_warmth_step > 0 and true or false,
enabled = not self.powerd.auto_warmth,
background = curr_warmth_step > 0 and button_color or nil,
callback = function()
self:setProgress(self.fl_cur, step, i * step)
end
@ -324,7 +308,6 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
for i = curr_warmth_step + 1, self.steps - 1 do
table.insert(warmth_group, self.fl_prog_button:new{
text = "",
enabled = not self.powerd.auto_warmth,
callback = function()
self:setProgress(self.fl_cur, step, i * step)
end
@ -332,6 +315,9 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
end
end
if math.floor(num_warmth / self.nl_scale) <= self.nl_min then enable_button_minus = false end
if math.ceil(num_warmth / self.nl_scale) >= self.nl_max then enable_button_plus = false end
local text_warmth = TextBoxWidget:new{
text = "\n" .. _("Warmth"),
face = self.medium_font_face,
@ -367,7 +353,7 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
text = _("Min"),
margin = Size.margin.small,
radius = 0,
enabled = not self.powerd.auto_warmth,
enabled = true,
width = math.floor(self.screen_width * 0.2),
show_parent = self,
callback = function() self:setProgress(self.fl_cur, step, self.nl_min) end,
@ -376,7 +362,7 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
text = _("Max"),
margin = Size.margin.small,
radius = 0,
enabled = not self.powerd.auto_warmth,
enabled = true,
width = math.floor(self.screen_width * 0.2),
show_parent = self,
callback = function() self:setProgress(self.fl_cur, step, (self.nl_max * self.nl_scale)) end,
@ -396,92 +382,10 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
empty_space,
button_max,
}
local checkbutton_auto_nl = CheckButton:new({
text = _("Auto"),
checked = self.powerd.auto_warmth,
max_width = math.floor(self.screen_width * 0.15),
callback = function()
if self.powerd.auto_warmth then
self.powerd.auto_warmth = false
else
self.powerd.auto_warmth = true
self.powerd:calculateAutoWarmth()
end
self:setProgress(self.fl_cur, step)
end
})
local text_auto_nl, text_hour, button_minus_one_hour, button_plus_one_hour
if not self.has_nl_api then
text_auto_nl = TextBoxWidget:new{
--- @todo Implement padding_right (etc.) on TextBoxWidget and remove the two-space hack.
text = _("Max. at:") .. " ",
face = self.larger_font_face,
alignment = "right",
fgcolor = self.powerd.auto_warmth and Blitbuffer.COLOR_BLACK or
Blitbuffer.COLOR_DARK_GRAY,
width = math.floor(self.screen_width * 0.3),
}
text_hour = TextBoxWidget:new{
text = " " .. math.floor(self.powerd.max_warmth_hour) .. ":" ..
self.powerd.max_warmth_hour % 1 * 6 .. "0",
face = self.larger_font_face,
alignment = "center",
fgcolor =self.powerd.auto_warmth and Blitbuffer.COLOR_BLACK or
Blitbuffer.COLOR_DARK_GRAY,
width = math.floor(self.screen_width * 0.15),
}
button_minus_one_hour = Button:new{
text = "",
margin = Size.margin.small,
radius = 0,
enabled = self.powerd.auto_warmth,
width = math.floor(self.screen_width * 0.1),
show_parent = self,
callback = function()
self.powerd.max_warmth_hour =
(self.powerd.max_warmth_hour - 1) % 24
self.powerd:calculateAutoWarmth()
self:setProgress(self.fl_cur, step)
end,
hold_callback = function()
self.powerd.max_warmth_hour =
(self.powerd.max_warmth_hour - 0.5) % 24
self.powerd:calculateAutoWarmth()
self:setProgress(self.fl_cur, step)
end,
}
button_plus_one_hour = Button:new{
text = "",
margin = Size.margin.small,
radius = 0,
enabled = self.powerd.auto_warmth,
width = math.floor(self.screen_width * 0.1),
show_parent = self,
callback = function()
self.powerd.max_warmth_hour =
(self.powerd.max_warmth_hour + 1) % 24
self.powerd:calculateAutoWarmth()
self:setProgress(self.fl_cur, step)
end,
hold_callback = function()
self.powerd.max_warmth_hour =
(self.powerd.max_warmth_hour + 0.5) % 24
self.powerd:calculateAutoWarmth()
self:setProgress(self.fl_cur, step)
end,
}
end
table.insert(vertical_group, text_warmth)
table.insert(button_group_up, button_table_up)
table.insert(button_group_down, button_table_down)
table.insert(auto_nl_group, checkbutton_auto_nl)
table.insert(auto_nl_group, text_auto_nl)
table.insert(auto_nl_group, button_minus_one_hour)
table.insert(auto_nl_group, text_hour)
table.insert(auto_nl_group, button_plus_one_hour)
table.insert(vertical_group, padding_span)
table.insert(vertical_group, button_group_up)
@ -491,9 +395,6 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
table.insert(vertical_group, button_group_down)
table.insert(vertical_group, padding_span)
if not self.has_nl_api then
table.insert(vertical_group, auto_nl_group)
end
end
function FrontLightWidget:setFrontLightIntensity(num)

Loading…
Cancel
Save