summaryrefslogtreecommitdiffstats
path: root/kmd.c
diff options
context:
space:
mode:
authorJames <git@panaceas.org>2014-05-05 17:50:20 +0100
committerJames <git@panaceas.org>2014-05-05 17:50:20 +0100
commit470457e22a1b5537013603d5e367c51e47bb61bf (patch)
tree6b72d32bfd9eaec31c8c520d18782ccaebc01759 /kmd.c
downloadkmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.tar.gz
kmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.tar.bz2
kmd_usb-470457e22a1b5537013603d5e367c51e47bb61bf.zip
fish
Diffstat (limited to 'kmd.c')
-rw-r--r--kmd.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/kmd.c b/kmd.c
new file mode 100644
index 0000000..ca2a66a
--- /dev/null
+++ b/kmd.c
@@ -0,0 +1,89 @@
+#include "project.h"
+
+
+
+
+static void
+check_bored (int b)
+{
+ static int lcd = 1;
+
+ if ((b > 8) && (lcd))
+ {
+ lcd_off ();
+ lcd = 0;
+ }
+
+ if ((b == 0) && (!lcd))
+ {
+ lcd_on ();
+ lcd = 1;
+ }
+}
+
+
+#define SCAN_TIME 4
+
+
+int
+main (int argc, char *argv[])
+{
+ struct input_event ev;
+ struct timeval tv = { 0 };
+ fd_set rfds;
+ int n;
+ int bored = 0;
+
+ usb_init ();
+
+ status_init ();
+
+ dispatch_init ();
+
+ scan_output_devs (1);
+ for (;;)
+ {
+ input_dev_t *id;
+
+ if (!tv.tv_usec && !tv.tv_sec)
+ {
+ scan_input_devs ();
+ scan_output_devs (0);
+ tv.tv_sec = SCAN_TIME;
+ bored++;
+ check_bored (bored);
+ }
+
+
+ FD_ZERO (&rfds);
+ n = 0;
+ for (id = input_devs; id; id = id->next)
+ {
+ if (id->fd == -1 || id->blacklistid)
+ continue;
+ FD_SET (id->fd, &rfds);
+ if (id->fd >= n)
+ n = id->fd + 1;
+ }
+
+ if (!select (n, &rfds, NULL, NULL, &tv))
+ continue;
+
+ for (id = input_devs; id; id = id->next)
+ {
+ if (id->fd == -1 || id->blacklistid)
+ continue;
+ if (!FD_ISSET (id->fd, &rfds))
+ continue;
+ if (read (id->fd, &ev, sizeof (struct input_event)) ==
+ sizeof (struct input_event))
+ {
+ dispatch_event (&ev);
+ bored = 0;
+ check_bored (bored);
+ }
+ }
+ }
+
+ return 0;
+}