Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 31f5f35

Browse files
committed
Win32: Add working Windows example.
Works with SpaceExplorer and should mostly work with all USB devices if the usbdev.c implementation is merged.
1 parent 53973fa commit 31f5f35

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

examples/win32/test.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <signal.h>
5+
#include <errno.h>
6+
#include "spnavdev.h"
7+
8+
static struct spndev *dev;
9+
static int quit = 0;
10+
11+
int main(int argc, char **argv)
12+
{
13+
int fd;
14+
union spndev_event ev;
15+
const char *s;
16+
17+
if(!(dev = spndev_open(argv[1]))) {
18+
fprintf(stderr, "Failed to open 6dof device %s\n", argv[1] ? argv[1] : "");
19+
return 1;
20+
}
21+
fd = spndev_fd(dev);
22+
23+
printf("Monitoring device, ctrl-c to quit\n");
24+
25+
while(!quit) {
26+
27+
if(1 > 0) {
28+
if(1) {
29+
if(spndev_process(dev, &ev)) {
30+
switch(ev.type) {
31+
case SPNDEV_MOTION:
32+
printf("motion: T[%+6d %+6d %+6d] R[%+6d %+6d %+6d]\n",
33+
ev.mot.v[0], ev.mot.v[1], ev.mot.v[2], ev.mot.v[3],
34+
ev.mot.v[4], ev.mot.v[5]);
35+
break;
36+
37+
case SPNDEV_BUTTON:
38+
if((s = spndev_button_name(dev, ev.bn.num))) {
39+
printf("button %d (%s) ", ev.bn.num, s);
40+
} else {
41+
printf("button %d ", ev.bn.num);
42+
}
43+
puts(ev.bn.press ? "pressed" : "released");
44+
break;
45+
46+
default:
47+
break;
48+
}
49+
}
50+
}
51+
}
52+
53+
}
54+
55+
spndev_close(dev);
56+
return 0;
57+
}

0 commit comments

Comments
 (0)