Package: pyspacemouse
PySpaceMouseA Python library for 3Dconnexion SpaceMouse devices3Dconnexion Space Mouse in Python using raw HID.
Note: youdon'tneed to install or use any of the drivers or 3Dconnexion software to use this package.
It interfaces with the controller directly withhidapiand python wrapper libraryeasyhid.PySpaceMouseis forked from:johnhw/pyspacenavigatorConnected projectPySpaceAppis a simple example of how controll your PC with SpaceMouse.Implements a simple interface to the 6 DoF 3DconnexionSpace Mousedevice as
well as similar devices.Control arobotwith a Space MouseSupported 3Dconnexion devicesSpaceNavigatorSpaceMouse ProSpaceMouse Pro WirelessSpaceMouse Wireless3Dconnexion Universal ReceiverSpaceMouse CompactSpacePilotSpacePilot ProAdd more devicesInstallationUse the package managerpipto installpyspacemouse.pipinstallpyspacemouseDependencieshidapiisClibrary for direct communication with HID devicesLinuxlibhidapi-devto access HID datasudo apt-get install libhidapi-dev(Debian/Ubuntu)Compile and installhidapi.  (other Linux
distributions)add rules for permissionssudoecho'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"'>/etc/udev/rules.d/99-hidraw-permissions.rules
sudousermod-aGplugdev$USERnewgrpplugdevAleternative option - with tee (RPi)echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-hidraw-permissions.rules
  sudo usermod -aG plugdev $USER
  newgrp plugdevWindowsInstall the latest release of hidapi.dll and hidapi.lib from
thehidapi releasespage.Set system environment: add absolute path forx64orx86folder in Path.Mac OS X (M1)Install fromHomebrewbrew install hidapiAdd hidapi to yourDYLD_LIBRARY_PATHdirectory.exportDYLD_LIBRARY_PATH=/opt/homebrew/Cellar/hidapi/0.14.0/lib:$DYLD_LIBRARY_PATHOn MacOS M1 you will need patched version of easyhidpipinstallgit+https://github.com/bglopez/python-easyhid.gitIn case of problem with M1 chip, try to run you code with Rosseta 2How to use Rosseta 2 -Setup RosettaTested and developed byconsi- thanks!easyhidishidapiinterface for Python - required on all platformspip install git+https://github.com/bglopez/python-easyhid.gitthis fork fix problems withhidapion MacOS.on other platforms it possible works with original packagepip install easyhidBasic Usage:basicExample.pyimportpyspacemouseimporttimesuccess=pyspacemouse.open()ifsuccess:while1:state=pyspacemouse.read()print(state.x,state.y,state.z)time.sleep(0.01)State objectsState objects returned fromread()have 7 attributes: [t,x,y,z,roll,pitch,yaw,button].t: timestamp in seconds since the script started.x,y,z: translations in the range [-1.0, 1.0]roll, pitch, yaw: rotations in the range [-1.0, 1.0].button: list of button states (0 or 1), in order specified in the device specifierUsage with callbackcallbackExample.pyimportpyspacemouseimporttimedefbutton_0(state,buttons,pressed_buttons):print("Button:",pressed_buttons)defbutton_0_1(state,buttons,pressed_buttons):print("Buttons:",pressed_buttons)defsomeButton(state,buttons):print("Some button")defcallback():button_arr=[pyspacemouse.ButtonCallback(0,button_0),pyspacemouse.ButtonCallback([1],lambdastate,buttons,pressed_buttons:print("Button: 1")),pyspacemouse.ButtonCallback([0,1],button_0_1),]success=pyspacemouse.open(dof_callback=pyspacemouse.print_state,button_callback=someButton,button_callback_arr=button_arr)ifsuccess:whileTrue:pyspacemouse.read()time.sleep(0.01)if__name__=='__main__':callback()APIopen(callback=None, button_callback=None, button_callback_arr=None, set_nonblocking_loop=True, device=None)
    Open a 3D space navigator device. Makes this device the current active device, which enables the module-level read() and close()
    calls. For multiple devices, use the read() and close() calls on the returned object instead, and don't use the module-level calls.

    Parameters:
        callback: If callback is provided, it is called on each HID update with a copy of the current state namedtuple
        dof_callback: If dof_callback is provided, it is called only on DOF state changes with the argument (state).
        button_callback: If button_callback is provided, it is called on each button push, with the arguments (state_tuple, button_state)
        device: name of device to open, as a string like "SpaceNavigator". Must be one of the values in `supported_devices`.
                If `None`, chooses the first supported device found.
    Returns:
        Device object if the device was opened successfully
        None if the device could not be opened

read()              Return a namedtuple giving the current device state (t,x,y,z,roll,pitch,yaw,button)
close()             Close the connection to the current device, if it is open
list_devices()      Return a list of supported devices found, or an empty list if none foundopen() returns a DeviceSpec object. If you have multiple 3Dconnexion devices, you can use the object-oriented API to
access them individually.
Each object has the following API, which functions exactly as the above API, but on a per-device basis:dev.open()          Opens the connection (this is always called by the module-level open command,
                    so you should not need to use it unless you have called close())
dev.read()          Return the state of the device as namedtuple [t,x,y,z,roll,pitch,yaw,button]
dev.close()         Close this deviceThere are also attributes:dev.connected       True if the device is connected, False otherwise
dev.state           Convenience property which returns the same value as read()Predefined callbacksimportpyspacemouseimporttimesuccess=pyspacemouse.open(dof_callback=pyspacemouse.print_state,button_callback=pyspacemouse.print_buttons)ifsuccess:while1:state=pyspacemouse.read()time.sleep(0.01)Callback: print_statePrint all axis statesx +0.00    y +0.00    z +0.00 roll +0.00 pitch +0.00  yaw +0.00    t +0.0Callback: print_buttonsPrint all buttons states[ 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, ]TroubleshootingModuleNotFoundError: No module named 'easyhid'Installeasyhidbypip install easyhid.AttributeError: function/symbol 'hid_enumerate' not found in library '': python3: undefined symbol: hid_enumerateHID library for your computer is not installed.Follow the instructions inrequirements.