Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natural light configuration #3744

Merged
merged 6 commits into from Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/device/kobo/device.lua
Expand Up @@ -32,6 +32,7 @@ local Kobo = Generic:new{
internal_storage_mount_point = "/mnt/onboard/",
-- currently only Aura One has coloured frontlight
hasNaturalLight = no,
frontlight_settings = {},
}

-- TODO: hasKeys for some devices?
Expand Down
6 changes: 6 additions & 0 deletions frontend/device/kobo/powerd.lua
Expand Up @@ -97,6 +97,12 @@ function KoboPowerD:init()
-- If this device has natural light (currently only KA1)
-- use the SysFS interface, and ioctl otherwise.
if self.device.hasNaturalLight() then
local nl_config = G_reader_settings:readSetting("natural_light_config")
if nl_config then
for key,val in pairs(nl_config) do
self.device.frontlight_settings[key] = val
end
end
self.fl = SysfsLight:new(self.device.frontlight_settings)
self.fl_warmth = 0
self:_syncKoboLightOnStart()
Expand Down
31 changes: 23 additions & 8 deletions frontend/device/kobo/sysfs_light.lua
Expand Up @@ -17,6 +17,7 @@ local KoboSysfsLight = {
white_offset = -25,
red_offset = 0,
green_offset = -65,
exponent = 0.25,
}

function KoboSysfsLight:new(o)
Expand Down Expand Up @@ -48,14 +49,28 @@ dbg:guard(KoboSysfsLight, 'setWarmth',
end)

function KoboSysfsLight:setNaturalBrightness(brightness, warmth)
-- On Nickel, the values for white/red/green are roughly linearly dependent
-- on the 4th root of brightness and warmth.
local white = math.min(self.white_gain * math.pow(brightness, 0.25) *
math.pow(100 - warmth, 0.25) + self.white_offset, 255)
local red = math.min(self.red_gain * math.pow(brightness, 0.25) *
math.pow(warmth, 0.25) + self.red_offset, 255)
local green = math.min(self.green_gain * math.pow(brightness, 0.25) *
math.pow(warmth, 0.25) + self.green_offset, 255)
if not brightness then
brightness = self.current_brightness
end
if not warmth then
warmth = self.current_warmth
end

local red = 0
local green = 0
local white = 0
if brightness > 0 then
-- On Nickel, the values for white/red/green are roughly linearly dependent
-- on the 4th root of brightness and warmth.
white = math.min(self.white_gain * math.pow(brightness, self.exponent) *
math.pow(100 - warmth, self.exponent) + self.white_offset, 255)
end
if warmth > 0 then
red = math.min(self.red_gain * math.pow(brightness, self.exponent) *
math.pow(warmth, self.exponent) + self.red_offset, 255)
green = math.min(self.green_gain * math.pow(brightness, self.exponent) *
math.pow(warmth, self.exponent) + self.green_offset, 255)
end

white = math.max(white, 0)
red = math.max(red, 0)
Expand Down
47 changes: 44 additions & 3 deletions frontend/ui/widget/frontlightwidget.lua
Expand Up @@ -11,6 +11,7 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local InputContainer = require("ui/widget/container/inputcontainer")
local LineWidget = require("ui/widget/linewidget")
local NaturalLight = require("ui/widget/naturallightwidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local Size = require("ui/size")
local TextBoxWidget = require("ui/widget/textboxwidget")
Expand All @@ -27,6 +28,8 @@ local FrontLightWidget = InputContainer:new{
title_face = Font:getFace("x_smalltfont"),
width = nil,
height = nil,
-- This should stay active during natural light configuration
is_always_active = true,
}

function FrontLightWidget:init()
Expand Down Expand Up @@ -243,8 +246,21 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
table.insert(vertical_group,button_group_down)
table.insert(vertical_group,padding_span)
if self.natural_light then
-- If the device supports natural light, add the widgets for 'warmth'.
-- If the device supports natural light, add the widgets for 'warmth'
-- and a 'Configure' button
self:addWarmthWidgets(num_warmth, step, vertical_group)
self.configure_button = Button:new{
text = _("Configure"),
margin = Size.margin.small,
radius = 0,
width = self.screen_width * 0.20,
enabled = not self.nl_configure_open,
show_parent = self,
callback = function()
UIManager:show(NaturalLight:new{fl_widget = self})
end,
}
table.insert(vertical_group, self.configure_button)
end
table.insert(self.fl_container, vertical_group)
-- Reset container height to what it actually contains
Expand Down Expand Up @@ -455,8 +471,11 @@ function FrontLightWidget:onAnyKeyPressed()
end

function FrontLightWidget:onTapCloseFL(arg, ges_ev)
if ges_ev.pos:notIntersectWith(self.light_frame.dimen) then
self:onClose()
-- Do not close when natural light configuration is open
if not self.nl_configure_open then
if ges_ev.pos:notIntersectWith(self.light_frame.dimen) then
self:onClose()
end
end
return true
end
Expand All @@ -466,4 +485,26 @@ function FrontLightWidget:onClose()
return true
end

-- This is called when natural light configuration is shown
function FrontLightWidget:naturalLightConfigOpen()
-- Remove the close button
table.remove(self.light_bar)
-- Disable the 'configure' button
self.configure_button:disable()
self.nl_configure_open = true
-- Move to the bottom to make place for the new widget
self[1].align="bottom"
UIManager:setDirty("all", "ui")
end

function FrontLightWidget:naturalLightConfigClose()
table.insert(self.light_bar,
CloseButton:new{window = self,
padding_top = Size.margin.title})
self.configure_button:enable()
self.nl_configure_open = false
self[1].align="center"
UIManager:setDirty("all", "ui")
end

return FrontLightWidget