2014-01-04 13:38:07 +00:00
|
|
|
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
|
2014-10-30 18:42:18 +00:00
|
|
|
device = nil, -- device object
|
2014-07-07 02:50:16 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
capacity_pulled_count = 0,
|
|
|
|
capacity_cached_count = 10,
|
2014-01-04 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function BasePowerD:new(o)
|
2016-02-16 07:10:07 +00:00
|
|
|
o = o or {}
|
2014-03-13 13:52:43 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
if o.init then o:init() end
|
|
|
|
return o
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:init() end
|
|
|
|
function BasePowerD:toggleFrontlight() end
|
|
|
|
function BasePowerD:setIntensityHW() end
|
2014-07-08 16:19:00 +00:00
|
|
|
function BasePowerD:getCapacityHW() return "0" end
|
2014-01-04 13:38:07 +00:00
|
|
|
function BasePowerD:isChargingHW() end
|
|
|
|
function BasePowerD:suspendHW() end
|
|
|
|
function BasePowerD:wakeUpHW() end
|
|
|
|
|
|
|
|
function BasePowerD:read_int_file(file)
|
2014-07-15 08:45:09 +00:00
|
|
|
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
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2015-01-17 15:54:49 +00:00
|
|
|
function BasePowerD:read_str_file(file)
|
|
|
|
local fd = io.open(file, "r")
|
|
|
|
if fd then
|
|
|
|
local str = fd:read("*all")
|
|
|
|
fd:close()
|
|
|
|
return str
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
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()
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:getCapacity()
|
2014-07-07 02:50:16 +00:00
|
|
|
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
|
2014-07-07 02:50:16 +00:00
|
|
|
self.capacity_pulled_count = self.capacity_pulled_count + 1
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.battCapacity or self:getCapacityHW()
|
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2015-02-01 04:49:46 +00:00
|
|
|
function BasePowerD:refreshCapacity()
|
2015-10-16 00:49:39 +00:00
|
|
|
-- We want our next getCapacity call to actually pull up to date info instead of a cached value ;)
|
|
|
|
self.capacity_pulled_count = self.capacity_cached_count
|
2015-02-01 04:49:46 +00:00
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
function BasePowerD:isCharging()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self:isChargingHW()
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:suspend()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self:suspendHW()
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:wakeUp()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self:wakeUpHW()
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return BasePowerD
|