13 static int stty_sball(int fd);
14 static int stty_mag(int fd);
16 struct sball *sball_open(const char *dev)
21 if((fd = open(dev, O_RDWR | | O_NOCTTY | O_NONBLOCK)) == -1) {
22 fprintf(stderr, "sball_open: failed to open device: %s: %s\n", dev, strerror(errno));
26 if(!(sb = malloc(sizeof *sb))) {
27 fprintf(stderr, "sball_open: failed to allocate sball object\n");
32 if(stty_sball(fd) == -1) {
36 /* set detect receiver function pointer */
46 void sball_close(struct sball *sb)
53 /* Labtec spaceball: 9600 8n1 XON/XOFF */
54 static int stty_sball(int fd)
58 if(tcgetattr(fd, &term) == -1) {
59 perror("sball_open: tcgetattr");
68 term.c_cflag = CLOCAL | CREAD | CS8 | HUPCL;
69 term.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF;
71 csetispeed(&term, B9600);
72 csetospeed(&term, B9600);
74 if(tcsetattr(fd, TCSANOW, &term) == -1) {
75 perror("sball_open: tcsetattr");
82 /* Logicad magellan spacemouse: 9600 8n2 CTS/RTS */
83 static int stty_mag(int fd)
87 if(tcgetattr(fd, &term) == -1) {
88 perror("sball_open: tcgetattr");
97 term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL | CRTSCTS;
98 term.c_iflag = IGNBRK | IGNPAR |;
100 csetispeed(&term, B9600);
101 csetospeed(&term, B9600);
103 if(tcsetattr(fd, TCSANOW, &term) == -1) {
104 perror("sball_open: tcsetattr");