From b749ae14b503c3a01d8fcefc22daf561454a3de0 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 7 Nov 2020 01:51:58 +0200 Subject: [PATCH] fixed spaceball on freebsd --- Makefile | 2 +- src/main.c | 10 ++++++++-- src/sball.c | 24 ++++++++++++++---------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a41c55c..e352f41 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -src = $(wildcard src/*.c) +src = src/main.c src/sball.c obj = $(src:.c=.o) dep = $(obj:.o=.d) bin = sball diff --git a/src/main.c b/src/main.c index 3c41acf..ec3bcf8 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,12 @@ #include #include "sball.h" +#ifdef __FreeBSD__ +#define DEFDEV "/dev/ttyu0" +#else +#define DEFDEV "/dev/ttyS0" +#endif + static void sighandler(int s); static struct sball *sb; @@ -18,8 +24,8 @@ int main(int argc, char **argv) signal(SIGINT, sighandler); - if(!(sb = sball_open(argv[1] ? argv[1] : "/dev/ttyS0"))) { - fprintf(stderr, "Failed to open spaceball at %s\n", argv[1] ? argv[1] : "/dev/ttyS0"); + if(!(sb = sball_open(argv[1] ? argv[1] : DEFDEV))) { + fprintf(stderr, "Failed to open spaceball at %s\n", argv[1] ? argv[1] : DEFDEV); return 1; } fd = sball_fd(sb); diff --git a/src/sball.c b/src/sball.c index 9dce2ae..951ff45 100644 --- a/src/sball.c +++ b/src/sball.c @@ -169,7 +169,13 @@ int sball_num_buttons(struct sball *sb) return sb->nbuttons; } -/* Labtec spaceball: 9600 8n1 XON/XOFF */ +/* Labtec spaceball: 9600 8n1 XON/XOFF + * Can't use canonical mode to assemble input into lines for the spaceball, + * because binary data received for motion events can include newlines which + * would be eaten up by the line discipline. Therefore we'll rely on VTIME=1 to + * hopefully get more than 1 byte at a time. Alternatively we could request + * printable reports, but I don't feel like implementing that. + */ static int stty_sball(struct sball *sb) { int mstat; @@ -177,17 +183,12 @@ static int stty_sball(struct sball *sb) term = sb->saved_term; term.c_oflag = 0; - term.c_lflag = ICANON; + term.c_lflag = 0; term.c_cc[VMIN] = 0; - term.c_cc[VTIME] = 0; - term.c_cc[VEOF] = 0; - term.c_cc[VEOL] = '\r'; - term.c_cc[VEOL2] = 0; - term.c_cc[VERASE] = 0; - term.c_cc[VKILL] = 0; + term.c_cc[VTIME] = 1; term.c_cflag = CLOCAL | CREAD | CS8 | HUPCL; - term.c_iflag = IGNBRK | IGNPAR; + term.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF; cfsetispeed(&term, B9600); cfsetospeed(&term, B9600); @@ -203,7 +204,10 @@ static int stty_sball(struct sball *sb) return 0; } -/* Logicad magellan spacemouse: 9600 8n2 CTS/RTS */ +/* Logicad magellan spacemouse: 9600 8n2 CTS/RTS + * Since the magellan devices don't seem to send any newlines, we can rely on + * canonical mode to feed us nice whole lines at a time. + */ static int stty_mag(struct sball *sb) { int mstat; -- 1.7.10.4