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

Commit 53973fa

Browse files
committed
- added UNIX text program
- in the middle of converting and expanding the UNIX serial code over from the sball test program.
1 parent cb600f5 commit 53973fa

File tree

9 files changed

+381
-13
lines changed

9 files changed

+381
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
libspnavdev.a
55
libspnavdev.so*
66
libspnavdev.dll
7+
test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
PREFIX ?= /usr/local
22

3-
src = src/spnavdev.c
3+
src = src/spnavdev.c src/serdev.o src/usbdev.o
44
obj = $(src:.c=.o)
55
dep = $(obj:.o=.d)
66
name = spnavdev
77

88
so_abi = 0
99
so_rev = 1
1010

11-
CFLAGS = -pedantic -Wall -g -MMD
11+
CFLAGS = -pedantic -Wall -g -MMD $(pic)
1212

1313
alib = lib$(name).a
1414

examples/unix/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
obj = test.o
2+
bin = test
3+
4+
CFLAGS = -pedantic -Wall -g -I../../src
5+
LDFLAGS = ../../libspnavdev.a
6+
7+
$(bin): $(obj)
8+
$(CC) -o $@ $(obj) $(LDFLAGS)
9+
10+
.PHONY: clean
11+
clean:
12+
$(RM) $(obj) $(bin)

examples/unix/test.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <signal.h>
5+
#include <errno.h>
6+
#include <unistd.h>
7+
#include <sys/select.h>
8+
#include "spnavdev.h"
9+
10+
#ifdef __FreeBSD__
11+
#define DEFDEV "/dev/ttyu0"
12+
#elif defined(__sgi__)
13+
#define DEFDEV "/dev/ttyd1"
14+
#else
15+
#define DEFDEV "/dev/ttyS0"
16+
#endif
17+
18+
static void sighandler(int s);
19+
20+
static struct spndev *dev;
21+
static int quit;
22+
23+
int main(int argc, char **argv)
24+
{
25+
int fd;
26+
fd_set rdset;
27+
union spndev_event ev;
28+
const char *s;
29+
30+
signal(SIGINT, sighandler);
31+
32+
if(!(dev = spndev_open(argv[1]))) {
33+
fprintf(stderr, "Failed to open 6dof device %s\n", argv[1] ? argv[1] : "");
34+
return 1;
35+
}
36+
fd = spndev_fd(dev);
37+
38+
printf("Monitoring device, ctrl-c to quit\n");
39+
40+
while(!quit) {
41+
FD_ZERO(&rdset);
42+
FD_SET(fd, &rdset);
43+
44+
if(select(fd + 1, &rdset, 0, 0, 0) > 0) {
45+
if(FD_ISSET(fd, &rdset)) {
46+
if(spndev_process(dev, &ev)) {
47+
switch(ev.type) {
48+
case SPNDEV_MOTION:
49+
printf("motion: T[%+6d %+6d %+6d] R[%+6d %+6d %+6d]\n",
50+
ev.mot.v[0], ev.mot.v[1], ev.mot.v[2], ev.mot.v[3],
51+
ev.mot.v[4], ev.mot.v[5]);
52+
break;
53+
54+
case SPNDEV_BUTTON:
55+
if((s = spndev_button_name(dev, ev.bn.num))) {
56+
printf("button %d (%s) ", ev.bn.num, s);
57+
} else {
58+
printf("button %d ", ev.bn.num);
59+
}
60+
puts(ev.bn.press ? "pressed" : "released");
61+
break;
62+
63+
default:
64+
break;
65+
}
66+
}
67+
}
68+
}
69+
70+
}
71+
72+
spndev_close(dev);
73+
return 0;
74+
}
75+
76+
static void sighandler(int s)
77+
{
78+
quit = 1;
79+
}

src/dev.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#ifndef SPNAVDEV_DEVICE_H_
1919
#define SPNAVDEV_DEVICE_H_
2020

21+
#include "spnavdev.h"
22+
23+
struct axisprop {
24+
char *name;
25+
int minval, maxval, deadz;
26+
};
27+
2128
struct spndev {
2229
char *name, *path;
2330
int usb_vendor, usb_product;
@@ -26,12 +33,11 @@ struct spndev {
2633
void *handle; /* Win32 handle */
2734

2835
int num_axes, num_buttons;
29-
char **axis_name, **bn_name;
30-
int *minval, *maxval;
31-
int *deadz;
36+
struct axisprop *aprop;
37+
char **bn_name;
3238
int led;
3339

34-
void *uptr;
40+
void *uptr, *drvdata;
3541

3642
void (*close)(struct spndev*);
3743
int (*read)(struct spndev*, union spndev_event*);
@@ -41,8 +47,8 @@ struct spndev {
4147
};
4248

4349

44-
struct spndev *spndev_usb_open(const char *devstr, int vend, int prod);
45-
struct spndev *spndev_ser_open(const char *devstr);
50+
int spndev_usb_open(struct spndev *dev, const char *devstr, int vend, int prod);
51+
int spndev_ser_open(struct spndev *dev, const char *devstr);
4652

4753

4854
#endif /* SPNAVDEV_DEVICE_H_ */

0 commit comments

Comments
 (0)