diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index 2c52109a3..aec07ed95 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -3,17 +3,23 @@ Only PowerOptions:FrontLightLevel is currently supported . ]] +local dbg = require("dbg") + local NickelConf = {} NickelConf.frontLightLevel = {} NickelConf.frontLightState = {} +NickelConf.colorSetting = {} 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" -- 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*$" local re_PowerOptionsSection = "^%[PowerOptions%]%s*" local re_AnySection = "^%[.*%]%s*" @@ -69,6 +75,14 @@ function NickelConf.frontLightState.get() return new_state end +function NickelConf.colorSetting.get() + local new_colorsetting = NickelConf._read_kobo_conf(re_ColorSetting) + if new_colorsetting then + return tonumber(new_colorsetting) + end + return nil +end + function NickelConf._write_kobo_conf(re_Match, key, value, dont_create) local kobo_conf = io.open(kobo_conf_path, "r") local lines = {} @@ -143,4 +157,16 @@ function NickelConf.frontLightState.set(new_state) true) end +function NickelConf.colorSetting.set(new_color) + return NickelConf._write_kobo_conf(re_ColorSetting, + color_setting_str, + new_color) +end + +dbg:guard(NickelConf.colorSetting, 'set', + function(self, new_color) + assert(new_color >= 1500 and new_color <= 6400, + "Wrong colorSetting value given!") + end) + return NickelConf diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 397cd66b8..9984927d1 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -23,6 +23,7 @@ local KoboPowerD = BasePowerD:new{ function KoboPowerD:_syncKoboLightOnStart() local new_intensity = nil local is_frontlight_on = nil + local new_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 @@ -34,6 +35,14 @@ function KoboPowerD:_syncKoboLightOnStart() elseif kobo_light_on_start == -2 then -- get values from NickelConf new_intensity = NickelConf.frontLightLevel.get() is_frontlight_on = NickelConf.frontLightState:get() + if self.fl_warmth ~= nil then + local new_color = NickelConf.colorSetting.get() + if new_color ~= nil then + -- ColorSetting is in [1500,6400], with '1500' + -- being maximum warmth, so normalize this to [0,100] + new_warmth = (100 - math.floor((new_color - 1500) / 49)) + end + end if is_frontlight_on == nil then -- this device does not support frontlight toggle, -- we set the value based on frontlight intensity. @@ -54,6 +63,9 @@ function KoboPowerD:_syncKoboLightOnStart() -- stored in koreader settings new_intensity = G_reader_settings:readSetting("frontlight_intensity") is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on") + if self.fl_warmth ~= nil then + new_warmth = G_reader_settings:readSetting("frontlight_warmth") + end end end @@ -64,6 +76,9 @@ 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 + self.fl_warmth = new_warmth + end -- In any case frontlight is off, ensure intensity is non-zero so untoggle works if self.initial_is_fl_on == false and self.hw_intensity == 0 then @@ -103,9 +118,13 @@ function KoboPowerD:saveSettings() -- untoggled intensity and toggle state at next startup) local cur_intensity = self.fl_intensity local cur_is_fl_on = self.is_fl_on + local cur_warmth = self.fl_warmth -- 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) + end -- And to "Kobo eReader.conf" if needed if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then if NickelConf.frontLightState.get() ~= nil then @@ -120,6 +139,12 @@ function KoboPowerD:saveSettings() if NickelConf.frontLightLevel.get() ~= cur_intensity then NickelConf.frontLightLevel.set(cur_intensity) end + if cur_warmth ~= nil then + local warmth_rescaled = (100 - cur_warmth) * 49 + 1500 + if NickelConf.colorSetting.get() ~= warmth_rescaled then + NickelConf.colorSetting.set(warmth_rescaled) + end + end end end end