Advertisement
Hyratel

Untitled

Jan 4th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. from __future__ import print_function
  4. import threading
  5. import time
  6. import socket
  7. import queue
  8. import pygame
  9. #from pygame import joystick, event
  10.  
  11. j = pygame.joystick.Joystick(0)
  12. UDP_IP = "127.0.0.1"
  13. UDP_PORT = 5005
  14. KEEPAMSG = "Otherdata 12"
  15. XNAME = "xpos"
  16. YNAME = "ypos"
  17. STICKX
  18. STICK
  19.  
  20. pygame.init()
  21. # joystick.init()
  22. q = queue.Queue()
  23.  
  24. sock = socket.socket(socket.AF_INET, # Internet
  25.                     socket.SOCK_DGRAM) # UDP
  26.  
  27.  
  28. j = pygame.joystick.Joystick(0)
  29. j.init()
  30. print("Initialized Joystick :" + j.get_name())
  31.  
  32. class Keepalive(threading.Thread):
  33.     def run(self):
  34.         if q.Empty():
  35.             q.put(KEEPAMSG)
  36.         time.sleep(1)
  37.  
  38.  
  39. class JoystickPoll(threading.Thread):
  40.     def run(self):
  41.         # TBD
  42.        
  43.  
  44. class UDPsend(threading.Thread):
  45.     def run(self):
  46.         sock.sendto(q.get(True), (UDP_IP, UDP_PORT))
  47.        
  48. UDPsend.start()
  49. JoystickPoll.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement