pocketbook: warmth lights support (#6531)

* also enables natural light controls for the emulator
reviewable/pr6541/r1
Martín Fernández 4 years ago committed by GitHub
parent 01ed79fb92
commit b9ffb2e0d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,

@ -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())

@ -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

@ -113,6 +113,8 @@ local Emulator = Device:new{
hasBattery = yes,
hasEinkScreen = yes,
hasFrontlight = yes,
hasNaturalLight = yes,
hasNaturalLightApi = yes,
hasWifiToggle = yes,
hasWifiManager = yes,
canPowerOff = yes,

@ -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()

@ -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)

Loading…
Cancel
Save