#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; }