Advertisement
here2share

# s60_bt.py

Jul 20th, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # s60_bt.py
  2.  
  3. import appuifw
  4. import socket
  5. import graphics
  6. import e32
  7. import btsocket as socket
  8.  
  9. keyboard_state={}
  10. last_keycode=0
  11.  
  12. def bt_connect():
  13.     global sock
  14.     sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
  15.     target=”
  16.     if not target:
  17.         address,services=socket.bt_discover()
  18.         print “Discovered: %s, %s”%(address,services)
  19.         if len(services)>1:
  20.             choices=services.keys()
  21.             choices.sort()
  22.             choice=appuifw.popup_menu([unicode(services[x])+”: “+x
  23.                                         for x in choices],u’Choose port:’)
  24.             target=(address,services[choices[choice]])
  25.         else:
  26.             target=(address,services.values()[0])
  27.     print “Connecting to “+str(target)
  28.     sock.connect(target)
  29.     print “OK.”
  30.      
  31.      
  32. def callback(event):
  33.     if event[type] == appuifw.EEventKeyDown:
  34.         keyboard_state[event[‘scancode’]]=1
  35.     elif event[type] == appuifw.EEventKeyUp:
  36.         keyboard_state[event[‘scancode’]]=0
  37.     elif event[type] == appuifw.EEventKey:
  38.         last_keycode=event[‘keycode’]
  39.          
  40.     canvas.text((0,60),u’%s’%(last_keycode))
  41.     sock.sendall(u’%s’%(last_keycode))
  42.      
  43.  
  44. bt_connect()
  45.      
  46. canvas=appuifw.Canvas(event_callback=callback)
  47. appuifw.app.body=canvas
  48.  
  49.  
  50. lock=e32.Ao_lock()
  51. appuifw.app.exit_key_handler=lock.signal
  52. lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement