应用程序代码参考
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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("%srn", recv_buf);
}
return 0;
}