Author: remi
Date: 2009-03-12 13:56:34 +0100 (Thu, 12 Mar 2009)
New Revision: 3995

Added:
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Charger.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/Battery.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 charger state

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:46:52 UTC (rev 3994)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
  2009-03-12 12:56:34 UTC (rev 3995)
@@ -31,6 +31,7 @@
 from tuxdroid.Framework import Framework
 from tuxdroid.Light import Light
 from tuxdroid.Battery import Battery
+from tuxdroid.Charger import Charger
 
 # 
------------------------------------------------------------------------------
 # Tux Droid API.
@@ -86,6 +87,8 @@
         self.light = Light(self, self.server)
         # Create the battery object
         self.battery = Battery(self, self.server)
+        # Create the charger object
+        self.charger = Charger(self, self.server)
         # Create the framework object
         self.framework = Framework(self, self.server)
         # Initialize the helper

Modified: 
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
        2009-03-12 12:46:52 UTC (rev 3994)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Battery.py
        2009-03-12 12:56:34 UTC (rev 3995)
@@ -100,7 +100,7 @@
     # 
--------------------------------------------------------------------------
     def getState(self):
         """Return the current state of the battery.
-        @return: A battery state.
+        @return: The battery state.
             <BATTERY_STATE_FULL|BATTERY_STATE_HIGH|BATTERY_STATE_LOW|
              BATTERY_STATE_EMPTY>
         """

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Charger.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Charger.py
                                (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Charger.py
        2009-03-12 12:56:34 UTC (rev 3995)
@@ -0,0 +1,81 @@
+# -*- 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 charger states.
+# 
------------------------------------------------------------------------------
+class Charger(ApiBaseChildResource):
+    """Class to interact with the charger states.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # 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 charger state event.
+    # 
--------------------------------------------------------------------------
+    def registerEventOnStateChange(self, funct, idx = None):
+        """Register a callback on the charger 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_CHARGER_STATE, None, funct, idx)
+        return nIdx
+
+    # 
--------------------------------------------------------------------------
+    # Unregister a callback from the charger state event.
+    # 
--------------------------------------------------------------------------
+    def unregisterEventOnStateChange(self, idx):
+        """Unregister a callback from the charger 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_CHARGER_STATE, idx)
+
+    # 
--------------------------------------------------------------------------
+    # Return the current state of the charger.
+    # 
--------------------------------------------------------------------------
+    def getState(self):
+        """Return the current state of the charger.
+        @return: The charger state.
+            <CHARGER_STATE_UNPLUGGED|CHARGER_STATE_CHARGING|
+             CHARGER_STATE_PLUGGED_NO_POWER|CHARGER_STATE_TRICKLE|
+             CHARGER_STATE_INHIBITED>
+        """
+        value = self._requestOne(ST_NAME_CHARGER_STATE)
+        if value != None:
+            return value
+        return CHARGER_STATE_UNPLUGGED
+
+    # 
--------------------------------------------------------------------------
+    # Get if the charger is connected or not.
+    # 
--------------------------------------------------------------------------
+    def getConnected(self):
+        """Get if the charger is connected or not.
+        @return: True or False.
+        """
+        if self.getState() != CHARGER_STATE_UNPLUGGED:
+            return True
+        else:
+            return False


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/Charger.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:46:52 UTC (rev 3994)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstTuxDriver.py
   2009-03-12 12:56:34 UTC (rev 3995)
@@ -310,4 +310,20 @@
     BATTERY_STATE_HIGH,
     BATTERY_STATE_LOW,
     BATTERY_STATE_EMPTY,
+]
+
+#
+# Charger states
+#
+CHARGER_STATE_UNPLUGGED = "UNPLUGGED"
+CHARGER_STATE_CHARGING = "CHARGING"
+CHARGER_STATE_PLUGGED_NO_POWER = "PLUGGED_NO_POWER"
+CHARGER_STATE_TRICKLE = "TRICKLE"
+CHARGER_STATE_INHIBITED = "INHIBITED"
+CHARGER_STATES_LIST = [
+    CHARGER_STATE_UNPLUGGED,
+    CHARGER_STATE_CHARGING,
+    CHARGER_STATE_PLUGGED_NO_POWER,
+    CHARGER_STATE_TRICKLE,
+    CHARGER_STATE_INHIBITED,
 ]
\ 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