mirror of https://github.com/koreader/koreader
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
Lua
68 lines
1.9 KiB
Lua
10 years ago
|
local BasePowerD = require("device/generic/powerd")
|
||
11 years ago
|
-- liblipclua, see require below
|
||
|
|
||
|
local KindlePowerD = BasePowerD:new{
|
||
11 years ago
|
fl_min = 0, fl_max = 24,
|
||
10 years ago
|
|
||
11 years ago
|
flIntensity = nil,
|
||
|
battCapacity = nil,
|
||
|
is_charging = nil,
|
||
|
lipc_handle = nil,
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
function KindlePowerD:init()
|
||
11 years ago
|
local lipc = require("liblipclua")
|
||
|
if lipc then
|
||
10 years ago
|
self.lipc_handle = lipc.init("com.github.koreader.kindlepowerd")
|
||
11 years ago
|
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
|
||
11 years ago
|
end
|
||
|
|
||
|
function KindlePowerD:toggleFrontlight()
|
||
11 years ago
|
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
|
||
11 years ago
|
end
|
||
|
|
||
|
function KindlePowerD:setIntensityHW()
|
||
11 years ago
|
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
|
||
11 years ago
|
end
|
||
|
|
||
|
function KindlePowerD:getCapacityHW()
|
||
11 years ago
|
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
|
||
11 years ago
|
end
|
||
|
|
||
|
function KindlePowerD:isChargingHW()
|
||
11 years ago
|
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
|
||
11 years ago
|
end
|
||
|
|
||
10 years ago
|
function KindlePowerD:__gc()
|
||
10 years ago
|
if self.lipc_handle then
|
||
|
self.lipc_handle:close()
|
||
10 years ago
|
self.lipc_handle = nil
|
||
10 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
return KindlePowerD
|