diff --git a/spnav.c b/spnav.c index ac6c103..a7f0030 100644 --- a/spnav.c +++ b/spnav.c @@ -4,8 +4,6 @@ #include "spnav.h" #include "hidapi.h" -#define DEBUG - #ifdef DEBUG #define DEBUG_PRINT(...) do{ fprintf( stderr, __VA_ARGS__ ); } while( false ) #else @@ -37,11 +35,11 @@ int convert_input(int first, unsigned char val) { } } -bool in_deadzone(unsigned char *data) { +bool in_deadzone(unsigned char *data, int threshold) { /* data[0] is the event type */ int i; for (i=1; i threshold) { return false; } } @@ -51,7 +49,6 @@ bool in_deadzone(unsigned char *data) { int read_event(hid_device *device, spnav_event* ev, int ms) { unsigned char buf[64]; - int i; int nbytes = hid_read_timeout(device, buf, sizeof(buf), ms); if (nbytes < 0) { DEBUG_PRINT("hid_read_timeout() error"); @@ -64,7 +61,7 @@ int read_event(hid_device *device, spnav_event* ev, int ms) { switch (ev->type) { case TRANSLATION: - if (in_deadzone(buf)) { + if (in_deadzone(buf, 4)) { ev->type = 0; return ev->type; } @@ -72,13 +69,10 @@ int read_event(hid_device *device, spnav_event* ev, int ms) { ev->motion.x = convert_input((buf[1] & 0x0000ff), buf[2]); ev->motion.y = convert_input((buf[3] & 0x0000ff), buf[4]); ev->motion.z = convert_input((buf[5] & 0x0000ff), buf[6]); - for (i=0; i < SPNAV_NAXIS; i++) { - ev->motion.data[i] = buf[i]; - } // DEBUG_PRINT("Translation x=%d, y=%d, z=%d\n", ev->motion.x, ev->motion.y, ev->motion.z); break; case ROTATION: - if (in_deadzone(buf)) { + if (in_deadzone(buf, 4)) { ev->type = 0; return ev->type; } @@ -86,9 +80,6 @@ int read_event(hid_device *device, spnav_event* ev, int ms) { ev->motion.rx = convert_input((buf[1] & 0x0000ff), buf[2]); ev->motion.ry = convert_input((buf[3] & 0x0000ff), buf[4]); ev->motion.rz = convert_input((buf[5] & 0x0000ff), buf[6]); - for (i=0; i < SPNAV_NAXIS; i++) { - ev->motion.data[i] = buf[i]; - } // DEBUG_PRINT("Rotation rx=%d, ry=%d, rz=%d\n", ev->motion.rx, ev->motion.ry, ev->motion.rz); break; case BTN: diff --git a/spnav.h b/spnav.h index 21c07a1..3368fb2 100644 --- a/spnav.h +++ b/spnav.h @@ -26,7 +26,7 @@ struct event_motion { int x, y, z; int rx, ry, rz; unsigned int period; - int data[SPNAV_NAXIS]; + int *data; }; struct event_button { @@ -50,9 +50,10 @@ int SPNAV_API_EXPORT_CALL spnav_close(void); // TODO : return event type 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); -//spnav_event SPNAV_API_EXPORT_CALL read_event(int timeout); +int SPNAV_API_EXPORT_CALL spnav_sensitivity(double sens); #ifdef __cplusplus } #endif + #endif /* SPNAV_H__ */ \ No newline at end of file