button按键测试

该博客介绍了一个在Linux系统中用于测试硬件上四个按键的C语言程序。程序通过读取/dev/input/event0(对应按键1和2)和/dev/input/event3(对应按键3和4)的输入事件来检测按键是否被按下。程序使用非阻塞方式打开设备文件,并在设定的超时时间内检查按键状态。如果所有按键都被按下,则测试成功,否则测试失败。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define DEV_PATH0 "/dev/input/event0"   //button1 button2对应的是event0
#define DEV_PATH3 "/dev/input/event3"   //button3 button4对应的是event3


int main(int argc, char **argv)
{
    int i = 0;
    int but1 = 0;
    int but2 = 0;
    int but3 = 0;
    int but4 = 0;
    int times = 5; //缺省超时时间
    int ret = 0;
    char buffer[128] = {0};
    int keys_fd = 0;
    struct input_event t;

    if (argc == 2) {
        times = (int)strtoul(argv[1], NULL, 10);  //传入的超时时间
    }

    keys_fd=open(DEV_PATH0, O_RDONLY | O_NDELAY);   //非阻塞的方式打开
    if(keys_fd <= 0)
    {
        printf("open /dev/input/event0 device error!\n");
        return -1;
    }

    for(i=0;i<tim
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值