todbot / hidapitester

Simple command-line program to test HIDAPI
GNU General Public License v3.0
263 stars 31 forks source link

Add hidapi libusb backend support #8

Open mcuee opened 3 years ago

mcuee commented 3 years ago

It would be good to add hidapi libusb backend support.

mcuee commented 3 years ago

Here is a quick hack of Makefile.libusb, only for Linux, and not properly done with pkg-config.

############ Linux (libusb)
ifeq "$(OS)" "linux"

LIBS = -L/usr/local/lib -lusb-1.0 -ludev -lpthread 
OBJS = $(HIDAPI_DIR)/libusb/hid.o
EXE=

endif

############# common

CFLAGS +=-I $(HIDAPI_DIR)/hidapi -I /usr/local/include/libusb-1.0
OBJS += hidapitester.o
mcuee commented 3 years ago

It seems to work fine.

hidapitester on  master [?] ❯ ./hidapitester_libusb --vidpid 0925:7001  -l 3 --open --send-output 2,2,3 --read-input
Opening device, vid/pid: 0x0925/0x7001
Writing output report of 3-bytes...wrote 3 bytes:
 02 02 03
Reading 3-byte input report 0, 250 msec timeout...read 3 bytes:
 01 02 03
Closing device

hidapitester on  master [?] ❯ ./hidapitester_libusb --vidpid 0925:7001  -l 3 --open --send-feature 3,4,5 --read-feature 4 
Opening device, vid/pid: 0x0925/0x7001
Writing 3-byte feature report...wrote 3 bytes:
 03 04 05
Reading 3-byte feature report, report_id 4...read 3 bytes:
 04 04 05
Closing device
mcuee commented 3 years ago

A quick mod of Windows version with libusb. hidapitester_mingw64_libusb.zip

C:\work\hid\hidapitester [master ≡ +3 ~0 -0 !]> .\hidapitester_libusb.exe --vidpid=0925:7001 --open --send-output 2,0x80,0x81 --read-input
Opening device, vid/pid: 0x0925/0x7001
Writing output report of 64-bytes...wrote 3 bytes:
 02 80 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 3 bytes:
 01 80 81 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device
C:\work\hid\hidapitester [master ≡ +3 ~0 -0 !]> .\hidapitester_libusb.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 4...read 3 bytes:
 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device