[WIP] Add exit handler to home button
This commit is contained in:
parent
457efc07cd
commit
241ee5cfb2
22
src/main.c
22
src/main.c
|
@ -60,6 +60,7 @@ typedef struct Mouse {
|
||||||
typedef struct Input {
|
typedef struct Input {
|
||||||
int kbd_fd;
|
int kbd_fd;
|
||||||
int mouse_fd;
|
int mouse_fd;
|
||||||
|
int home_fd;
|
||||||
char map[KEY_MAX / 8 + 1];
|
char map[KEY_MAX / 8 + 1];
|
||||||
u8 controller;
|
u8 controller;
|
||||||
Mouse mouse;
|
Mouse mouse;
|
||||||
|
@ -84,6 +85,12 @@ init_input(void) {
|
||||||
fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
|
fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: nook home and power buttons event handler.
|
||||||
|
in.home_fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK);
|
||||||
|
if (in.home_fd == -1) {
|
||||||
|
fprintf(stderr, "error: couldn't open home buttons %s: %s.\n", "/dev/input/event1", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
// in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
|
// in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK);
|
||||||
in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
|
in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK);
|
||||||
if (in.mouse_fd == -1) {
|
if (in.mouse_fd == -1) {
|
||||||
|
@ -161,10 +168,25 @@ poll_mouse(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
poll_home(void) {
|
||||||
|
if (in.home_fd == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct input_event event;
|
||||||
|
if (read(in.home_fd, &event, sizeof(event)) != -1) {
|
||||||
|
if (event.code == 102 && event.value == 1) {
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
poll_input(void) {
|
poll_input(void) {
|
||||||
poll_keyboard();
|
poll_keyboard();
|
||||||
poll_mouse();
|
poll_mouse();
|
||||||
|
poll_home();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue