2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/device/kobo/powerd.lua
Dimitrios Semitsoglou-Tsiapos eb47c5a39f Synchronise frontlight level with nickel config
* Drops support for mocking the frontlight setting internally which may
  cause incorrect in-memory values.

* Adds new supported value for `KOBO_LIGHT_ON_START` (-2), which sets
  'Kobo eReader.conf' as the source to update `settings.reader.lua`'s
  brightness setting on startup, thus using the value from it
  indirectly.

* Adds the `KOBO_SYNC_BRIGHTNESS_WITH_NICKEL` configuration variable
  which updates 'Kobo eReader.conf' every time the brightness setting is
  changed within koreader.

* Fixes missing call to save brightness when modifying via two-finger
  swipe.

Closes #1523.
2016-01-11 23:30:22 +02:00

50 lines
1.3 KiB
Lua

local BasePowerD = require("device/generic/powerd")
local NickelConf = require("device/kobo/nickel_conf")
local KoboPowerD = BasePowerD:new{
fl_min = 0, fl_max = 100,
flIntensity = 20,
restore_settings = true,
fl = nil,
batt_capacity_file = "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity",
is_charging_file = "/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status",
battCapacity = nil,
is_charging = nil,
}
function KoboPowerD:init()
if self.device.hasFrontlight() then
local kobolight = require("ffi/kobolight")
local ok, light = pcall(kobolight.open)
if ok then self.fl = light end
end
end
function KoboPowerD:toggleFrontlight()
if self.fl ~= nil then
self.fl:toggle()
end
end
function KoboPowerD:setIntensityHW()
if self.fl ~= nil then
self.fl:setBrightness(self.flIntensity)
if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
NickelConf.frontLightLevel.set(self.flIntensity)
end
end
end
function KoboPowerD:getCapacityHW()
self.battCapacity = self:read_int_file(self.batt_capacity_file)
return self.battCapacity
end
function KoboPowerD:isChargingHW()
self.is_charging = self:read_str_file(self.is_charging_file) == "Charging\n"
return self.is_charging
end
return KoboPowerD