?? avrcp_lircd.py
字號:
#! /usr/bin/env python"""Simple multi-client AVRCP->lircd server* Copyright (C) 2006 Sergei Krivov <krivov@yahoo.com>** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.""""""be sure to have installed:pybluez (http://org.csail.mit.edu/pybluez/)enable lirc support in applications (mplayer, xmms, audacious, vlc)append the provided sample lircrc file to your ~/.lircrc filestart by python avrcp_lirc.py"""import threadingimport socketimport osimport avdtp deb=1class lircd_client_thread( threading.Thread ): def __init__ (self,clients,sock,addr): threading.Thread.__init__ ( self ) self.clients=clients self.sock=sock self.addr=addr def run ( self ): l=self.sock.recv(1000) if deb: print "lircd client sock is closed, removing",self.addr self.clients.remove(self) if deb: print "number of lircd_emu clients",len(self.clients)class lircd_accept_thread ( threading.Thread ): def __init__ (self,clients): threading.Thread.__init__ ( self ) self.clients=clients def run ( self ): LIRCD='/dev/lircd' serv=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) if os.access(LIRCD,os.F_OK): os.remove(LIRCD) serv.bind(LIRCD) os.chmod(LIRCD,0666) serv.listen(1) while True: sock,addr=serv.accept() client=lircd_client_thread(self.clients,sock,addr) client.start() if deb:print 'lircd_emu: accepted new connection' self.clients.append(client) if deb: print "number of lircd_emu clients",len(self.clients)class lircd_emu: def __init__(self): self.clients=[] self.accept=lircd_accept_thread(self.clients) self.accept.start() def send(self,com): if com==avdtp.PLAY_OP:com2='0000000000000000 00 play avrcp\n' elif com==avdtp.STOP_OP:com2='0000000000000000 00 stop avrcp\n' elif com==avdtp.PAUSE_OP:com2='0000000000000000 00 pause avrcp\n' elif com==avdtp.NEXT_OP: com2='0000000000000000 00 next avrcp\n' elif com==avdtp.PREV_OP: com2='0000000000000000 00 prev avrcp\n' else: if deb: print "lircd_emu: unknown command code",com return 0 if deb>1: print "sending command", com2 for client in self.clients: try: l=client.sock.send(com2) except: if deb: print "client sock is dead, removing",addr self.clients.remove(client) if deb: print "number of lircd_emu clients",len(self.clients) return 1class avrcp_client_thread ( threading.Thread ): def __init__ (self,sock,callback,lthreads): self.sock=sock self.callback=callback self.lthreads=lthreads threading.Thread.__init__ ( self ) def run( self ): if deb: print "started new avrcp thread" if deb: print "number of avrcp threads is %i" %(len(self.lthreads))# avdtp.avrcp_receive_commands(self.sock,self.callback) try: avdtp.avrcp_receive_commands(self.sock,self.callback) except: pass if deb: print "avrcp socket is dead, removing" self.lthreads.remove(self) if deb: print "number of avrcp threads is %i" %(len(self.lthreads)) class avrcp_server ( threading.Thread ): def __init__ ( self,callback): threading.Thread.__init__ ( self ) self.lthreads=[] self.callback=callback def run ( self ): while True: sock=avdtp.avrcp_accept_connection() athread=avrcp_client_thread(sock,self.callback,self.lthreads) self.lthreads.append(athread) athread.start()if __name__=="__main__": deb=0 lircd=lircd_emu() avrcp=avrcp_server(lircd.send) avrcp.start()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -