2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/frontend/device/android/powerd.lua
chrox 687b6df4f2 add support of screen brightness settings for Android
and use standrad Android API to query battery level and charging status
This should fix #2025, fix #1759 and fix #1415.
2016-06-24 02:05:20 +08:00

31 lines
795 B
Lua

local BasePowerD = require("device/generic/powerd")
local _, android = pcall(require, "android")
local AndroidPowerD = BasePowerD:new{
fl_min = 0, fl_max = 25,
fl_intensity = 10,
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()
android.setScreenBrightness(math.floor(255 * self.fl_intensity / 25))
end
function AndroidPowerD:getCapacityHW()
self.battCapacity = android.getBatteryLevel()
return self.battCapacity
end
function AndroidPowerD:isChargingHW()
self.is_charging = android.isCharging()
return self.is_charging
end
return AndroidPowerD