2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/frontend/ui/device/basepowerd.lua

74 lines
1.9 KiB
Lua
Raw Normal View History

local BasePowerD = {
2014-03-13 13:52:43 +00:00
fl_min = 0, -- min frontlight intensity
fl_max = 10, -- max frontlight intensity
flIntensity = nil, -- frontlight intensity
battCapacity = nil, -- battery capacity
model = nil, -- device model
2014-03-13 13:52:43 +00:00
capacity_pulled_count = 0,
capacity_cached_count = 10,
}
function BasePowerD: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() 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)
2014-03-13 13:52:43 +00:00
local f = io.open(file, "r")
local sysint = tonumber(f:read("*all"):match("%d+"))
f:close()
return sysint
end
function BasePowerD:setIntensity(intensity)
2014-03-13 13:52:43 +00:00
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
2014-03-13 13:52:43 +00:00
return self:getCapacityHW()
else
self.capacity_pulled_count = self.capacity_pulled_count + 1
2014-03-13 13:52:43 +00:00
return self.battCapacity or self:getCapacityHW()
end
end
function BasePowerD:isCharging()
2014-03-13 13:52:43 +00:00
return self:isChargingHW()
end
function BasePowerD:suspend()
2014-03-13 13:52:43 +00:00
return self:suspendHW()
end
function BasePowerD:wakeUp()
2014-03-13 13:52:43 +00:00
return self:wakeUpHW()
end
return BasePowerD