From b9ffb2e0d092c3e164c8be38bca096e17be459a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= Date: Wed, 19 Aug 2020 22:41:10 +0200 Subject: [PATCH] pocketbook: warmth lights support (#6531) * also enables natural light controls for the emulator --- frontend/device/generic/device.lua | 1 + frontend/device/pocketbook/device.lua | 12 +++ frontend/device/pocketbook/powerd.lua | 13 +++ frontend/device/sdl/device.lua | 2 + frontend/device/sdl/powerd.lua | 21 +++- frontend/ui/widget/frontlightwidget.lua | 128 +++++++++++++----------- 6 files changed, 116 insertions(+), 61 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index e2e56e23e..8320a8354 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -41,6 +41,7 @@ local Device = { hasFrontlight = no, hasNaturalLight = no, -- FL warmth implementation specific to NTX boards (Kobo, Cervantes) hasNaturalLightMixer = no, -- Same, but only found on newer boards + hasNaturalLightApi = no, needsTouchScreenProbe = no, hasClipboard = yes, -- generic internal clipboard on all devices hasEinkScreen = yes, diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index a1dc4a2f9..103027616 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -46,6 +46,7 @@ ffi.cdef[[ char *GetSoftwareVersion(void); char *GetDeviceModel(void); int GetNetState(void); +int GetFrontlightColor(void); int NetConnect(const char *name); int NetDisconnect(); ]] @@ -66,6 +67,10 @@ local PocketBook = Generic:new{ canSuspend = no, emu_events_dev = "/dev/shm/emu_events", home_dir = "/mnt/ext1", + + -- all devices that have warmth lights use inkview api + hasNaturalLightApi = yes, + } -- Make sure the C BB cannot be used on devices with a 24bpp fb @@ -308,6 +313,7 @@ local PocketBook628 = PocketBook:new{ model = "PBTouchLux5", display_dpi = 212, isAlwaysPortrait = yes, + hasNaturalLight = yes, } -- PocketBook Sense / Sense 2 (630) @@ -320,6 +326,8 @@ local PocketBook630 = PocketBook:new{ local PocketBook631 = PocketBook:new{ model = "PBTouchHD", display_dpi = 300, + -- see https://github.com/koreader/koreader/pull/6531#issuecomment-676629182 + hasNaturalLight = function() return inkview.GetFrontlightColor() >= 0 end, } -- PocketBook Touch HD Plus / Touch HD 3 (632) @@ -327,6 +335,7 @@ local PocketBook632 = PocketBook:new{ model = "PBTouchHDPlus", display_dpi = 300, isAlwaysPortrait = yes, + hasNaturalLight = yes, } -- PocketBook Color (633) @@ -361,6 +370,7 @@ local PocketBook740 = PocketBook:new{ model = "PBInkPad3", display_dpi = 300, isAlwaysPortrait = yes, + hasNaturalLight = yes, } -- PocketBook InkPad 3 Pro (740_2) @@ -368,6 +378,7 @@ local PocketBook740_2 = PocketBook:new{ model = "PBInkPad3Pro", display_dpi = 300, isAlwaysPortrait = yes, + hasNaturalLight = yes, } -- PocketBook Color Lux (801) @@ -390,6 +401,7 @@ local PocketBook1040 = PocketBook:new{ model = "PB1040", display_dpi = 227, isAlwaysPortrait = yes, + hasNaturalLight = yes, } logger.info('SoftwareVersion: ', PocketBook:getSoftwareVersion()) diff --git a/frontend/device/pocketbook/powerd.lua b/frontend/device/pocketbook/powerd.lua index cc3aa3c0f..ff65b6fae 100644 --- a/frontend/device/pocketbook/powerd.lua +++ b/frontend/device/pocketbook/powerd.lua @@ -5,20 +5,28 @@ local inkview = ffi.load("inkview") ffi.cdef[[ void OpenScreen(); int GetFrontlightState(void); +int GetFrontlightColor(void); void SetFrontlightState(int flstate); +void SetFrontlightColor(int color); int GetBatteryPower(); int IsCharging(); ]] local PocketBookPowerD = BasePowerD:new{ is_charging = nil, + fl_warmth = nil, + fl_min = 0, fl_max = 100, + fl_warmth_min = 0, + fl_warmth_max = 100, } function PocketBookPowerD:init() -- needed for SetFrontlightState / GetFrontlightState inkview.OpenScreen() + local color = inkview.GetFrontlightColor() + self.fl_warmth = color >= 0 and color or 0 end function PocketBookPowerD:frontlightIntensityHW() @@ -34,6 +42,11 @@ function PocketBookPowerD:setIntensityHW(intensity) end end +function PocketBookPowerD:setWarmth(level) + self.fl_warmth = level or self.fl_warmth + inkview.SetFrontlightColor(self.fl_warmth) +end + function PocketBookPowerD:getCapacityHW() return inkview.GetBatteryPower() end diff --git a/frontend/device/sdl/device.lua b/frontend/device/sdl/device.lua index 25b469ce9..6a1fa6f7a 100644 --- a/frontend/device/sdl/device.lua +++ b/frontend/device/sdl/device.lua @@ -113,6 +113,8 @@ local Emulator = Device:new{ hasBattery = yes, hasEinkScreen = yes, hasFrontlight = yes, + hasNaturalLight = yes, + hasNaturalLightApi = yes, hasWifiToggle = yes, hasWifiManager = yes, canPowerOff = yes, diff --git a/frontend/device/sdl/powerd.lua b/frontend/device/sdl/powerd.lua index 011485f56..db363b291 100644 --- a/frontend/device/sdl/powerd.lua +++ b/frontend/device/sdl/powerd.lua @@ -1,7 +1,26 @@ local BasePowerD = require("device/generic/powerd") local SDL = require("ffi/SDL2_0") -local SDLPowerD = BasePowerD:new{} +local SDLPowerD = BasePowerD:new{ + -- these values are just used on the emulator + hw_intensity = 50, + fl_min = 0, + fl_max = 100, + fl_warmth = 50, + fl_warmth_min = 0, + fl_warmth_max = 100, +} + +function SDLPowerD:setIntensityHW(intensity) + require("logger").info("set brightness to", intensity) + self.hw_intensity = intensity or self.hw_intensity +end + + +function SDLPowerD:setWarmth(level) + require("logger").info("set warmth to", level) + self.fl_warmth = level or self.fl_warmth +end function SDLPowerD:getCapacityHW() local _, _, _, percent = SDL.getPowerInfo() diff --git a/frontend/ui/widget/frontlightwidget.lua b/frontend/ui/widget/frontlightwidget.lua index 0560fd55d..40baac8ee 100644 --- a/frontend/ui/widget/frontlightwidget.lua +++ b/frontend/ui/widget/frontlightwidget.lua @@ -58,6 +58,7 @@ function FrontLightWidget:init() self.steps = math.min(self.steps, steps_fl) self.natural_light = Device:hasNaturalLight() self.has_nl_mixer = Device:hasNaturalLightMixer() + self.has_nl_api = Device:hasNaturalLightApi() -- Handle Warmth separately, because it may use a different scale if self.natural_light then self.nl_min = self.powerd.fl_warmth_min @@ -254,7 +255,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth) -- 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) - if not self.has_nl_mixer then + if not self.has_nl_mixer and not self.has_nl_api then self.configure_button = Button:new{ text = _("Configure"), margin = Size.margin.small, @@ -409,64 +410,68 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group) end }) - local 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), - } - local 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), - } - local 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, - } - local 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, - } + 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) @@ -484,7 +489,10 @@ function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group) table.insert(vertical_group, padding_span) table.insert(vertical_group, button_group_down) table.insert(vertical_group, padding_span) - table.insert(vertical_group, auto_nl_group) + + if not self.has_nl_api then + table.insert(vertical_group, auto_nl_group) + end end function FrontLightWidget:setFrontLightIntensity(num)