mirror of
https://github.com/koreader/koreader
synced 2024-11-04 12:00:25 +00:00
AutoWarmth: Fix frontlight flash after resume and weird true midnight settings (#9730)
This commit is contained in:
parent
4a355f789d
commit
629304adce
@ -82,6 +82,14 @@ function AutoWarmth:init()
|
|||||||
self.control_nightmode = true
|
self.control_nightmode = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Fix entries not in ascending order (only happens by manual editing of settings.reader.lua)
|
||||||
|
for i = 1, #self.scheduler_times - 1 do
|
||||||
|
if self.scheduler_times[i] > self.scheduler_times[i + 1] then
|
||||||
|
self.scheduler_times[i + 1] = self.scheduler_times[i]
|
||||||
|
logger.warn("AutoWarmth: scheduling times fixed.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- schedule recalculation shortly afer midnight
|
-- schedule recalculation shortly afer midnight
|
||||||
self:scheduleMidnightUpdate()
|
self:scheduleMidnightUpdate()
|
||||||
end
|
end
|
||||||
@ -130,7 +138,6 @@ function AutoWarmth:onAutoWarmthMode()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function AutoWarmth:leavePowerSavingState(from_resume)
|
function AutoWarmth:leavePowerSavingState(from_resume)
|
||||||
logger.dbg("AutoWarmth: onResume/onLeaveStandby")
|
|
||||||
local resume_date = os.date("*t")
|
local resume_date = os.date("*t")
|
||||||
|
|
||||||
-- check if resume and suspend are done on the same day
|
-- check if resume and suspend are done on the same day
|
||||||
@ -146,14 +153,17 @@ function AutoWarmth:leavePowerSavingState(from_resume)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function AutoWarmth:_onResume()
|
function AutoWarmth:_onResume()
|
||||||
|
logger.dbg("AutoWarmth: onResume")
|
||||||
self:leavePowerSavingState(true)
|
self:leavePowerSavingState(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function AutoWarmth:_onLeaveStandby()
|
function AutoWarmth:_onLeaveStandby()
|
||||||
|
logger.dbg("AutoWarmth: onLeaveStandby")
|
||||||
self:leavePowerSavingState(false)
|
self:leavePowerSavingState(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function AutoWarmth:_onSuspend()
|
function AutoWarmth:_onSuspend()
|
||||||
|
logger.dbg("AutoWarmth: onSuspend")
|
||||||
UIManager:unschedule(self.scheduleMidnightUpdate)
|
UIManager:unschedule(self.scheduleMidnightUpdate)
|
||||||
UIManager:unschedule(self.setWarmth)
|
UIManager:unschedule(self.setWarmth)
|
||||||
end
|
end
|
||||||
@ -179,7 +189,7 @@ function AutoWarmth:scheduleMidnightUpdate(from_resume)
|
|||||||
logger.dbg("AutoWarmth: scheduleMidnightUpdate")
|
logger.dbg("AutoWarmth: scheduleMidnightUpdate")
|
||||||
-- first unschedule all old functions
|
-- first unschedule all old functions
|
||||||
UIManager:unschedule(self.scheduleMidnightUpdate)
|
UIManager:unschedule(self.scheduleMidnightUpdate)
|
||||||
UIManager:unschedule(AutoWarmth.setWarmth)
|
UIManager:unschedule(self.setWarmth)
|
||||||
|
|
||||||
SunTime:setPosition(self.location, self.latitude, self.longitude, self.timezone, self.altitude, true)
|
SunTime:setPosition(self.location, self.latitude, self.longitude, self.timezone, self.altitude, true)
|
||||||
SunTime:setAdvanced()
|
SunTime:setAdvanced()
|
||||||
@ -291,7 +301,7 @@ end
|
|||||||
-- from_resume ... true if first call after resume
|
-- from_resume ... true if first call after resume
|
||||||
function AutoWarmth:scheduleNextWarmthChange(time_s, search_pos, from_resume)
|
function AutoWarmth:scheduleNextWarmthChange(time_s, search_pos, from_resume)
|
||||||
logger.dbg("AutoWarmth: scheduleNextWarmthChange")
|
logger.dbg("AutoWarmth: scheduleNextWarmthChange")
|
||||||
UIManager:unschedule(AutoWarmth.setWarmth)
|
UIManager:unschedule(self.setWarmth)
|
||||||
|
|
||||||
if self.activate == 0 or #self.sched_warmths == 0 or search_pos > #self.sched_warmths then
|
if self.activate == 0 or #self.sched_warmths == 0 or search_pos > #self.sched_warmths then
|
||||||
return
|
return
|
||||||
@ -309,39 +319,40 @@ function AutoWarmth:scheduleNextWarmthChange(time_s, search_pos, from_resume)
|
|||||||
-- before true midnight. OK, this value is actually not quite the right one, as it is calculated
|
-- before true midnight. OK, this value is actually not quite the right one, as it is calculated
|
||||||
-- for the current day (and not the previous one), but this is for a corner case
|
-- for the current day (and not the previous one), but this is for a corner case
|
||||||
-- and the error is small.
|
-- and the error is small.
|
||||||
local actual_warmth = self.sched_warmths[self.sched_warmth_index or #self.sched_warmths]
|
local actual_warmth = self.sched_warmths[self.sched_warmth_index]
|
||||||
local next_warmth = actual_warmth
|
local next_warmth = actual_warmth
|
||||||
for i = self.sched_warmth_index, #self.sched_warmths do
|
for i = self.sched_warmth_index, #self.sched_warmths do
|
||||||
if self.sched_times_s[i] <= time_s then
|
-- It might be possible that actual_warmth == self.sched_warmth[#self.sched_warmths]
|
||||||
actual_warmth = self.sched_warmths[i]
|
-- in this case next self.sched_warmth_index should be #self.sched_warmths
|
||||||
local j = i
|
self.sched_warmth_index = i
|
||||||
while from_resume and j <= #self.sched_warmths and self.sched_times_s[j] <= time_s + delay_s do
|
|
||||||
-- Most times only one iteration through this loop
|
if self.sched_times_s[i] > time_s then
|
||||||
next_warmth = self.sched_warmths[j]
|
|
||||||
j = j + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.sched_warmth_index = i
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
|
||||||
-- update current warmth immediately
|
-- update actual_warmth and next_warmth
|
||||||
self:setWarmth(actual_warmth, false) -- no setWarmth rescheduling, don't force warmth
|
actual_warmth = self.sched_warmths[i]
|
||||||
if self.sched_warmth_index <= #self.sched_warmths then
|
local j = i
|
||||||
local next_sched_time_s = self.sched_times_s[self.sched_warmth_index] - time_s
|
while from_resume and j <= #self.sched_warmths and self.sched_times_s[j] <= time_s + delay_s do
|
||||||
if next_sched_time_s > 0 then
|
-- Most times only one iteration through this loop
|
||||||
-- This setWarmth will call scheduleNextWarmthChange which will schedule setWarmth again.
|
next_warmth = self.sched_warmths[j]
|
||||||
UIManager:scheduleIn(next_sched_time_s, self.setWarmth, self, self.sched_warmths[self.sched_warmth_index], true)
|
j = j + 1
|
||||||
elseif self.sched_warmth_index < #self.sched_warmths then
|
|
||||||
-- If this really happens under strange conditions, wait until the next full minute to
|
|
||||||
-- minimize wakeups from standby.
|
|
||||||
UIManager:scheduleIn(61 - tonumber(os.date("%S")),
|
|
||||||
self.setWarmth, self, self.sched_warmths[self.sched_warmth_index], true)
|
|
||||||
else
|
|
||||||
logger.dbg("AutoWarmth: schedule is over, waiting for midnight update")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- update current warmth immediately
|
||||||
|
self:setWarmth(actual_warmth, false) -- no setWarmth rescheduling, don't force warmth
|
||||||
|
local next_sched_time_s = self.sched_times_s[self.sched_warmth_index] - time_s
|
||||||
|
if next_sched_time_s <= 0 then
|
||||||
|
-- If this really happens under strange conditions (after the last scheduler entry
|
||||||
|
-- (true midnight) and before 00:00),
|
||||||
|
-- wait until the next full minute to minimize wakeups from standby.
|
||||||
|
next_sched_time_s = 61 - tonumber(os.date("%S"))
|
||||||
|
end
|
||||||
|
-- This setWarmth will call scheduleNextWarmthChange which will schedule setWarmth again.
|
||||||
|
UIManager:scheduleIn(next_sched_time_s,
|
||||||
|
self.setWarmth, self, self.sched_warmths[self.sched_warmth_index], true)
|
||||||
|
|
||||||
if from_resume then
|
if from_resume then
|
||||||
-- On some strange devices like KA1 setWarmth doesn't work right after a resume so
|
-- On some strange devices like KA1 setWarmth doesn't work right after a resume so
|
||||||
-- schedule setting of another valid warmth (=`next_warmth`) again (one time).
|
-- schedule setting of another valid warmth (=`next_warmth`) again (one time).
|
||||||
@ -729,11 +740,11 @@ function AutoWarmth:getScheduleMenu()
|
|||||||
store_times(touchmenu_instance, new_time, num)
|
store_times(touchmenu_instance, new_time, num)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
elseif num < 10 and new_time > get_valid_time(num, 1) then
|
elseif num < midnight_index and new_time > get_valid_time(num, 1) then
|
||||||
UIManager:show(ConfirmBox:new{
|
UIManager:show(ConfirmBox:new{
|
||||||
text = _("This time is after the subsequent time.\nAdjust the subsequent time?"),
|
text = _("This time is after the subsequent time.\nAdjust the subsequent time?"),
|
||||||
ok_callback = function()
|
ok_callback = function()
|
||||||
for i = num + 1, midnight_index - 1 do
|
for i = num + 1, midnight_index do
|
||||||
if self.scheduler_times[i] then
|
if self.scheduler_times[i] then
|
||||||
if new_time > self.scheduler_times[i] then
|
if new_time > self.scheduler_times[i] then
|
||||||
self.scheduler_times[i] = new_time
|
self.scheduler_times[i] = new_time
|
||||||
|
Loading…
Reference in New Issue
Block a user