[feat] kobo/powerd, kobo/nickel_conf: Saving of auto-warmth settings

Add support in nickel_conf to save/retrieve setting of
'autoColorEnabled', which is the automatic warmth feature in
Nickel. We do not support reading of 'BedTime', because it is encoded
as a QVariant. This setting is hence saved/loaded solely in/from
G_reader_settings.
pull/3823/head
David Engster 6 years ago committed by Frans de Jonge
parent 596e20e588
commit e80951413d

@ -9,17 +9,22 @@ 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*"
@ -83,6 +88,13 @@ function NickelConf.colorSetting.get()
return nil
end
function NickelConf.autoColorEnabled.get()
local new_autocolor = NickelConf._read_kobo_conf(re_AutoColorEnabled)
if new_autocolor then
return (new_autocolor == "true")
end
end
function NickelConf._write_kobo_conf(re_Match, key, value, dont_create)
local kobo_conf = io.open(kobo_conf_path, "r")
local lines = {}
@ -163,10 +175,22 @@ function NickelConf.colorSetting.set(new_color)
new_color)
end
function NickelConf.autoColorEnabled.set(new_autocolor)
return NickelConf._write_kobo_conf(re_AutoColorEnabled,
auto_color_enabled_str,
new_autocolor)
end
dbg:guard(NickelConf.colorSetting, 'set',
function(self, new_color)
assert(new_color >= 1500 and new_color <= 6400,
"Wrong colorSetting value given!")
end)
dbg:guard(NickelConf.autoColorEnabled, 'set',
function(self, new_autocolor)
assert(type(new_autocolor) == "boolean",
"Wrong type for autocolor (expected boolean)!")
end)
return NickelConf

@ -27,6 +27,7 @@ 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
@ -45,6 +46,7 @@ function KoboPowerD:_syncKoboLightOnStart()
-- being maximum warmth, so normalize this to [0,100]
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,
@ -68,6 +70,7 @@ 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
@ -79,7 +82,17 @@ function KoboPowerD:_syncKoboLightOnStart()
-- will only be used to give initial state to BasePowerD:_decideFrontlightState()
self.initial_is_fl_on = is_frontlight_on
end
if new_warmth ~= nil then
-- 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
self.fl_warmth = new_warmth
end
@ -129,11 +142,15 @@ function KoboPowerD: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
-- And to "Kobo eReader.conf" if needed
if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
@ -154,6 +171,9 @@ 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
@ -255,6 +275,9 @@ function KoboPowerD: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

Loading…
Cancel
Save