kopia lustrzana https://github.com/FreeSpacenav/spacenavd
starting the hidapi USB device backend
rodzic
9b46aebfee
commit
a4c98fbe33
|
@ -10,7 +10,7 @@ warn = -pedantic -Wall
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
CFLAGS = $(warn) $(dbg) $(opt) -fno-strict-aliasing -fcommon \
|
CFLAGS = $(warn) $(dbg) $(opt) -fno-strict-aliasing -fcommon \
|
||||||
-I$(srcdir)/src -I/usr/local/include -MMD $(add_cflags)
|
-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)
|
$(bin): $(obj)
|
||||||
$(CC) -o $@ $(obj) $(LDFLAGS)
|
$(CC) -o $@ $(obj) $(LDFLAGS)
|
||||||
|
|
|
@ -141,6 +141,17 @@ HAVE_MALLOC_H=`check_header malloc.h`
|
||||||
HAVE_STDINT_H=`check_header stdint.h`
|
HAVE_STDINT_H=`check_header stdint.h`
|
||||||
HAVE_INTTYPES_H=`check_header inttypes.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
|
if [ "$X11" = "no" ]; then
|
||||||
echo "WARNING: you have disabled the X11 interface, the resulting daemon \
|
echo "WARNING: you have disabled the X11 interface, the resulting daemon \
|
||||||
won't be compatible with applications written for the proprietary 3Dconnexion \
|
won't be compatible with applications written for the proprietary 3Dconnexion \
|
||||||
|
@ -181,6 +192,11 @@ if [ "$X11" = 'yes' ]; then
|
||||||
echo 'xlib += -lX11 -lXext' >>Makefile
|
echo 'xlib += -lX11 -lXext' >>Makefile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$HAVE_HIDAPI_H" ]; then
|
||||||
|
echo 'hidapi = -lhidapi-hidraw' >>Makefile
|
||||||
|
#echo 'hidapi = -lhidapi-libusb' >>Makefile
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$CFLAGS" ]; then
|
if [ -n "$CFLAGS" ]; then
|
||||||
echo "add_cflags = $CFLAGS" >>Makefile
|
echo "add_cflags = $CFLAGS" >>Makefile
|
||||||
fi
|
fi
|
||||||
|
@ -206,6 +222,10 @@ if [ "$HOTPLUG" = yes ]; then
|
||||||
echo '#define USE_NETLINK' >>$cfgheader
|
echo '#define USE_NETLINK' >>$cfgheader
|
||||||
echo >>$cfgheader
|
echo >>$cfgheader
|
||||||
fi
|
fi
|
||||||
|
if [ -n "$HAVE_HIDAPI_H" ]; then
|
||||||
|
echo '#define USE_HIDAPI' >>$cfgheader
|
||||||
|
echo >>$cfgheader
|
||||||
|
fi
|
||||||
echo '#define VERSION "'$VER'"' >>$cfgheader
|
echo '#define VERSION "'$VER'"' >>$cfgheader
|
||||||
echo >>$cfgheader
|
echo >>$cfgheader
|
||||||
|
|
||||||
|
@ -216,6 +236,7 @@ echo >>$cfgheader
|
||||||
[ -n "$HAVE_INTTYPES_H" ] && echo $HAVE_INTTYPES_H >>$cfgheader
|
[ -n "$HAVE_INTTYPES_H" ] && echo $HAVE_INTTYPES_H >>$cfgheader
|
||||||
[ -n "$HAVE_XINPUT2_H" ] && echo $HAVE_XINPUT2_H >>$cfgheader
|
[ -n "$HAVE_XINPUT2_H" ] && echo $HAVE_XINPUT2_H >>$cfgheader
|
||||||
[ -n "$HAVE_XTEST_H" ] && echo $HAVE_XTEST_H >>$cfgheader
|
[ -n "$HAVE_XTEST_H" ] && echo $HAVE_XTEST_H >>$cfgheader
|
||||||
|
[ -n "$HAVE_HIDAPI_H" ] && echo $HAVE_HIDAPI_H >>$cfgheader
|
||||||
echo >>$cfgheader
|
echo >>$cfgheader
|
||||||
|
|
||||||
echo "#define CFGDIR \"$CFGDIR\"" >>$cfgheader
|
echo "#define CFGDIR \"$CFGDIR\"" >>$cfgheader
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
spacenavd - a free software replacement driver for 6dof space-mice.
|
||||||
|
Copyright (C) 2007-2023 John Tsiombikas <nuclear@member.fsf.org>
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef USE_HIDAPI
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <hidapi/hidapi.h>
|
||||||
|
#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
|
|
@ -15,9 +15,10 @@ GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifdef __linux__
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#if defined(__linux__) && !defined(USE_HIDAPI)
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
Ładowanie…
Reference in New Issue