From 5c1f97eeb3e31798d5a0e9ba1f849e68751a926c Mon Sep 17 00:00:00 2001 From: David Engster Date: Sun, 4 Feb 2018 12:35:14 +0100 Subject: [PATCH] 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. --- frontend/device/kobo/powerd.lua | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 9cc168a36..397cd66b8 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -1,5 +1,6 @@ local BasePowerD = require("device/generic/powerd") local NickelConf = require("device/kobo/nickel_conf") +local SysfsLight = require ("device/kobo/sysfs_light") local batt_state_folder = "/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", is_charging_file = batt_state_folder .. "status", + fl_warmth = nil, } -- TODO: Remove KOBO_LIGHT_ON_START @@ -77,11 +79,19 @@ function KoboPowerD:init() self.initial_is_fl_on = true if self.device.hasFrontlight() then - local kobolight = require("ffi/kobolight") - local ok, light = pcall(kobolight.open) - if ok then - self.fl = light + -- If this device has natural light (currently only KA1) + -- use the SysFS interface, and ioctl otherwise. + if self.device.hasNaturalLight() then + self.fl = SysfsLight + self.fl_warmth = 0 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 @@ -135,7 +145,11 @@ end function KoboPowerD:setIntensityHW(intensity) 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 -- Now that we have set intensity, we need to let BasePowerD -- know about possibly changed frontlight state (if we came @@ -143,6 +157,12 @@ function KoboPowerD:setIntensityHW(intensity) self:_decideFrontlightState() end +function KoboPowerD:setWarmth(warmth) + if self.fl == nil then return end + self.fl_warmth = warmth + self.fl:setWarmth(warmth) +end + function KoboPowerD:getCapacityHW() return self:read_int_file(self.batt_capacity_file) end @@ -162,7 +182,11 @@ end function KoboPowerD:afterResume() if self.fl == nil then return end -- 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 return KoboPowerD