📄 testapp.c
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/select.h>#include <sys/time.h>#include <errno.h>int main(void){ int pad_fd; int key_value; fd_set rds; int ret,ret1; printf(" open pad ... ...\n"); pad_fd = open("/dev/pad", 0); if (pad_fd < 0) { perror("open device pad\n"); exit(1); } printf(" open pad ok!\n"); for (;;) { FD_ZERO(&rds); //clear the fd_set FD_SET(pad_fd, &rds);//add pad_fd to the fd_set ret = select(pad_fd + 1, &rds, NULL, NULL, NULL); //if the fd_set is readbles or writeable? if (ret < 0) { perror("select"); exit(1); } if (ret == 0) { printf("Timeout.\n"); } else if (FD_ISSET(pad_fd, &rds)) //if the pad_fd in the fd_set { ret1 = read(pad_fd, &key_value, sizeof key_value); if (ret1 != sizeof key_value) { if (errno != EAGAIN) perror("read buttons\n"); continue; } else { printf("buttons_value: %d\n", key_value); } } } close(pad_fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -