Add parameters to spnav_open : product & vendor id

This commit is contained in:
Thibaud Gasser 2018-05-30 11:36:20 +02:00
parent 0daaf52c7c
commit f37537fa83
4 changed files with 6 additions and 9 deletions

View File

@ -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

3
main.c
View File

@ -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 <signal.h>
#include <stdbool.h>
@ -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 (;;) {

View File

@ -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;

View File

@ -2,9 +2,6 @@
#define SPNAV_H__
#include <stdbool.h>
#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);