Author: fmueller
Date: Mon Aug 16 06:33:05 2010
New Revision: 9054

URL: http://svn.slimdevices.com/jive?rev=9054&view=rev
Log:
Bug: 16408 
Description: Clean up statusbar functions. 

Modified:
    
7.6/trunk/squeezeplay/src/squeezeplay_jive/share/applets/SqueezeboxJive/SqueezeboxJiveApplet.lua

Modified: 
7.6/trunk/squeezeplay/src/squeezeplay_jive/share/applets/SqueezeboxJive/SqueezeboxJiveApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.6/trunk/squeezeplay/src/squeezeplay_jive/share/applets/SqueezeboxJive/SqueezeboxJiveApplet.lua?rev=9054&r1=9053&r2=9054&view=diff
==============================================================================
--- 
7.6/trunk/squeezeplay/src/squeezeplay_jive/share/applets/SqueezeboxJive/SqueezeboxJiveApplet.lua
 (original)
+++ 
7.6/trunk/squeezeplay/src/squeezeplay_jive/share/applets/SqueezeboxJive/SqueezeboxJiveApplet.lua
 Mon Aug 16 06:33:05 2010
@@ -1,6 +1,6 @@
 
 -- stuff we use
-local ipairs, pcall, tonumber, tostring = ipairs, pcall, tonumber, tostring
+local ipairs, pcall, tonumber, tostring, unpack = ipairs, pcall, tonumber, 
tostring, unpack
 
 local oo                     = require("loop.simple")
 local string                 = require("string")
@@ -61,6 +61,10 @@
 local SW_AC_POWER            = 0
 local SW_PHONE_DETECT        = 1
 
+local UPDATE_WIRELESS        = 0x01
+local UPDATE_POWER           = 0x02
+
+
 local squeezeboxjiveTitleStyle = 'settingstitle'
 module(..., Framework.constants)
 oo.class(_M, SqueezeboxApplet)
@@ -133,8 +137,11 @@
                self:_cpuPowerOverride(active)
        end)
 
-       iconbar.iconWireless:addTimer(5000, function()  -- every 5 seconds
-             self:update()
+       -- status bar updates
+       local updateTask = Task("statusbar", self, _updateTask)
+       updateTask:addTask(UPDATE_WIRELESS | UPDATE_POWER)
+       iconbar.iconWireless:addTimer(5000, function()  -- every five seconds
+               updateTask:addTask(UPDATE_WIRELESS | UPDATE_POWER)
        end)
 
        Framework:addListener(EVENT_SWITCH,
@@ -146,7 +153,7 @@
                                              log:info("acpower=", val)
 
                                              self.acpower = (val == 0)
-                                             self:update()
+                                             updateTask:addTask(UPDATE_POWER)
 
                                              if self.acpower then
                                                      
self:setPowerState("dimmed")
@@ -229,9 +236,6 @@
        -- headphone or speaker
        local headphoneInserted = jiveBSP.ioctl(18)
        self:headphoneJack(headphoneInserted)
-
-       -- set initial state
-       self:update()
 
        -- open audio device
        Decode:open(settings)
@@ -308,14 +312,47 @@
 end
 
 
-function update(self)
-        Task("statusbar", self, _updateTask):addTask()
-end
-
-
-function _updateTask(self)
+local function _updateWirelessDone(self, iface, success)
        local player = Player:getLocalPlayer()
 
+       -- wireless
+       if success then
+               local percentage, quality = iface:getSignalStrength()
+               iconbar:setWirelessSignal(quality ~= nil and quality or "ERROR")
+               if player then
+                       player:setSignalStrength(percentage)
+               end
+       else            
+               iconbar:setWirelessSignal("ERROR")
+               if player then
+                       player:setSignalStrength(nil)
+               end
+       end
+end
+
+
+local function _updateWireless(self)
+       local iface = Networking:activeInterface()
+
+       Networking:checkNetworkHealth(
+               iface,
+               function(continue, err, msg, msg_param)
+                       local message = self:string(msg, msg_param)
+                       log:debug("_updateWireless status: ", message)
+
+                       if not continue then
+                               log:debug("_updateWireless: ", err)
+
+                               _updateWirelessDone(self, iface, (err == 0))
+                       end
+               end,
+               false,
+               nil
+       )
+end
+
+
+local function _updatePower(self)
        -- ac power / battery
        if self.acpower then
                if self.batteryPopup then
@@ -344,12 +381,22 @@
                        iconbar:setBattery("4")
                end
        end
-
-       -- wireless strength
-       local percentage, quality = self.wireless:getSignalStrength()
-       iconbar:setWirelessSignal(quality ~= nil and quality or "ERROR")
-       if player then
-               player:setSignalStrength(percentage)
+end
+
+
+function _updateTask(self)
+       while true do
+               local what = unpack(Task:running().args)
+
+               if (what & UPDATE_POWER) == UPDATE_POWER then
+                       _updatePower(self)
+               end
+               if (what & UPDATE_WIRELESS) == UPDATE_WIRELESS then
+                       _updateWireless(self)
+               end
+
+               -- suspend task
+               Task:yield(false)
        end
 end
 

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/jive-checkins

Reply via email to