2018-05-22 23:25:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define MAX_STR 255
|
|
|
|
#define SPNAV_VENDOR_ID 0x046d
|
|
|
|
#define SPNAV_PRODUCT_ID 0xc626
|
2018-05-30 09:36:20 +00:00
|
|
|
#define SPNAV_3D_EXPLORER_PRODUCT_ID 0x0c627
|
2018-05-22 23:25:02 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "spnav.h"
|
|
|
|
|
|
|
|
static bool INTERRUPTED = false;
|
|
|
|
|
|
|
|
void sighandler(int signo) {
|
|
|
|
if (signo == SIGINT) {
|
|
|
|
INTERRUPTED = true;
|
2018-05-30 09:30:18 +00:00
|
|
|
}
|
2018-05-22 23:25:02 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 09:30:18 +00:00
|
|
|
int main(int argc, char const* argv[]) {
|
2018-05-22 23:25:02 +00:00
|
|
|
signal(SIGINT, sighandler);
|
2018-05-30 09:30:18 +00:00
|
|
|
spnav_event ev;
|
2018-05-30 09:36:20 +00:00
|
|
|
spnav_open(SPNAV_VENDOR_ID, SPNAV_3D_EXPLORER_PRODUCT_ID);
|
2018-05-30 09:30:18 +00:00
|
|
|
spnav_sensitivity(0.1);
|
|
|
|
spnav_deadzone(10);
|
2018-05-30 22:10:16 +00:00
|
|
|
spnav_set_nonblocking(true);
|
2018-05-30 09:30:18 +00:00
|
|
|
for (;;) {
|
2018-05-30 22:10:16 +00:00
|
|
|
// spnav_wait_event_timeout(&ev, 400);
|
|
|
|
spnav_wait_event(&ev);
|
2018-05-30 09:30:18 +00:00
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case MOTION:
|
2018-05-22 23:25:02 +00:00
|
|
|
printf("x=%d, y=%d, z=%d ", ev.motion.x, ev.motion.y, ev.motion.z);
|
|
|
|
printf("rx=%d, ry=%d, rz=%d\n", ev.motion.rx, ev.motion.ry, ev.motion.rz);
|
|
|
|
break;
|
|
|
|
case BUTTON:
|
2018-05-23 12:42:09 +00:00
|
|
|
printf("bnum=%d, pressed=%d\n", ev.button.bnum, ev.button.press);
|
2018-05-22 23:25:02 +00:00
|
|
|
break;
|
2018-05-30 09:30:18 +00:00
|
|
|
}
|
2018-05-22 23:25:02 +00:00
|
|
|
|
2018-05-30 09:30:18 +00:00
|
|
|
if (INTERRUPTED) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spnav_close();
|
2018-05-22 23:25:02 +00:00
|
|
|
}
|