summaryrefslogtreecommitdiffstats
path: root/kmd.c
blob: ca2a66af191ef30b29a9a4a0c647c8d7f67f51e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;
}