projects
/
sball
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
magellan works
[sball]
/
src
/
main.c
diff --git
a/src/main.c
b/src/main.c
index
7fe32c5
..
c39e0ff
100644
(file)
--- a/
src/main.c
+++ b/
src/main.c
@@
-1,16
+1,45
@@
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/select.h>
#include "sball.h"
#include "sball.h"
-static int fd;
+static void sighandler(int s);
+
+static struct sball *sb;
+static int quit;
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
- if(!(fd = sball_open(argv[1] ? argv[1] : "/dev/ttyS0"))) {
+ 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;
}
fprintf(stderr, "Failed to open spaceball at %s\n", argv[1] ? argv[1] : "/dev/ttyS0");
return 1;
}
+ fd = sball_fd(sb);
- sball_close(fd);
+ 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;
}
return 0;
}
+
+static void sighandler(int s)
+{
+ quit = 1;
+}