2014-10-30 18:42:18 +00:00
|
|
|
local BasePowerD = require("device/generic/powerd")
|
2016-01-07 14:30:28 +00:00
|
|
|
local NickelConf = require("device/kobo/nickel_conf")
|
2014-01-04 13:38:07 +00:00
|
|
|
|
2016-02-25 08:54:41 +00:00
|
|
|
local batt_state_folder =
|
|
|
|
"/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/"
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
local KoboPowerD = BasePowerD:new{
|
2016-02-25 08:54:41 +00:00
|
|
|
-- Do not actively set front light to 0, it may confuse users -- pressing
|
|
|
|
-- hardware button won't take any effect.
|
|
|
|
fl_min = 1, fl_max = 100,
|
2016-03-02 06:06:21 +00:00
|
|
|
fl_intensity = 20,
|
2014-03-13 13:52:43 +00:00
|
|
|
restore_settings = true,
|
|
|
|
fl = nil,
|
2016-03-02 06:59:48 +00:00
|
|
|
|
|
|
|
-- We will set this value for all kobo models. but it will only be synced
|
|
|
|
-- with nickel's FrontLightState config if the current model has a
|
|
|
|
-- frontlight toggle button.
|
2016-03-02 06:06:21 +00:00
|
|
|
is_fl_on = false,
|
2016-03-02 06:59:48 +00:00
|
|
|
|
2016-02-25 08:54:41 +00:00
|
|
|
batt_capacity_file = batt_state_folder .. "capacity",
|
|
|
|
is_charging_file = batt_state_folder .. "status",
|
2014-03-13 13:52:43 +00:00
|
|
|
battCapacity = nil,
|
|
|
|
is_charging = nil,
|
2014-01-04 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function KoboPowerD:init()
|
2014-12-02 10:15:23 +00:00
|
|
|
if self.device.hasFrontlight() then
|
|
|
|
local kobolight = require("ffi/kobolight")
|
|
|
|
local ok, light = pcall(kobolight.open)
|
2016-03-02 06:59:48 +00:00
|
|
|
if ok then
|
|
|
|
self.fl = light
|
|
|
|
if NickelConf.frontLightState.get() ~= nil then
|
|
|
|
self.has_fl_toggle_btn = true
|
|
|
|
else
|
|
|
|
self.has_fl_toggle_btn = false
|
|
|
|
end
|
|
|
|
end
|
2014-12-02 10:15:23 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KoboPowerD:toggleFrontlight()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.fl ~= nil then
|
2016-03-02 06:06:21 +00:00
|
|
|
if self.is_fl_on then
|
2016-02-25 08:54:41 +00:00
|
|
|
self.fl:setBrightness(0)
|
|
|
|
else
|
2016-03-02 06:06:21 +00:00
|
|
|
self.fl:setBrightness(self.fl_intensity)
|
2016-02-25 08:54:41 +00:00
|
|
|
end
|
2016-03-02 06:06:21 +00:00
|
|
|
self.is_fl_on = not self.is_fl_on
|
2016-03-02 06:59:48 +00:00
|
|
|
if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
|
2016-03-02 06:06:21 +00:00
|
|
|
NickelConf.frontLightState.set(self.is_fl_on)
|
2016-02-25 08:54:41 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KoboPowerD:setIntensityHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.fl ~= nil then
|
2016-03-02 06:06:21 +00:00
|
|
|
self.fl:setBrightness(self.fl_intensity)
|
2016-01-07 14:30:28 +00:00
|
|
|
if KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
|
2016-03-02 06:06:21 +00:00
|
|
|
NickelConf.frontLightLevel.set(self.fl_intensity)
|
2016-01-07 14:30:28 +00:00
|
|
|
end
|
2016-03-02 06:59:48 +00:00
|
|
|
-- also keep self.is_fl_on in sync with intensity if needed
|
|
|
|
local is_fl_on
|
|
|
|
if self.fl_intensity > 0 then
|
|
|
|
is_fl_on = true
|
|
|
|
else
|
|
|
|
is_fl_on = false
|
|
|
|
end
|
|
|
|
if self.is_fl_on ~= is_fl_on then
|
|
|
|
self.is_fl_on = is_fl_on
|
|
|
|
if self.has_fl_toggle_btn and KOBO_SYNC_BRIGHTNESS_WITH_NICKEL then
|
|
|
|
NickelConf.frontLightState.set(self.is_fl_on)
|
|
|
|
end
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2014-01-04 16:29:41 +00:00
|
|
|
function KoboPowerD:getCapacityHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.battCapacity = self:read_int_file(self.batt_capacity_file)
|
|
|
|
return self.battCapacity
|
2014-01-04 16:29:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KoboPowerD:isChargingHW()
|
2015-02-02 16:27:59 +00:00
|
|
|
self.is_charging = self:read_str_file(self.is_charging_file) == "Charging\n"
|
|
|
|
return self.is_charging
|
2014-01-04 16:29:41 +00:00
|
|
|
end
|
|
|
|
|
2016-02-26 09:46:23 +00:00
|
|
|
-- Turn off front light before suspend.
|
|
|
|
function KoboPowerD:beforeSuspend()
|
2016-02-29 19:12:50 +00:00
|
|
|
if self.fl ~= nil then
|
2016-02-26 09:46:23 +00:00
|
|
|
self.fl:setBrightness(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Restore front light state after resume.
|
|
|
|
function KoboPowerD:afterResume()
|
2016-02-29 19:12:50 +00:00
|
|
|
if self.fl ~= nil then
|
|
|
|
if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then
|
|
|
|
self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100))
|
2016-03-02 06:06:21 +00:00
|
|
|
elseif self.is_fl_on then
|
|
|
|
self.fl:setBrightness(self.fl_intensity)
|
2016-02-29 19:12:50 +00:00
|
|
|
end
|
2016-02-26 09:46:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
return KoboPowerD
|