2014-10-30 18:42:18 +00:00
|
|
|
local BasePowerD = require("device/generic/powerd")
|
2016-06-23 17:50:24 +00:00
|
|
|
local _, android = pcall(require, "android")
|
2014-07-15 08:23:38 +00:00
|
|
|
|
|
|
|
local AndroidPowerD = BasePowerD:new{
|
2020-08-02 20:27:49 +00:00
|
|
|
fl_min = 0,
|
|
|
|
fl_max = 100,
|
2014-07-15 08:23:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 12:42:39 +00:00
|
|
|
-- Let the footer know of the change
|
|
|
|
local function broadcastLightChanges()
|
|
|
|
if package.loaded["ui/uimanager"] ~= nil then
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-08 06:29:57 +00:00
|
|
|
function AndroidPowerD:frontlightIntensityHW()
|
2020-08-02 20:27:49 +00:00
|
|
|
return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max)
|
2014-07-15 08:23:38 +00:00
|
|
|
end
|
|
|
|
|
2017-06-15 22:27:04 +00:00
|
|
|
function AndroidPowerD:setIntensityHW(intensity)
|
2020-08-25 12:42:39 +00:00
|
|
|
-- if frontlight switch was toggled of, turn it on
|
2020-09-09 15:58:44 +00:00
|
|
|
android.enableFrontlightSwitch()
|
2020-08-25 12:42:39 +00:00
|
|
|
|
2020-08-02 20:27:49 +00:00
|
|
|
self.fl_intensity = intensity
|
|
|
|
android.setScreenBrightness(math.floor(intensity * self.bright_diff / self.fl_max))
|
|
|
|
end
|
|
|
|
|
|
|
|
function AndroidPowerD:init()
|
2020-09-09 15:58:44 +00:00
|
|
|
local min_bright = android.getScreenMinBrightness()
|
|
|
|
self.bright_diff = android.getScreenMaxBrightness() - min_bright
|
2020-08-25 12:42:39 +00:00
|
|
|
|
|
|
|
-- if necessary scale fl_min:
|
|
|
|
-- do not use fl_min==0 if getScreenMinBrightness!=0,
|
|
|
|
-- because intenstiy==0 would mean to use system intensity
|
2020-09-09 15:58:44 +00:00
|
|
|
if min_bright ~= self.fl_min then
|
|
|
|
self.fl_min = math.ceil(min_bright * self.bright_diff / self.fl_max)
|
2020-08-25 12:42:39 +00:00
|
|
|
end
|
|
|
|
|
2020-08-02 20:27:49 +00:00
|
|
|
if self.device:hasNaturalLight() then
|
2020-09-09 15:58:44 +00:00
|
|
|
self.fl_warmth_min = android.getScreenMinWarmth()
|
|
|
|
self.fl_warmth_max = android.getScreenMaxWarmth()
|
|
|
|
self.warm_diff = self.fl_warmth_max - self.fl_warmth_min
|
2020-08-02 20:27:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
function AndroidPowerD:setWarmthHW(warmth)
|
|
|
|
android.setScreenWarmth(warmth)
|
2020-08-02 20:27:49 +00:00
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
function AndroidPowerD:frontlightWarmthHW()
|
2020-08-02 20:27:49 +00:00
|
|
|
return android.getScreenWarmth() * self.warm_diff
|
2014-07-15 08:23:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function AndroidPowerD:getCapacityHW()
|
2017-03-24 06:36:15 +00:00
|
|
|
return android.getBatteryLevel()
|
2014-07-15 08:23:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function AndroidPowerD:isChargingHW()
|
2017-03-24 06:36:15 +00:00
|
|
|
return android.isCharging()
|
2014-07-15 08:23:38 +00:00
|
|
|
end
|
|
|
|
|
2020-08-25 12:42:39 +00:00
|
|
|
function AndroidPowerD:turnOffFrontlightHW()
|
|
|
|
if not self:isFrontlightOnHW() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
android.setScreenBrightness(self.fl_min)
|
|
|
|
self.is_fl_on = false
|
|
|
|
broadcastLightChanges()
|
|
|
|
end
|
|
|
|
|
|
|
|
function AndroidPowerD:turnOnFrontlightHW()
|
|
|
|
if self:isFrontlightOn() and self:isFrontlightOnHW() then
|
|
|
|
return
|
|
|
|
end
|
2020-08-29 14:42:57 +00:00
|
|
|
-- on devices with a software frontlight switch (e.g Tolinos), enable it
|
|
|
|
android.enableFrontlightSwitch()
|
|
|
|
|
2020-08-25 12:42:39 +00:00
|
|
|
android.setScreenBrightness(math.floor(self.fl_intensity * self.bright_diff / self.fl_max))
|
|
|
|
|
|
|
|
self.is_fl_on = true
|
|
|
|
broadcastLightChanges()
|
|
|
|
end
|
|
|
|
|
2014-07-15 08:23:38 +00:00
|
|
|
return AndroidPowerD
|