Explore HIDAPI callback function #13
JakubAndrysek
started this conversation in
Ideas
Replies: 1 comment
-
Something like this import hidapi
def my_callback(device, data, length):
print(f"Received {length} bytes of data: {data}")
# Open a HID device
handle = hidapi.hid_open_path(vendor_id=0x1234, product_id=0x5678, path="/dev/hidraw0")
if handle is None:
print("Failed to open HID device")
else:
# Register the callback function
hidapi.hid_set_callback(handle, my_callback)
# Write data to the device
data = [0x01, 0x02, 0x03]
num_bytes_written = hidapi.hid_write(handle, data, len(data))
print(f"Wrote {num_bytes_written} bytes of data")
# Read data from the device
data = hidapi.hid_read(handle, 64)
if data is None:
print("Failed to read data from HID device")
else:
print(f"Read {len(data)} bytes of data: {data}")
# Close the HID device
hidapi.hid_close(handle) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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
dev.set_raw_data_handler(lambda x: new_device.process(x))
Beta Was this translation helpful? Give feedback.
All reactions