spnav-csharp-wrapper/main.c

45 lines
1009 B
C
Raw Normal View History

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
#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;
spnav_open();
spnav_sensitivity(0.1);
spnav_deadzone(10);
for (;;) {
spnav_wait_event_timeout(&ev, 400);
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:
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
}