feat: input device subsystem to resolve race condition on polling input
[lunaix-os.git] / lunaix-os / kernel / demos / input_test.c
1 #include <lunaix/fctrl.h>
2 #include <lunaix/foptions.h>
3 #include <lunaix/input.h>
4 #include <lunaix/lunistd.h>
5
6 #define STDIN 1
7 #define STDOUT 0
8
9 void
10 input_test()
11 {
12     int fd = open("/dev/input/i8042-kbd", 0);
13
14     if (fd < 0) {
15         write(STDOUT, "fail to open", 13);
16         return;
17     }
18
19     struct input_evt_pkt event;
20
21     while (read(fd, &event, sizeof(event)) > 0) {
22         if (event.pkt_type == PKT_PRESS) {
23             write(STDOUT, "PRESSED: ", 10);
24         } else {
25             write(STDOUT, "RELEASE: ", 10);
26         }
27         char c = event.sys_code & 0xff;
28         write(STDOUT, &c, 1);
29         write(STDOUT, "\n", 2);
30     }
31     return;
32 }