Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inputs
- import time
- import threading
- class GamePad:
- def __init__(self, ldms_button='BTN_TL',rdms_button='BTN_TR',
- activate_button='BTN_EAST', status_pv=None):
- self._ldms_button = ldms_button
- self._rdms_button = rdms_button
- self._act_button = activate_button
- self._ldms = 0
- self._rdms = 0
- self._active = 0
- self._enabled = False
- self._run = True
- self._gp = None
- self._thread = threading.Thread(target=self._main_loop)
- self._thread.start()
- self._v_thread = threading.Thread(target=self._vib_loop)
- self._v_thread.start()
- def _main_loop(self):
- while self._run:
- events = inputs.get_gamepad()
- for event in events:
- self._enable(event.code, event.state)
- if self._enabled:
- getattr(self, event.code)(event.state)
- if event.code != 'SYN_REPORT':
- print(event.ev_type, event.code, event.state)
- def _enable(self, code, value):
- if code == self._ldms_button:
- self._ldms = value
- if code == self._rdms_button:
- self._rdms = value
- if (self._ldms or self._rdms):
- if code == self._act_button:
- print(self._active)
- self._active += value
- if self._active >= 5:
- self._enabled = True
- else:
- self._enabled = False
- else:
- self._enabled = False
- self._active = 0
- def _vib_loop(self):
- inputs.devices.codes['ForceFeedback'] = {num: "SYN_REPORT" for num in range(20)}
- while self._run:
- if not self._gp:
- self._gp = inputs.devices.gamepads[0]
- if self._enabled:
- ...
- #self._gp.set_vibration(1,1,500)
- time.sleep(3)
- def _update_status(self, value):
- ...
- def __del__(self):
- self.run = False
- self._thread.join()
- def ABS_X(self, value):
- # Left stick X.
- ...
- def ABS_Y(self, value):
- # Left stick Y.
- ...
- def ABS_Z(self, value):
- # Left stick Z.
- ...
- def ABS_RX(self, value):
- ...
- def ABS_RY(self, value):
- ...
- def ABS_RZ(self, value):
- ...
- def ABS_HAT0X(self, value):
- # d-pad x, -1 is left, 1 is right.
- ...
- def ABS_HAT0Y(self, value):
- # d-pad y, -1 is up, 1 is down.
- ...
- def BTN_START(self, value):
- # Start button.
- ...
- def BTN_SELECT(self, value):
- # Select button.
- ...
- def BTN_NORTH(self, value):
- # X button.
- ...
- def BTN_SOUTH(self, value):
- # A button.
- ...
- def BTN_EAST(self, value):
- # B button.
- ...
- def BTN_WEST(self, value):
- # Y button.
- ...
- def BTN_THUMBL(self, value):
- # Left stick button.
- ...
- def BTN_THUMBR(self, value):
- # Right stick button.
- ...
- def BTN_TL(self, value):
- # Top left button.
- #self._ldms = value
- #if value == 1:
- # self._ldms = True
- #else:
- # self._ldms = False
- ...
- def BTN_TR(self, value):
- # Top right button.
- #self._rdms = value
- #if value == 1:
- # self._rdms = True
- #else:
- # self._rdms = False
- ...
- def BTN_MODE(self, value):
- # Center xbox button.
- ...
- def SYN_REPORT(self, value):
- # Don't know.
- ...
- gp = GamePad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement