diff --git a/Makefile.in b/Makefile.in index 5a9ca3a..13af734 100644 --- a/Makefile.in +++ b/Makefile.in @@ -10,7 +10,7 @@ warn = -pedantic -Wall CC ?= gcc CFLAGS = $(warn) $(dbg) $(opt) -fno-strict-aliasing -fcommon \ -I$(srcdir)/src -I/usr/local/include -MMD $(add_cflags) -LDFLAGS = -L/usr/local/lib $(xlib) $(add_ldflags) -lm +LDFLAGS = -L/usr/local/lib $(xlib) $(hidapi) $(add_ldflags) -lm $(bin): $(obj) $(CC) -o $@ $(obj) $(LDFLAGS) diff --git a/configure b/configure index 5abad3b..725556a 100755 --- a/configure +++ b/configure @@ -141,6 +141,17 @@ HAVE_MALLOC_H=`check_header malloc.h` HAVE_STDINT_H=`check_header stdint.h` HAVE_INTTYPES_H=`check_header inttypes.h` +#if [ `uname -s` != Linux ]; then + HAVE_HIDAPI_H=`check_header hidapi/hidapi.h` + + if [ -z "$HAVE_HIDAPI_H" ]; then + echo "WARNING: without the hidapi library USB devices will not be \ +supported on this platform." + echo + fi +#fi + + if [ "$X11" = "no" ]; then echo "WARNING: you have disabled the X11 interface, the resulting daemon \ won't be compatible with applications written for the proprietary 3Dconnexion \ @@ -181,6 +192,11 @@ if [ "$X11" = 'yes' ]; then echo 'xlib += -lX11 -lXext' >>Makefile fi +if [ -n "$HAVE_HIDAPI_H" ]; then + echo 'hidapi = -lhidapi-hidraw' >>Makefile + #echo 'hidapi = -lhidapi-libusb' >>Makefile +fi + if [ -n "$CFLAGS" ]; then echo "add_cflags = $CFLAGS" >>Makefile fi @@ -206,6 +222,10 @@ if [ "$HOTPLUG" = yes ]; then echo '#define USE_NETLINK' >>$cfgheader echo >>$cfgheader fi +if [ -n "$HAVE_HIDAPI_H" ]; then + echo '#define USE_HIDAPI' >>$cfgheader + echo >>$cfgheader +fi echo '#define VERSION "'$VER'"' >>$cfgheader echo >>$cfgheader @@ -216,6 +236,7 @@ echo >>$cfgheader [ -n "$HAVE_INTTYPES_H" ] && echo $HAVE_INTTYPES_H >>$cfgheader [ -n "$HAVE_XINPUT2_H" ] && echo $HAVE_XINPUT2_H >>$cfgheader [ -n "$HAVE_XTEST_H" ] && echo $HAVE_XTEST_H >>$cfgheader +[ -n "$HAVE_HIDAPI_H" ] && echo $HAVE_HIDAPI_H >>$cfgheader echo >>$cfgheader echo "#define CFGDIR \"$CFGDIR\"" >>$cfgheader diff --git a/src/dev_usb_hidapi.c b/src/dev_usb_hidapi.c new file mode 100644 index 0000000..ad3b449 --- /dev/null +++ b/src/dev_usb_hidapi.c @@ -0,0 +1,98 @@ +/* +spacenavd - a free software replacement driver for 6dof space-mice. +Copyright (C) 2007-2023 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include "config.h" + +#ifdef USE_HIDAPI +#include +#include +#include +#include +#include "dev.h" +#include "dev_usb.h" +#include "spnavd.h" +#include "event.h" +#include "hotplug.h" +#include "client.h" + + +int open_dev_usb(struct device *dev) +{ + return -1; +} + +struct usb_dev_info *find_usb_devices(int (*match)(const struct usb_dev_info*)) +{ + int len; + struct hid_device_info *hidlist, *hid; + struct usb_dev_info *dev, *devlist = 0; + + if(!(hidlist = hid_enumerate(0, 0))) { + return 0; + } + + hid = hidlist; + while(hid) { + if(!(dev = malloc(sizeof *dev))) { + fprintf(stderr, "failed to allocate device list node\n"); + hid = hid->next; + continue; + } + + len = wcslen(hid->product_string) + 1; + if(!(dev->name = malloc(len + 1))) { + fprintf(stderr, "failed to allocate buffer for device name\n"); + free(dev); + hid = hid->next; + continue; + } + sprintf(dev->name, "%ls", hid->product_string); + + dev->num_devfiles = 1; + if(!(dev->devfiles[0] = strdup(hid->path))) { + fprintf(stderr, "failed to allocate buffer for device path\n"); + free(dev->name); + free(dev); + hid = hid->next; + continue; + } + + dev->vendorid = hid->vendor_id; + dev->productid = hid->product_id; + + /* check with the user-supplied matching callback to see if we should include + * this device in the returned list or not... + */ + if(!match || match(dev)) { + printf("DBG %x:%x %s (%x,%x) - %s\n", dev->vendorid, dev->productid, dev->devfiles[0], + hid->usage_page, hid->usage, dev->name); + /*dev->next = devlist; + devlist = dev;*/ + } else { + free(dev->name); + free(dev->devfiles[0]); + free(dev); + } + + hid = hid->next; + } + + hid_free_enumeration(hidlist); + return devlist; +} + +#endif diff --git a/src/dev_usb_linux.c b/src/dev_usb_linux.c index 5868b08..f3def12 100644 --- a/src/dev_usb_linux.c +++ b/src/dev_usb_linux.c @@ -15,9 +15,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifdef __linux__ - #include "config.h" + +#if defined(__linux__) && !defined(USE_HIDAPI) + #include #include #include