fixed spaceball on freebsd
authorJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 6 Nov 2020 23:51:58 +0000 (01:51 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 6 Nov 2020 23:51:58 +0000 (01:51 +0200)
Makefile
src/main.c
src/sball.c

index a41c55c..e352f41 100644 (file)
--- 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
index 3c41acf..ec3bcf8 100644 (file)
@@ -6,6 +6,12 @@
 #include <sys/select.h>
 #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);
index 9dce2ae..951ff45 100644 (file)
@@ -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;