echo Installation complete! Basic Usage: # Simple example from ps2_driver import PS2Joystick, PS2Button joy = PS2Joystick(port='COM3') joy.connect()
def __init__(self): self.joystick = None self.vjoy = None self.use_virtual_joystick = True self.running = False def start(self, port: Optional[str] = None): """Start the PS2 controller driver""" self.joystick = PS2Joystick(port=port) if not self.joystick.connect(): print("Failed to connect to PS2 controller") return False # Initialize virtual joystick if self.use_virtual_joystick: self.vjoy = VJoyWrapper() if not self.vjoy.load_vjoy(): print("Virtual joystick not available, using direct input mode") self.use_virtual_joystick = False # Register callbacks self.joystick.register_axis_callback(self._on_axis_update) # Register button callbacks for debugging for button in PS2Button: self.joystick.register_button_callback(button, lambda pressed, b=button: self._on_button_press(b, pressed)) self.running = True # Main loop try: while self.running: if not self.use_virtual_joystick: # Print debug info self._print_debug_info() time.sleep(0.016) # ~60Hz update except KeyboardInterrupt: print("\nShutting down...") finally: self.stop() return True
parser = argparse.ArgumentParser(description='PS2 Joystick Driver for Windows 10') parser.add_argument('--port', help='COM port (e.g., COM3)') parser.add_argument('--baudrate', type=int, default=115200, help='Serial baudrate') parser.add_argument('--install', action='store_true', help='Install requirements') parser.add_argument('--debug', action='store_true', help='Debug mode (no virtual joystick)') driver joystick ps2 windows 10
while True: if joy.get_button_state(PS2Button.CROSS): print("X button pressed!")
# Axis ranges (0-255 for analog sticks) AXIS_MIN = 0 AXIS_CENTER = 128 AXIS_MAX = 255 echo Installation complete
def _print_debug_info(self): """Print current controller state for debugging""" lx, ly, rx, ry = self.joystick.get_axis_values() print(f"\rLX:lx:3d LY:ly:3d RX:rx:3d RY:ry:3d | ", end="") # Print active buttons active = [b.name for b in PS2Button if self.joystick.get_button_state(b)] print(f"Buttons: ', '.join(active) if active else 'None'", end="")
// Initialize PS2 controller int error = ps2x.config_gamepad(4, 5, 3, 2, true, true); help='COM port (e.g.
void setup() Serial.begin(115200);