应用程序代码参考
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <errno.h>
#define DEV_NAME "/dev/mybtn"
int main(int argc, char *args[])
{
int fd = 0;
int ret = 0;
unsigned char recv_buf[1] = {"0"};
fd = open(DEV_NAME, O_RDONLY);
//fd = open(DEV_NAME, O_RDONLY|O_NONBLOCK);
if(fd < 0) {
perror("open");
}
while(1) {
strcpy(recv_buf, "0000");
//读取按键数据
ret = read(fd, recv_buf, 1);
if((ret < 0) && (errno != EAGAIN)) {
perror("read");
exit(-1);
}
//输出按键状态
printf("%s\r\n", recv_buf);
}
return 0;
}