summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2022-10-12 15:05:06 +0200
committerBad Diode <bd@badd10de.dev>2022-10-12 15:05:06 +0200
commit241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff (patch)
tree9c61eb52898e3bcbf943b042b5f6821623716028
parent457efc07cd5989e947bc2f05feef9173fbde541a (diff)
downloaduxnnst-241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff.tar.gz
uxnnst-241ee5cfb2d8d81ea9f31648f4c1f05c6a5006ff.zip
[WIP] Add exit handler to home button
-rw-r--r--src/main.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 7ae8ef8..a0a56f9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -60,6 +60,7 @@ typedef struct Mouse {
60typedef struct Input { 60typedef struct Input {
61 int kbd_fd; 61 int kbd_fd;
62 int mouse_fd; 62 int mouse_fd;
63 int home_fd;
63 char map[KEY_MAX / 8 + 1]; 64 char map[KEY_MAX / 8 + 1];
64 u8 controller; 65 u8 controller;
65 Mouse mouse; 66 Mouse mouse;
@@ -84,6 +85,12 @@ init_input(void) {
84 fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); 85 fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
85 } 86 }
86 87
88 // NOTE: nook home and power buttons event handler.
89 in.home_fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK);
90 if (in.home_fd == -1) {
91 fprintf(stderr, "error: couldn't open home buttons %s: %s.\n", "/dev/input/event1", strerror(errno));
92 }
93
87 // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); 94 // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
88 in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK); 95 in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
89 if (in.mouse_fd == -1) { 96 if (in.mouse_fd == -1) {
@@ -162,9 +169,24 @@ poll_mouse(void) {
162} 169}
163 170
164void 171void
172poll_home(void) {
173 if (in.home_fd == -1) {
174 return;
175 }
176
177 struct input_event event;
178 if (read(in.home_fd, &event, sizeof(event)) != -1) {
179 if (event.code == 102 && event.value == 1) {
180 exit(EXIT_SUCCESS);
181 }
182 }
183}
184
185void
165poll_input(void) { 186poll_input(void) {
166 poll_keyboard(); 187 poll_keyboard();
167 poll_mouse(); 188 poll_mouse();
189 poll_home();
168} 190}
169 191
170void 192void