mirror of https://github.com/koreader/koreader
refactoring frontlight device to more generic power device
parent
b6b3207a79
commit
92b62c907a
@ -1,25 +0,0 @@
|
||||
local BaseFrontLight = {
|
||||
min = 1, max = 10,
|
||||
intensity = nil,
|
||||
}
|
||||
|
||||
function BaseFrontLight:new(o)
|
||||
local o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
if o.init then o:init() end
|
||||
return o
|
||||
end
|
||||
|
||||
function BaseFrontLight:init() end
|
||||
function BaseFrontLight:toggle() end
|
||||
function BaseFrontLight:setIntensityHW() end
|
||||
|
||||
function BaseFrontLight:setIntensity(intensity)
|
||||
intensity = intensity < self.min and self.min or intensity
|
||||
intensity = intensity > self.max and self.max or intensity
|
||||
self.intensity = intensity
|
||||
self:setIntensityHW()
|
||||
end
|
||||
|
||||
return BaseFrontLight
|
@ -0,0 +1,55 @@
|
||||
local BasePowerD = {
|
||||
fl_min = 0, -- min frontlight intensity
|
||||
fl_max = 10, -- max frontlight intensity
|
||||
flIntensity = nil, -- frontlight intensity
|
||||
battCapacity = nil, -- battery capacity
|
||||
model = nil -- device model
|
||||
}
|
||||
|
||||
function BasePowerD:new(o)
|
||||
local o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
if o.init then o:init() end
|
||||
return o
|
||||
end
|
||||
|
||||
function BasePowerD:init() end
|
||||
function BasePowerD:toggleFrontlight() end
|
||||
function BasePowerD:setIntensityHW() end
|
||||
function BasePowerD:getCapacityHW() end
|
||||
function BasePowerD:isChargingHW() end
|
||||
function BasePowerD:suspendHW() end
|
||||
function BasePowerD:wakeUpHW() end
|
||||
|
||||
function BasePowerD:read_int_file(file)
|
||||
local f = io.open(file, "r")
|
||||
local sysint = tonumber(f:read("*all"):match("%d+"))
|
||||
f:close()
|
||||
return sysint
|
||||
end
|
||||
|
||||
function BasePowerD:setIntensity(intensity)
|
||||
intensity = intensity < self.fl_min and self.fl_min or intensity
|
||||
intensity = intensity > self.fl_max and self.fl_max or intensity
|
||||
self.flIntensity = intensity
|
||||
self:setIntensityHW()
|
||||
end
|
||||
|
||||
function BasePowerD:getCapacity()
|
||||
return self:getCapacityHW()
|
||||
end
|
||||
|
||||
function BasePowerD:isCharging()
|
||||
return self:isChargingHW()
|
||||
end
|
||||
|
||||
function BasePowerD:suspend()
|
||||
return self:suspendHW()
|
||||
end
|
||||
|
||||
function BasePowerD:wakeUp()
|
||||
return self:wakeUpHW()
|
||||
end
|
||||
|
||||
return BasePowerD
|
@ -1,37 +0,0 @@
|
||||
local BaseFrontLight = require("ui/device/basefrontlight")
|
||||
-- liblipclua, see require below
|
||||
|
||||
local KindleFrontLight = BaseFrontLight:new{
|
||||
min = 0, max = 24,
|
||||
-- FIXME: Check how to handle this on the PW2, initial reports on IRC suggest that this isn't possible anymore
|
||||
kpw_fl = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity",
|
||||
intensity = nil,
|
||||
lipc_handle = nil,
|
||||
}
|
||||
|
||||
function KindleFrontLight:init()
|
||||
require "liblipclua"
|
||||
self.lipc_handle = lipc.init("com.github.koreader")
|
||||
if self.lipc_handle then
|
||||
self.intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
|
||||
end
|
||||
end
|
||||
|
||||
function KindleFrontLight:toggle()
|
||||
local f = io.open(self.kpw_fl, "r")
|
||||
local sysint = tonumber(f:read("*all"):match("%d+"))
|
||||
f:close()
|
||||
if sysint == 0 then
|
||||
self:setIntensity(self.intensity)
|
||||
else
|
||||
os.execute("echo -n 0 > " .. self.kpw_fl)
|
||||
end
|
||||
end
|
||||
|
||||
function KindleFrontLight:setIntensityHW()
|
||||
if self.lipc_handle ~= nil then
|
||||
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.intensity)
|
||||
end
|
||||
end
|
||||
|
||||
return KindleFrontLight
|
@ -0,0 +1,82 @@
|
||||
local BasePowerD = require("ui/device/basepowerd")
|
||||
-- liblipclua, see require below
|
||||
|
||||
local KindlePowerD = BasePowerD:new{
|
||||
fl_min = 0, fl_max = 24,
|
||||
-- FIXME: Check how to handle this on the PW2, initial reports on IRC suggest that this isn't possible anymore
|
||||
kpw_frontlight = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity",
|
||||
kt_kpw_capacity = "/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity",
|
||||
kpw_charging = "/sys/devices/platform/aplite_charger.0/charging",
|
||||
kt_charging = "/sys/devices/platform/fsl-usb2-udc/charging",
|
||||
|
||||
flIntensity = nil,
|
||||
battCapacity = nil,
|
||||
isCharging = nil,
|
||||
lipc_handle = nil,
|
||||
}
|
||||
|
||||
function KindlePowerD:new(o)
|
||||
local o = o or {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
if o.init then o:init(o.model) end
|
||||
return o
|
||||
end
|
||||
|
||||
function KindlePowerD:init(model)
|
||||
local lipc = require("liblipclua")
|
||||
if lipc then
|
||||
self.lipc_handle = lipc.init("com.github.koreader")
|
||||
end
|
||||
|
||||
if model == "KindleTouch" then
|
||||
self.batt_capacity_file = self.kt_kpw_capacity
|
||||
self.is_charging_file = self.kt_charging
|
||||
elseif model == "KindlePaperWhite" or model == "KindlePaperWhite2" then
|
||||
self.fl_intensity_file = self.kpw_frontlight
|
||||
self.batt_capacity_file = self.kt_kpw_capacity
|
||||
self.is_charging_file = self.kpw_charging
|
||||
end
|
||||
if self.lipc_handle then
|
||||
self.flIntensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity")
|
||||
else
|
||||
self.flIntensity = self:read_int_file(self.fl_intensity_file)
|
||||
end
|
||||
end
|
||||
|
||||
function KindlePowerD:toggleFrontlight()
|
||||
local sysint = self:read_int_file(self.fl_intensity_file)
|
||||
if sysint == 0 then
|
||||
self:setIntensity(self.flIntensity)
|
||||
else
|
||||
os.execute("echo -n 0 > " .. self.fl_intensity_file)
|
||||
end
|
||||
end
|
||||
|
||||
function KindlePowerD:setIntensityHW()
|
||||
if self.lipc_handle ~= nil then
|
||||
self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.flIntensity)
|
||||
else
|
||||
os.execute("echo -n ".. self.flIntensity .." > " .. self.fl_intensity_file)
|
||||
end
|
||||
end
|
||||
|
||||
function KindlePowerD:getCapacityHW()
|
||||
if self.lipc_handle ~= nil then
|
||||
self.battCapacity = self.lipc_handle:get_int_property("com.lab126.powerd", "battLevel")
|
||||
else
|
||||
self.battCapacity = self:read_int_file(self.batt_capacity_file)
|
||||
end
|
||||
return self.battCapacity
|
||||
end
|
||||
|
||||
function KindlePowerD:isChargingHW()
|
||||
if self.lipc_handle ~= nil then
|
||||
self.isCharging = self.lipc_handle:get_int_property("com.lab126.powerd", "isCharging")
|
||||
else
|
||||
self.isCharging = self:read_int_file(self.is_charging_file)
|
||||
end
|
||||
return self.isCharging
|
||||
end
|
||||
|
||||
return KindlePowerD
|
@ -1,26 +0,0 @@
|
||||
local BaseFrontLight = require("ui/device/basefrontlight")
|
||||
|
||||
local KoboFrontLight = BaseFrontLight:new{
|
||||
min = 1, max = 100,
|
||||
intensity = 20,
|
||||
restore_settings = true,
|
||||
fl = nil,
|
||||
}
|
||||
|
||||
function KoboFrontLight:init()
|
||||
self.fl = kobolight.open()
|
||||
end
|
||||
|
||||
function KoboFrontLight:toggle()
|
||||
if self.fl ~= nil then
|
||||
self.fl:toggle()
|
||||
end
|
||||
end
|
||||
|
||||
function KoboFrontLight:setIntensityHW()
|
||||
if self.fl ~= nil then
|
||||
self.fl:setBrightness(self.intensity)
|
||||
end
|
||||
end
|
||||
|
||||
return KoboFrontLight
|
@ -0,0 +1,26 @@
|
||||
local BasePowerD = require("ui/device/basepowerd")
|
||||
|
||||
local KoboPowerD = BasePowerD:new{
|
||||
fl_min = 1, fl_max = 100,
|
||||
flIntensity = 20,
|
||||
restore_settings = true,
|
||||
fl = nil,
|
||||
}
|
||||
|
||||
function KoboPowerD:init()
|
||||
self.fl = kobolight.open()
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
return KoboPowerD
|
Loading…
Reference in New Issue