Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. import inputs
  2. import time
  3. import threading
  4.  
  5. class GamePad:
  6.  
  7. def __init__(self, ldms_button='BTN_TL',rdms_button='BTN_TR',
  8. activate_button='BTN_EAST', status_pv=None):
  9.  
  10. self._ldms_button = ldms_button
  11. self._rdms_button = rdms_button
  12. self._act_button = activate_button
  13. self._ldms = 0
  14. self._rdms = 0
  15. self._active = 0
  16. self._enabled = False
  17. self._run = True
  18. self._gp = None
  19. self._thread = threading.Thread(target=self._main_loop)
  20. self._thread.start()
  21. self._v_thread = threading.Thread(target=self._vib_loop)
  22. self._v_thread.start()
  23.  
  24. def _main_loop(self):
  25. while self._run:
  26. events = inputs.get_gamepad()
  27. for event in events:
  28. self._enable(event.code, event.state)
  29. if self._enabled:
  30. getattr(self, event.code)(event.state)
  31. if event.code != 'SYN_REPORT':
  32. print(event.ev_type, event.code, event.state)
  33.  
  34. def _enable(self, code, value):
  35. if code == self._ldms_button:
  36. self._ldms = value
  37. if code == self._rdms_button:
  38. self._rdms = value
  39. if (self._ldms or self._rdms):
  40. if code == self._act_button:
  41. print(self._active)
  42. self._active += value
  43. if self._active >= 5:
  44. self._enabled = True
  45. else:
  46. self._enabled = False
  47. else:
  48. self._enabled = False
  49. self._active = 0
  50.  
  51.  
  52.  
  53. def _vib_loop(self):
  54. inputs.devices.codes['ForceFeedback'] = {num: "SYN_REPORT" for num in range(20)}
  55. while self._run:
  56. if not self._gp:
  57. self._gp = inputs.devices.gamepads[0]
  58. if self._enabled:
  59. ...
  60. #self._gp.set_vibration(1,1,500)
  61. time.sleep(3)
  62.  
  63. def _update_status(self, value):
  64. ...
  65.  
  66. def __del__(self):
  67. self.run = False
  68. self._thread.join()
  69.  
  70. def ABS_X(self, value):
  71. # Left stick X.
  72. ...
  73.  
  74. def ABS_Y(self, value):
  75. # Left stick Y.
  76. ...
  77.  
  78. def ABS_Z(self, value):
  79. # Left stick Z.
  80. ...
  81.  
  82. def ABS_RX(self, value):
  83. ...
  84.  
  85. def ABS_RY(self, value):
  86. ...
  87.  
  88. def ABS_RZ(self, value):
  89. ...
  90.  
  91. def ABS_HAT0X(self, value):
  92. # d-pad x, -1 is left, 1 is right.
  93. ...
  94.  
  95. def ABS_HAT0Y(self, value):
  96. # d-pad y, -1 is up, 1 is down.
  97. ...
  98.  
  99. def BTN_START(self, value):
  100. # Start button.
  101. ...
  102.  
  103. def BTN_SELECT(self, value):
  104. # Select button.
  105. ...
  106.  
  107. def BTN_NORTH(self, value):
  108. # X button.
  109. ...
  110.  
  111. def BTN_SOUTH(self, value):
  112. # A button.
  113. ...
  114.  
  115. def BTN_EAST(self, value):
  116. # B button.
  117. ...
  118.  
  119. def BTN_WEST(self, value):
  120. # Y button.
  121. ...
  122.  
  123. def BTN_THUMBL(self, value):
  124. # Left stick button.
  125. ...
  126.  
  127. def BTN_THUMBR(self, value):
  128. # Right stick button.
  129. ...
  130.  
  131. def BTN_TL(self, value):
  132. # Top left button.
  133. #self._ldms = value
  134. #if value == 1:
  135. # self._ldms = True
  136. #else:
  137. # self._ldms = False
  138. ...
  139.  
  140. def BTN_TR(self, value):
  141. # Top right button.
  142. #self._rdms = value
  143. #if value == 1:
  144. # self._rdms = True
  145. #else:
  146. # self._rdms = False
  147. ...
  148.  
  149. def BTN_MODE(self, value):
  150. # Center xbox button.
  151. ...
  152.  
  153. def SYN_REPORT(self, value):
  154. # Don't know.
  155. ...
  156.  
  157. gp = GamePad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement