X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=sball;a=blobdiff_plain;f=src%2Fmain.c;h=c39e0ffea30cfd4b92b90f19a9ac3328746aa91d;hp=04b0acea31b4d22bc7e1e70fa9f234a8cc168d5d;hb=3c1dc0f43eade1f8e59f74ffcc41153ed0dff15f;hpb=aae3666f514af7606db0fe34c601bfdafa4cb7dc diff --git a/src/main.c b/src/main.c index 04b0ace..c39e0ff 100644 --- a/src/main.c +++ b/src/main.c @@ -1,16 +1,45 @@ #include #include +#include +#include +#include +#include #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; +}