magellan works
[sball] / src / main.c
index 04b0ace..c39e0ff 100644 (file)
@@ -1,16 +1,45 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/select.h>
 #include "sball.h"
 
+static void sighandler(int s);
+
 static struct sball *sb;
+static int quit;
 
 int main(int argc, char **argv)
 {
+       int fd;
+       fd_set rdset;
+
+       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");
                return 1;
        }
+       fd = sball_fd(sb);
+
+       while(!quit) {
+               FD_ZERO(&rdset);
+               FD_SET(fd, &rdset);
+
+               if(select(fd + 1, &rdset, 0, 0, 0) > 0) {
+                       if(FD_ISSET(fd, &rdset)) {
+                               sball_read(sb);
+                       }
+               }
+       }
 
        sball_close(sb);
        return 0;
 }
+
+static void sighandler(int s)
+{
+       quit = 1;
+}