[tuxdroid-svn] r732 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-11-27 09:53:49
|
Author: Paul_R Date: 2007-11-27 10:53:50 +0100 (Tue, 27 Nov 2007) New Revision: 732 Modified: api/python/trunk/tuxapi_class.py api/python/trunk/tuxapi_const.py Log: * Added two three new commands to store the sounds in the flash memory : tux.cmd.sound_erase() - Erase the flash tux.cmd.sound_storing() - Store a sound in the flash memory tux.cmd.sound_confirm(bool) - Confirm the storage. ... and two new status : tux.status.sound_play() - return the track number played from the flash memory, or 0 - return a True as second parameter if tux is playing sounds (from TTS, flash or streaming) tux.status.sound_record() - return the recording state - return the size of the last track written when the program is waiting for the confirmation. Note : This API version isn't compatible with tuxaudio firmware < SVN Rev 730 Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2007-11-27 09:45:14 UTC (rev 731) +++ api/python/trunk/tuxapi_class.py 2007-11-27 09:53:50 UTC (rev 732) @@ -1761,8 +1761,9 @@ tux.cmd.sleep_off tux.cmd.sleep_on tux.cmd.sound_play - tux.cmd.sound_store_index + tux.cmd.sound_confirm tux.cmd.sound_storing + tux.cmd.sound_erase tux.cmd.sound_test tux.cmd.spinl_off tux.cmd.spinl_on @@ -2510,39 +2511,46 @@ #-------------------------------------------------------------------------- # Send a command to tux for storing a sound collection in the memory flash #-------------------------------------------------------------------------- - def sound_storing(self,number): + def sound_storing(self): """ - Send a command to tux for storing a sound collection in the - memory flash + Send a command to tux for storing a sound in the memory flash - Parameters: - "number" as integer : number of sounds to be stored - Example: - >>> tux.cmd.sound_storing(10) + >>> tux.cmd.sound_storing() """ self.last_ack=self.structured(TUX_CMD_STRUCT_SOUND, \ - TUX_CMD_STRUCT_SUB_STORING,number,0,0) + TUX_CMD_STRUCT_SUB_STORING,0,0,0) #-------------------------------------------------------------------------- - # Send a command to tux for indexing the sound + # Send a command to tux to confirm the writing process #-------------------------------------------------------------------------- - def sound_store_index(self,highAdd,middleAdd,lowAdd): + def sound_confirm(self, write): """ - Send a command to tux for indexing the sound + Send a command to tux to confirm the writing process Parameters: - "highAdd" as integer : high byte address of the sound - "middleAdd" as integer : middle byte address of the sound - "lowAdd" as integer : low byte address of the sound + "write" as boolean : True to confirm, False to erase the sound. Example: - >>> tux.cmd.sound_store_index(0x00,0x04,0x00) + >>> tux.cmd.sound_confirm(True) """ self.last_ack=self.structured(TUX_CMD_STRUCT_SOUND, \ - TUX_CMD_STRUCT_SUB_STORE_INDEX,highAdd,middleAdd,lowAdd) + TUX_CMD_STRUCT_SUB_CONFIRM, write, 0, 0) #-------------------------------------------------------------------------- + # Send a command to tux to erase the flash memory + #-------------------------------------------------------------------------- + def sound_erase(self): + """ + Send a command to erase the flash memory. + + Example: + >>> tux.cmd.sound_erase() + """ + self.last_ack=self.structured(TUX_CMD_STRUCT_SOUND, \ + TUX_CMD_STRUCT_SUB_ERASE, 0, 0, 0) + + #-------------------------------------------------------------------------- # Send a command to tux for testing the sound in tux #-------------------------------------------------------------------------- def sound_test(self): @@ -2652,7 +2660,6 @@ Functions list for the users: tux.status.charger_state - tux.status.flash_status tux.status.eyes_closed tux.status.eyes_counter tux.status.eyes_motor @@ -2675,6 +2682,8 @@ tux.status.rwing_bt tux.status.sounds_count tux.status.sound_muted + tux.status.sound_play + tux.status.sound_record tux.status.spin_backward tux.status.spin_bt tux.status.spin_counter @@ -2815,6 +2824,12 @@ if status[4]==DATAS_STATUS_PONG: line=line+"Pong-> Received : %d Remaining : %d Average : %.0f %s" \ %(status[6],status[5],((status[6]*100)/(200-status[5])),'%') + if status[4]==DATAS_STATUS_AUDIO: + line=line+"Sound played from flash-> %d Playback status-> %d" \ + %(status[5], status[6]) + if status[4]==DATAS_STATUS_PROGRAMMING_AUDIO: + line=line+"Programming state-> %d nb of block used-> %d" \ + %(status[5], status[6]) value_type=value_np #-- Write value if value_type==value_onoff: @@ -3407,18 +3422,18 @@ #-------------------------------------------------------------------------- # Get the last state of sound status #-------------------------------------------------------------------------- - def flash_status(self): + def sound_play(self): """ - Get the last sound flash status + Get the last playback status Return a tupple with the audio flash status: - (play state, record state, sound number) - play state : Return the sound number or 0 if no sound is played - record state : Return the recording state - sound number : Return the track which is recorded. + sound number : Return the sound number played from the flash + memory. + status : Return 1 if tux is playing sound (flash, TTS or + streaming) Example: - >>> (play_state, record_state, sound_number) = tux.status.flash_status() + >>> (numSound, playback_status) = tux.status.sound_play() """ if not self.parent.daemon.connected: @@ -3426,13 +3441,47 @@ frame = self.get(0x26) try: if len(frame) > 0: - return (ord(frame[5]), ord(frame[6]), ord(frame[7])) + return (ord(frame[5]), ord(frame[6])) else: return 0 except: return 0 + #-------------------------------------------------------------------------- + # Get the last state of sound status + #-------------------------------------------------------------------------- + def sound_record(self): + """ + Get the last sound flash status + Return a tupple with the programming status: + 1st parameter : The programming state : + 0 : Standby + 1 : Programming in progress + 2 : Waiting for confirmation + 3 : Writing indexes + 4 : Erasing the last sound + 5 : The flash is full, the programming cycle is + stopped + 6 : No sound received + 2nd parameter : The 4kB block size of the last sound recorded. + (only when the state == 2) + + Example: + >>> (record_state, block) = tux.status.sound_record() + + """ + if not self.parent.daemon.connected: + return 0 + frame = self.get(DATAS_STATUS_PROGRAMMING_AUDIO) + try: + if len(frame) > 0: + return (ord(frame[5]), ord(frame[6])) + else: + return 0 + except: + return 0 + #-------------------------------------------------------------------------- # Get the last state of eyes position counter status #-------------------------------------------------------------------------- Modified: api/python/trunk/tuxapi_const.py =================================================================== --- api/python/trunk/tuxapi_const.py 2007-11-27 09:45:14 UTC (rev 731) +++ api/python/trunk/tuxapi_const.py 2007-11-27 09:53:50 UTC (rev 732) @@ -161,6 +161,7 @@ DATAS_STATUS_FLASH_USAGE = 0x27 DATAS_STATUS_AVAILABLE_RECORD_TIME = 0x28 DATAS_STATUS_SOUND_FLASH = 0x29 +DATAS_STATUS_PROGRAMMING_AUDIO = 0x2A STATUS_WINGS_MOTOR_BACKWARD = 0x01 STATUS_SPIN_MOTOR_BACKWARD = 0x02 @@ -199,6 +200,7 @@ STATUS_PONG = 0x24 STATUS_BATTERY = 0x25 STATUS_AUDIO = 0x26 +STATUS_PROGRAMMING_AUDIO = 0x2A STATUS_MICRO_ENERGY = 0xF0 # Tux connection commands @@ -302,7 +304,7 @@ TUX_CMD_STRUCT_SUB_SEND = 0x04 TUX_CMD_STRUCT_SUB_PLAY = 0x05 TUX_CMD_STRUCT_SUB_STORING = 0x06 -TUX_CMD_STRUCT_SUB_STORE_INDEX = 0x07 +TUX_CMD_STRUCT_SUB_CONFIRM = 0x07 TUX_CMD_STRUCT_SUB_TEST = 0x08 TUX_CMD_STRUCT_SUB_BLINK = 0x09 TUX_CMD_STRUCT_SUB_CH_GENERAL = 0x0A @@ -311,6 +313,7 @@ TUX_CMD_STRUCT_SUB_UP = 0x0C TUX_CMD_STRUCT_SUB_CLOSE = 0x0D TUX_CMD_STRUCT_SUB_DOWN = 0x0D +TUX_CMD_STRUCT_SUB_ERASE = 0x0E # Tux request information TUX_REQ_INFO_VERSION = 0x01 |