kobo/powerd: Use sysfs interface for natural light support

If the device has natural light support (currently only KA1), use the
sysfs interface instead of the ioctl-based one. It might also be
usable on other Kobo devices for setting brightness without natural
light, but since I cannot test this, this is currently restricted to
the KA1.
pull/3665/head
David Engster 6 years ago committed by Frans de Jonge
parent 7aefad6de9
commit 5c1f97eeb3

@ -1,5 +1,6 @@
local BasePowerD = require("device/generic/powerd") local BasePowerD = require("device/generic/powerd")
local NickelConf = require("device/kobo/nickel_conf") local NickelConf = require("device/kobo/nickel_conf")
local SysfsLight = require ("device/kobo/sysfs_light")
local batt_state_folder = local batt_state_folder =
"/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/" "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/"
@ -15,6 +16,7 @@ local KoboPowerD = BasePowerD:new{
batt_capacity_file = batt_state_folder .. "capacity", batt_capacity_file = batt_state_folder .. "capacity",
is_charging_file = batt_state_folder .. "status", is_charging_file = batt_state_folder .. "status",
fl_warmth = nil,
} }
-- TODO: Remove KOBO_LIGHT_ON_START -- TODO: Remove KOBO_LIGHT_ON_START
@ -77,11 +79,19 @@ function KoboPowerD:init()
self.initial_is_fl_on = true self.initial_is_fl_on = true
if self.device.hasFrontlight() then if self.device.hasFrontlight() then
local kobolight = require("ffi/kobolight") -- If this device has natural light (currently only KA1)
local ok, light = pcall(kobolight.open) -- use the SysFS interface, and ioctl otherwise.
if ok then if self.device.hasNaturalLight() then
self.fl = light self.fl = SysfsLight
self.fl_warmth = 0
self:_syncKoboLightOnStart() self:_syncKoboLightOnStart()
else
local kobolight = require("ffi/kobolight")
local ok, light = pcall(kobolight.open)
if ok then
self.fl = light
self:_syncKoboLightOnStart()
end
end end
end end
end end
@ -135,7 +145,11 @@ end
function KoboPowerD:setIntensityHW(intensity) function KoboPowerD:setIntensityHW(intensity)
if self.fl == nil then return end if self.fl == nil then return end
self.fl:setBrightness(intensity) if self.fl_warmth == nil then
self.fl:setBrightness(intensity)
else
self.fl:setNaturalBrightness(intensity, self.fl_warmth)
end
self.hw_intensity = intensity self.hw_intensity = intensity
-- Now that we have set intensity, we need to let BasePowerD -- Now that we have set intensity, we need to let BasePowerD
-- know about possibly changed frontlight state (if we came -- know about possibly changed frontlight state (if we came
@ -143,6 +157,12 @@ function KoboPowerD:setIntensityHW(intensity)
self:_decideFrontlightState() self:_decideFrontlightState()
end end
function KoboPowerD:setWarmth(warmth)
if self.fl == nil then return end
self.fl_warmth = warmth
self.fl:setWarmth(warmth)
end
function KoboPowerD:getCapacityHW() function KoboPowerD:getCapacityHW()
return self:read_int_file(self.batt_capacity_file) return self:read_int_file(self.batt_capacity_file)
end end
@ -162,7 +182,11 @@ end
function KoboPowerD:afterResume() function KoboPowerD:afterResume()
if self.fl == nil then return end if self.fl == nil then return end
-- just re-set it to self.hw_intensity that we haven't change on Suspend -- just re-set it to self.hw_intensity that we haven't change on Suspend
self.fl:setBrightness(self.hw_intensity) if self.fl_warmth == nil then
self.fl:setBrightness(self.hw_intensity)
else
self.fl:setNaturalBrightness(self.hw_intensity, self.fl_warmth)
end
end end
return KoboPowerD return KoboPowerD

Loading…
Cancel
Save