From f37537fa836f19905f43dc5fd49e58384790d38a Mon Sep 17 00:00:00 2001 From: Thibaud Date: Wed, 30 May 2018 11:36:20 +0200 Subject: [PATCH] Add parameters to spnav_open : product & vendor id --- Makefile | 2 +- main.c | 3 ++- spnav.c | 5 ++--- spnav.h | 5 +---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index e1ed0e4..d34122c 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ TARGET_LIB = libspnavhdi.so # target lib CC = gcc #CFLAGS = -Wall -Wextra -fPIC -pedantic -O2 # C flags for building library -CFLAGS = -Wall -Wextra -pedantic -g # C flags for developpement +CFLAGS = -Wall -Wextra -pedantic -g -DDEBUG # C flags for developpement LDFLAGS = -Wall -Wextra -O2 diff --git a/main.c b/main.c index 58e5ad4..e84159c 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ #define MAX_STR 255 #define SPNAV_VENDOR_ID 0x046d #define SPNAV_PRODUCT_ID 0xc626 +#define SPNAV_3D_EXPLORER_PRODUCT_ID 0x0c627 #include #include @@ -20,7 +21,7 @@ void sighandler(int signo) { int main(int argc, char const* argv[]) { signal(SIGINT, sighandler); spnav_event ev; - spnav_open(); + spnav_open(SPNAV_VENDOR_ID, SPNAV_3D_EXPLORER_PRODUCT_ID); spnav_sensitivity(0.1); spnav_deadzone(10); for (;;) { diff --git a/spnav.c b/spnav.c index 5555f2b..59a363f 100644 --- a/spnav.c +++ b/spnav.c @@ -4,7 +4,6 @@ #include "spnav.h" #include "hidapi.h" -#define DEBUG #ifdef DEBUG #define DEBUG_PRINT(...) \ do { \ @@ -113,7 +112,7 @@ int set_led(hid_device *dev, char state) { return nbytes; } -int spnav_open() { +int spnav_open(unsigned short vendor_id, unsigned short product_id) { DEBUG_PRINT("spnav_open()\n"); /* Connexion already opened */ if (IS_OPEN) { @@ -124,7 +123,7 @@ int spnav_open() { hid_init(); // Open the device using the VID, PID, // and optionally the Serial number. - device = hid_open(SPNAV_VENDOR_ID, SPNAV_PRODUCT_ID, NULL); + device = hid_open(vendor_id, product_id, NULL); if (device == NULL) { DEBUG_PRINT("hid_open() failed!"); return -1; diff --git a/spnav.h b/spnav.h index fecd311..b23ee8f 100644 --- a/spnav.h +++ b/spnav.h @@ -2,9 +2,6 @@ #define SPNAV_H__ #include - -#define SPNAV_VENDOR_ID 0x046d -#define SPNAV_PRODUCT_ID 0xc626 #define SPNAV_NAXIS 6 #ifdef _WIN32 @@ -47,7 +44,7 @@ typedef union spnav_event { extern "C" { #endif -int SPNAV_API_EXPORT_CALL spnav_open(void); +int SPNAV_API_EXPORT_CALL spnav_open(unsigned short vendor_id, unsigned short product_id); int SPNAV_API_EXPORT_CALL spnav_close(void); int SPNAV_API_EXPORT_CALL spnav_wait_event(spnav_event *event); int SPNAV_API_EXPORT_CALL spnav_wait_event_timeout(spnav_event *event, int timeout);