Author: remi
Date: 2009-03-12 13:40:47 +0100 (Thu, 12 Mar 2009)
New Revision: 3992

Added:
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
Modified:
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstTuxDriver.py
Log:
* added a class to interact with the battery level and states.

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
  2009-03-12 12:28:18 UTC (rev 3991)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
  2009-03-12 12:40:47 UTC (rev 3992)
@@ -30,6 +30,7 @@
 from tuxdroid.Spinning import Spinning
 from tuxdroid.Framework import Framework
 from tuxdroid.Light import Light
+from tuxdroid.Battery import Battery
 
 # 
------------------------------------------------------------------------------
 # Tux Droid API.
@@ -83,6 +84,8 @@
         self.spinning = Spinning(self, self.server)
         # Create the light object
         self.light = Light(self, self.server)
+        # Create the battery object
+        self.battery = Battery(self, self.server)
         # Create the framework object
         self.framework = Framework(self, self.server)
         # Initialize the helper

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
                                (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
        2009-03-12 12:40:47 UTC (rev 3992)
@@ -0,0 +1,110 @@
+# -*- coding: latin1 -*-
+
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+from base.ApiBaseChildResource import ApiBaseChildResource
+from base.const.ConstClient import *
+from const.ConstTuxDriver import *
+
+# 
------------------------------------------------------------------------------
+# Class to interact with the battery states and level.
+# 
------------------------------------------------------------------------------
+class Battery(ApiBaseChildResource):
+    """Class to interact with the battery states and level.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, apiBase, apiBaseServer):
+        """Constructor of the class.
+        @param apiBase: ApiBase parent object.
+        @param apiBaseServer: ApiBaseServer object.
+        """
+        ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+
+    # 
--------------------------------------------------------------------------
+    # Register a callback on the battery level event.
+    # 
--------------------------------------------------------------------------
+    def registerEventOnLevelChange(self, funct, idx = None):
+        """Register a callback on the battery level event.
+        Not available for CLIENT_LEVEL_ANONYME level.
+        @param funct: pointer to the function.
+        @param idx: index from a previous register.
+        @return: the new index of the callback in the handler.
+        """
+        if self.getServer().getClientLevel() == CLIENT_LEVEL_ANONYME:
+            return -1
+        self._syndicateEvent(ST_NAME_BATTERY_LEVEL)
+        nIdx = self._registerEvent(ST_NAME_BATTERY_LEVEL, None, funct, idx)
+        return nIdx
+
+    # 
--------------------------------------------------------------------------
+    # Unregister a callback from the battery level event.
+    # 
--------------------------------------------------------------------------
+    def unregisterEventOnLevelChange(self, idx):
+        """Unregister a callback from the battery level event.
+        Not available for CLIENT_LEVEL_ANONYME level.
+        @param idx: index from a previous register.
+        """
+        if self.getServer().getClientLevel() == CLIENT_LEVEL_ANONYME:
+            return
+        self._unregisterEvent(ST_NAME_BATTERY_LEVEL, idx)
+
+    # 
--------------------------------------------------------------------------
+    # Register a callback on the battery state event.
+    # 
--------------------------------------------------------------------------
+    def registerEventOnStateChange(self, funct, idx = None):
+        """Register a callback on the battery state event.
+        Not available for CLIENT_LEVEL_ANONYME level.
+        @param funct: pointer to the function.
+        @param idx: index from a previous register.
+        @return: the new index of the callback in the handler.
+        """
+        if self.getServer().getClientLevel() == CLIENT_LEVEL_ANONYME:
+            return -1
+        nIdx = self._registerEvent(ST_NAME_BATTERY_STATE, None, funct, idx)
+        return nIdx
+
+    # 
--------------------------------------------------------------------------
+    # Unregister a callback from the battery state event.
+    # 
--------------------------------------------------------------------------
+    def unregisterEventOnLevelChange(self, idx):
+        """Unregister a callback from the battery state event.
+        Not available for CLIENT_LEVEL_ANONYME level.
+        @param idx: index from a previous register.
+        """
+        if self.getServer().getClientLevel() == CLIENT_LEVEL_ANONYME:
+            return
+        self._unregisterEvent(ST_NAME_BATTERY_STATE, idx)
+
+    # 
--------------------------------------------------------------------------
+    # Return the current level of the battery.
+    # 
--------------------------------------------------------------------------
+    def getLevel(self):
+        """Return the current level of the battery.
+        @return: A float.
+        """
+        self._syndicateEvent(ST_NAME_BATTERY_LEVEL)
+        value = self._requestOne(ST_NAME_BATTERY_LEVEL)
+        if value != None:
+            return eval(value) / 1000.0
+        return 0.0
+
+    # 
--------------------------------------------------------------------------
+    # Return the current state of the battery.
+    # 
--------------------------------------------------------------------------
+    def getState(self):
+        """Return the current state of the battery.
+        @return: A battery state.
+            <BATTERY_STATE_FULL|BATTERY_STATE_HIGH|BATTERY_STATE_LOW|
+             BATTERY_STATE_EMPTY>
+        """
+        self._syndicateEvent(ST_NAME_BATTERY_STATE)
+        value = self._requestOne(ST_NAME_BATTERY_STATE)
+        if value != None:
+            return value
+        return BATTERY_STATE_EMPTY


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstTuxDriver.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstTuxDriver.py
   2009-03-12 12:28:18 UTC (rev 3991)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstTuxDriver.py
   2009-03-12 12:40:47 UTC (rev 3992)
@@ -296,4 +296,18 @@
     K_MOUSE,
     K_ALT,
     K_RELEASED,
+]
+
+#
+# Battery states
+#
+BATTERY_STATE_FULL = "FULL"
+BATTERY_STATE_HIGH = "HIGH"
+BATTERY_STATE_LOW = "LOW"
+BATTERY_STATE_EMPTY = "EMPTY"
+BATTERY_STATES_LIST = [
+    BATTERY_STATE_FULL,
+    BATTERY_STATE_HIGH,
+    BATTERY_STATE_LOW,
+    BATTERY_STATE_EMPTY,
 ]
\ No newline at end of file


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to