From 4d1df962f5ff230a77321ae926ab4965f20db3a5 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 4 Jan 2014 22:15:23 +0800 Subject: [PATCH] cache battery level in BasePowerD Since we need to pull it frequently but usually it doesn't change that often. --- frontend/ui/device/basepowerd.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/ui/device/basepowerd.lua b/frontend/ui/device/basepowerd.lua index 6fe44df70..20f26cafe 100644 --- a/frontend/ui/device/basepowerd.lua +++ b/frontend/ui/device/basepowerd.lua @@ -3,7 +3,10 @@ local BasePowerD = { fl_max = 10, -- max frontlight intensity flIntensity = nil, -- frontlight intensity battCapacity = nil, -- battery capacity - model = nil -- device model + model = nil, -- device model + + capacity_pulled_count = 0, + capacity_cached_count = 10, } function BasePowerD:new(o) @@ -37,7 +40,13 @@ function BasePowerD:setIntensity(intensity) end function BasePowerD:getCapacity() - return self:getCapacityHW() + if capacity_pulled_count == capacity_cached_count then + capacity_pulled_count = 0 + return self:getCapacityHW() + else + capacity_pulled_count = capacity_pulled_count + 1 + return self.battCapacity or self:getCapacityHW() + end end function BasePowerD:isCharging()