2014-01-04 13:38:07 +00:00
|
|
|
local BasePowerD = require("ui/device/basepowerd")
|
|
|
|
-- liblipclua, see require below
|
|
|
|
|
|
|
|
local KindlePowerD = BasePowerD:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
fl_min = 0, fl_max = 24,
|
|
|
|
kpw1_frontlight = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity",
|
|
|
|
kpw2_frontlight = "/sys/class/backlight/max77696-bl/brightness",
|
|
|
|
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,
|
|
|
|
is_charging = nil,
|
|
|
|
lipc_handle = nil,
|
2014-01-04 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function KindlePowerD:new(o)
|
2014-03-13 13:52:43 +00:00
|
|
|
local o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.init then o:init(o.model) end
|
|
|
|
return o
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:init(model)
|
2014-03-13 13:52:43 +00:00
|
|
|
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" then
|
|
|
|
self.fl_intensity_file = self.kpw1_frontlight
|
|
|
|
self.batt_capacity_file = self.kt_kpw_capacity
|
|
|
|
self.is_charging_file = self.kpw_charging
|
|
|
|
elseif model == "KindlePaperWhite2" then
|
|
|
|
self.fl_intensity_file = self.kpw2_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
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:toggleFrontlight()
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:setIntensityHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:getCapacityHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function KindlePowerD:isChargingHW()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.lipc_handle ~= nil then
|
|
|
|
self.is_charging = self.lipc_handle:get_int_property("com.lab126.powerd", "isCharging")
|
|
|
|
else
|
|
|
|
self.is_charging = self:read_int_file(self.is_charging_file)
|
|
|
|
end
|
|
|
|
return self.is_charging == 1
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return KindlePowerD
|