[tuxdroid-svn] r174 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2007-03-15 16:00:02
|
Author: remi Date: 2007-03-15 16:58:56 +0100 (Thu, 15 Mar 2007) New Revision: 174 Modified: api/python/trunk/tuxapi_class.py Log: UPD : - Alsa tux card device name is now constructed by the api for example, it is used for playing a sound with "aplay" Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2007-03-14 15:44:29 UTC (rev 173) +++ api/python/trunk/tuxapi_class.py 2007-03-15 15:58:56 UTC (rev 174) @@ -50,6 +50,7 @@ CT_SHELL =1 CT_FUNCTION =2 + #============================================================================== # TUXTCPCommunicator class #============================================================================== @@ -61,6 +62,7 @@ ## @param ipAddress : Tcp/IP Host address #-------------------------------------------------------------------------- def __init__(self,port,ipAddress): + self.print_api_version() self.Server_port=port self.Server_address=ipAddress self.connected=False @@ -79,7 +81,6 @@ self.tts=TUXtts(5500,"localhost",self) self.tts.connect_to_daemon() self.print_status=False - self.print_api_version() #-------------------------------------------------------------------------- ## Print versionning of API @@ -1436,6 +1437,10 @@ ## @param parent : TUXTCPCommunicator parent object def __init__(self,parent): self.parent=parent + self.TUX_devices=[] + self.TUX_devices_count=0 + self.alsa_device="default" + self.alsa_devices_select(0) ## Get versioning of a cpu ## @param cpu_num : cpu index @@ -1467,6 +1472,72 @@ ## Get version of dongle RF cpu def donglerf_get_version(self): return self.get_firmware_versioning(3) + + ## Get the alsa devices + def alsa_devices_enumerate(self): + self.TUX_devices=[] + self.TUX_devices_count=0 + try: + snd_dir=os.listdir("/dev/snd") + except OSError: + print "No alsa sound path found !" + return + last_card=255 + last_device=255 + for dinfo_name in snd_dir: + if ((dinfo_name.find('pcmC')==0)and(dinfo_name.find('D')>-1)): + card=int(dinfo_name[4:5]) + device=int(dinfo_name[6:7]) + if ((card!=last_card)or(device!=last_device)): + last_card=card + last_device=device + filename="/proc/asound/card%d/usbbus"%card + try: + fp=open(filename,'r') + except IOError: + break + tmp_tab=fp.read(7).split('/') + current_tux_device=["",0,0,0,0,0,0] + current_tux_device[1]=card + current_tux_device[2]=device + current_tux_device[3]=int(tmp_tab[0]) + current_tux_device[4]=int(tmp_tab[1]) + filename="/proc/asound/card%d/usbid"%card + try: + fp=open(filename,'r') + except IOError: + break + tmp_tab=fp.read(9).split(':') + current_tux_device[5]=int(tmp_tab[0],16) + current_tux_device[6]=int(tmp_tab[1],16) + if ((current_tux_device[5]==0x03eb)and(current_tux_device[6]==0xff07)): + self.TUX_devices.append(current_tux_device) + self.TUX_devices_count=self.TUX_devices_count+1 + + ## Return the number of tux alsa devices + def alsa_devices_count(self): + count=0 + for ctd in self.TUX_devices: + if ctd[2]==0: + count=count+1 + return count + + ## Get a tux alsa device + def alsa_devices_select(self,number): + self.alsa_devices_enumerate() + self.alsa_devices_count() + self.alsa_device="" + i=0 + if self.TUX_devices_count>0: + for ctd in self.TUX_devices: + if ctd[2]==0: + if i==number: + self.alsa_device="hw:%d,%d"%(ctd[1],ctd[2]) + return + i=i+1 + self.alsa_device="default" + else: + self.alsa_device="default" #============================================================================== # TUXTCPCommunicator - TTS - class |