jakubandrysek / pyspacemouse Goto Github PK
View Code? Open in Web Editor NEW🎮 Multiplatform Python library for 3Dconnexion SpaceMouse devices using raw HID.
Home Page: https://spacemouse.kubaandrysek.cz/
License: MIT License
🎮 Multiplatform Python library for 3Dconnexion SpaceMouse devices using raw HID.
Home Page: https://spacemouse.kubaandrysek.cz/
License: MIT License
Try to implement a callback read using a low-level function from the HIDAPI library - read_callback
This function has to be additionally implemented to a python HID wrapper like easyhid
The parent project pyspacenavigator, which supports only the Windows platform uses a callback function to the smooth read
I have tried to install PySpaceMouse on MacOS M1, but it doesn`t work.
Is there anybody who fixed this issue?
I have installed hidapi
trough brew install hidapi
.
My result from basicExample.py is there:
✘ kuba@KA-M1 ~/Documents/git/kuba/pyspacemouse master ± python3.11 ./examples/basicExample.py
Traceback (most recent call last):
File "/Users/kuba/Documents/git/kuba/pyspacemouse/./examples/basicExample.py", line 4, in <module>
success = pyspacemouse.open()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pyspacemouse/pyspacemouse.py", line 703, in open
all_devices = list_devices()
^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pyspacemouse/pyspacemouse.py", line 643, in list_devices
hid = Enumeration()
^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/easyhid/easyhid.py", line 366, in __init__
self.device_list = _hid_enumerate(vid, pid)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/easyhid/easyhid.py", line 428, in _hid_enumerate
start = hidapi.hid_enumerate(vendor_id, product_id)
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/cffi/api.py", line 912, in __getattr__
make_accessor(name)
File "/opt/homebrew/lib/python3.11/site-packages/cffi/api.py", line 908, in make_accessor
accessors[name](name)
File "/opt/homebrew/lib/python3.11/site-packages/cffi/api.py", line 838, in accessor_function
value = backendlib.load_function(BType, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: function/symbol 'hid_enumerate' not found in library '<None>': dlsym(RTLD_DEFAULT, hid_enumerate): symbol not found
Related links:
Following the documentation for installing the dependencies, I ran into a Permission denied
error with:
sudo echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"' > /etc/udev/rules.d/99-hidraw-permissions.rules
The solution was to use sudo tee
:
echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0664", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-hidraw-permissions.rules
I am emulating space pro bluetooth with esp32 and my button mapping same as yours. But modifier (like ctrl,shif etc) bits doesnt work.
I'm asking this question here because I couldn't see the Space Pro Bluetooth description in your code. Is there a specific reason for this?
C:\Users\61240\Downloads\weimo_ws\src>python mouse.py
Traceback (most recent call last):
File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\easyhid.py", line 53, in <module>
hidapi = ffi.dlopen('hidapi.dll')
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 827, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library 'hidapi.dll': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'hidapi.dll'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mouse.py", line 1, in <module>
import pyspacemouse
File "C:\opt\ros\noetic\x64\lib\site-packages\pyspacemouse\__init__.py", line 1, in <module>
from .pyspacemouse import *
File "C:\opt\ros\noetic\x64\lib\site-packages\pyspacemouse\pyspacemouse.py", line 1, in <module>
from easyhid import Enumeration
File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\__init__.py", line 8, in <module>
from easyhid.easyhid import *
File "C:\opt\ros\noetic\x64\lib\site-packages\easyhid\easyhid.py", line 55, in <module>
hidapi = ffi.dlopen(ctypes.util.find_library('hidapi.dll'))
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\opt\ros\noetic\x64\lib\site-packages\cffi\api.py", line 821, in _load_backend_lib
raise OSError("dlopen(None) cannot work on Windows for Python 3 "
OSError: dlopen(None) cannot work on Windows for Python 3 (see http://bugs.python.org/issue23606)
C:\Users\Student\Downloads\hidapi-win\x64
`Traceback (most recent call last):
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\easyhid\easyhid.py", line 53, in
hidapi = ffi.dlopen('hidapi.dll')
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 827, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library 'hidapi.dll': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'hidapi.dll'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Student\Downloads\basicExample.py", line 1, in
import pyspacemouse
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyspacemouse_init_.py", line 1, in
from .pyspacemouse import *
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyspacemouse\pyspacemouse.py", line 1, in
from easyhid import Enumeration, HIDException
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\easyhid_init_.py", line 8, in
from easyhid.easyhid import *
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\easyhid\easyhid.py", line 55, in
hidapi = ffi.dlopen(ctypes.util.find_library('hidapi.dll'))
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\Student\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\cffi\api.py", line 821, in _load_backend_lib
raise OSError("dlopen(None) cannot work on Windows for Python 3 "
OSError: dlopen(None) cannot work on Windows for Python 3 (see http://bugs.python.org/issue23606)
`
Look at set_nonblocking and test it wit the library.
Dear Jakub,
Thank you for your great contribution!
I had some issues when I changed from USB to wireless Spacemouse, but I found the solution here (the byte-array issue that was solved here) I dont think it is implemented in the current version that is downloaded from PyPi however.
My next issue is the fact that rotation doesnt show any reaction ( roll, pitch, yaw). I'm testing on a beaglebone blue running some new debian release. I tried to change channels in the pyspacemouse.py similar to the wired versions, but no change there...
When I connect the device, i get 5 HID devices popping up..
Best regards
Viktor
In a Python application with a SpaceMouse Wireless and SpaceMouse Compact we have very high delays when reading data.
We get the first values after initiating a movement after 100ms, but after reaching the zero position again it takes about 1-2 seconds until the values return to zero.
Is this problem known or are certain filters applied?
We are using the pyspacemouse package, and the 3 methods open(), read(), close().
Here is my code:
Thank you very much for your support.
Hi, I am receiving the following error on a raspi installation, any idea where it come from ?
Traceback (most recent call last):
File "/home/user/git/example.py", line 8, in <module>
state=pyspacemouse.read()
File "/home/user/.local/lib/python3.9/site-packages/pyspacemouse/pyspacemouse.py", line 586, in read
return _active_device.read()
File "/home/user/.local/lib/python3.9/site-packages/pyspacemouse/pyspacemouse.py", line 209, in read
self.process(ret)
File "/home/user/.local/lib/python3.9/site-packages/pyspacemouse/pyspacemouse.py", line 241, in process
flip * to_int16(data[b1], data[b2]) / float(self.axis_scale)
IndexError: bytearray index out of range
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.