2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/device/generic/powerd.lua
Hans-Werner Hilse 3066c86e38 Refactoring hardware abstraction
This is a major overhaul of the hardware abstraction layer.
A few notes:

General platform distinction happens in
  frontend/device.lua
which will delegate everything else to
  frontend/device/<platform_name>/device.lua
which should extend
  frontend/device/generic/device.lua

Screen handling is implemented in
  frontend/device/screen.lua
which includes the *functionality* to support device specifics.
Actually setting up the device specific functionality, however,
is done in the device specific setup code in the relevant
device.lua file.

The same goes for input handling.
2014-11-02 21:19:04 +01:00

78 lines
2.0 KiB
Lua

local BasePowerD = {
fl_min = 0, -- min frontlight intensity
fl_max = 10, -- max frontlight intensity
flIntensity = nil, -- frontlight intensity
battCapacity = nil, -- battery capacity
device = nil, -- device object
capacity_pulled_count = 0,
capacity_cached_count = 10,
}
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:setIntensitySW() end
function BasePowerD:getCapacityHW() return "0" end
function BasePowerD:isChargingHW() end
function BasePowerD:suspendHW() end
function BasePowerD:wakeUpHW() end
function BasePowerD:read_int_file(file)
local fd = io.open(file, "r")
if fd then
local int = fd:read("*all"):match("%d+")
fd:close()
return int and tonumber(int) or 0
else
return 0
end
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:setIntensityWithoutHW(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:setIntensitySW()
end
function BasePowerD:getCapacity()
if self.capacity_pulled_count == self.capacity_cached_count then
self.capacity_pulled_count = 0
return self:getCapacityHW()
else
self.capacity_pulled_count = self.capacity_pulled_count + 1
return self.battCapacity or self:getCapacityHW()
end
end
function BasePowerD:isCharging()
return self:isChargingHW()
end
function BasePowerD:suspend()
return self:suspendHW()
end
function BasePowerD:wakeUp()
return self:wakeUpHW()
end
return BasePowerD