From 470457e22a1b5537013603d5e367c51e47bb61bf Mon Sep 17 00:00:00 2001 From: James Date: Mon, 5 May 2014 17:50:20 +0100 Subject: fish --- kmd.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 kmd.c (limited to 'kmd.c') 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; +} -- cgit v1.2.3