test3djoystick.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import evdev
  2. from evdev import ecodes
  3. def test_joystick():
  4. # find the Anxinshi device
  5. target_device = None
  6. devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
  7. for device in devices:
  8. if "shenzhenxiaolong" in device.name.lower():
  9. target_device = device
  10. break
  11. if not target_device:
  12. print("Anxinshi device not found. You may not have the permissions.")
  13. return
  14. print(f"Testing Device: {target_device.name}")
  15. # check capabilities
  16. caps = target_device.capabilities()
  17. if ecodes.EV_ABS in caps:
  18. abs_axes = caps[ecodes.EV_ABS]
  19. print(f"Detected {len(abs_axes)} absolute axes.")
  20. for axis in abs_axes:
  21. axis_code = axis[0]
  22. print(f" - Axis found: {ecodes.ABS[axis_code]}")
  23. print("\n--- Monitoring Movements (Ctrl+C to exit) ---")
  24. try:
  25. for event in target_device.read_loop():
  26. if event.type == ecodes.EV_ABS:
  27. axis_name = ecodes.ABS.get(event.code, f"Unknown({event.code})")
  28. print(f"Event: {axis_name:<10} Value: {event.value:<5}")
  29. except KeyboardInterrupt:
  30. print("\nTest finished.")
  31. if __name__ == "__main__":
  32. test_joystick()