#include <sys/select.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/fb.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #define FRAMEBUFFER_DEVICE "/dev/fb0" void alarm_handler(int); int main(int argc, char **argv) { int kbdFD = -1; kbdFD = open("/dev/keypad0", O_RDONLY | O_NDELAY, 0); if (kbdFD < 0) exit(1); char buf[64]; int pressed = 0; int done = 0; char *answer = "WTF?!"; alarm(1); signal(SIGALRM, alarm_handler); while (!done) { int fbh = open(FRAMEBUFFER_DEVICE, O_RDWR); ioctl(fbh, FBIOSETBKLIGHT, BKLIGHT_ON); ioctl(fbh, FBIOSETBRIGHTNESS, 30); close(fbh); fd_set fds; struct timeval tv; int retval; tv.tv_sec = 1; tv.tv_usec = 0; FD_ZERO(&fds); FD_SET(kbdFD, &fds); retval = select(kbdFD+1, &fds, NULL, NULL, &tv); int i; if (FD_ISSET(kbdFD, &fds)) { int n = read(kbdFD, buf, 64); for (i=0; i<n && !done; i++) { // printf("key 0x%X\n", buf[i]); switch(buf[i]) { case 0x80: if (pressed) done = 1; break; case 0x25: pressed = 1; answer = "left_up"; break; case 0x19: pressed = 1; answer = "right_up"; break; } } } } lseek(kbdFD, 0, SEEK_END); close(kbdFD); printf("%s\n", answer); return 0; } void alarm_handler(int sig) { exit(0); }