[tuxdroid-svn] r588 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-10-08 14:56:26
|
Author: jaguarondi Date: 2007-10-08 16:56:27 +0200 (Mon, 08 Oct 2007) New Revision: 588 Modified: api/python/trunk/tuxapi_class.py api/python/trunk/tuxapi_const.py Log: * Added battery level status in the api. Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2007-10-08 14:54:27 UTC (rev 587) +++ api/python/trunk/tuxapi_class.py 2007-10-08 14:56:27 UTC (rev 588) @@ -2479,6 +2479,7 @@ tux.status.ir_led tux.status.ir_signal tux.status.light_level + tux.status.battery_level tux.status.lled tux.status.lwing_bt tux.status.mouth_closed @@ -2606,6 +2607,9 @@ if status[4]==DATAS_STATUS_LIGHT_LEVEL: line=line+"Light level->" value_type=value_16b + if status[4]==DATAS_STATUS_BATTERY: + line=line+"Battery level->" + value_type=value_16b if status[4]==DATAS_STATUS_EYES_POSITION_COUNTER: line=line+"Eyes position counter->" value_type=value_8b @@ -3175,7 +3179,7 @@ """ Get the last light level - Return an integer (0..1024, max light=0) + Return an integer (0..1024) Example: >>> var = tux.status.light_level() @@ -3192,6 +3196,34 @@ return 0 #-------------------------------------------------------------------------- + # Get the last state of battery level status + #-------------------------------------------------------------------------- + def battery_level(self): + """ + Get the last battery level + + Return a tupple with the battery level and the status: + (level, status) + level: 0..1024 + status: True (valid battery level) or False (i.e. a motor was + running during the measurement so it's not accurate) + + Example: + >>> (level, valid) = tux.status.battery_level() + """ + if not self.parent.daemon.connected: + return 0 + frame = self.get(DATAS_STATUS_BATTERY) + try: + if len(frame) > 0: + return ((ord(frame[5])*256)+ord(frame[6]), + bool(not ord(frame[7]))) + else: + return 0 + except: + return 0 + + #-------------------------------------------------------------------------- # Get the last state of eyes position counter status #-------------------------------------------------------------------------- def get_eyes_position_counter(self): Modified: api/python/trunk/tuxapi_const.py =================================================================== --- api/python/trunk/tuxapi_const.py 2007-10-08 14:54:27 UTC (rev 587) +++ api/python/trunk/tuxapi_const.py 2007-10-08 14:56:27 UTC (rev 588) @@ -156,6 +156,7 @@ DATAS_STATUS_IR_CODE = 0x22 DATAS_STATUS_SOUND_COUNT = 0x23 DATAS_STATUS_PONG = 0x24 +DATAS_STATUS_BATTERY = 0x25 # Tux connection commands TUX_CONNECTION_DISCONNECT = 1 |