Merge pull request #728 from chrox/master

add API to query battery status on Android
This commit is contained in:
Qingping Hou
2014-07-15 13:20:12 -04:00
3 changed files with 37 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
local AndroidPowerd = require("ui/device/androidpowerd")
local KindlePowerD = require("ui/device/kindlepowerd")
local KoboPowerD = require("ui/device/kobopowerd")
local BasePowerD = require("ui/device/basepowerd")
@@ -259,6 +260,8 @@ function Device:getPowerDevice()
self.powerd = KindlePowerD:new{model = model}
elseif self:isKobo() then
self.powerd = KoboPowerD:new()
elseif self.isAndroid then
self.powerd = AndroidPowerd:new()
else -- emulated FrontLight
self.powerd = BasePowerD:new()
end

View File

@@ -0,0 +1,26 @@
local BasePowerD = require("ui/device/basepowerd")
local AndroidPowerD = BasePowerD:new{
batt_capacity_file = "/sys/class/power_supply/battery/capacity",
is_charging_file = "/sys/class/power_supply/battery/charging_enabled",
battCapacity = nil,
is_charging = nil,
}
function AndroidPowerD:init()
end
function AndroidPowerD:setIntensityHW()
end
function AndroidPowerD:getCapacityHW()
self.battCapacity = self:read_int_file(self.batt_capacity_file)
return self.battCapacity
end
function AndroidPowerD:isChargingHW()
self.is_charging = self:read_int_file(self.is_charging_file)
return self.is_charging == 1
end
return AndroidPowerD

View File

@@ -27,10 +27,14 @@ function BasePowerD:suspendHW() end
function BasePowerD:wakeUpHW() end
function BasePowerD:read_int_file(file)
local f = io.open(file, "r")
local sysint = tonumber(f:read("*all"):match("%d+"))
f:close()
return sysint
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)