sunbeyond 发表于 2014-8-21 11:03:06

红外测试代码

本帖最后由 sunbeyond 于 2014-8-21 11:05 编辑

lirc.c



8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <fcntl.h>
14 #include <errno.h>
15 #include <time.h>
16 #include <linux/input.h>
17
18 int main(void)
19 {
20   int fd;
21   int key_value,i=0,count;
22   struct input_event ev_key;
23   fd = open("/dev/input/event0",O_RDWR);
24   if(fd < 0){
25         perror("open device buttons");
26         exit(1);
27   }
28
29 while(1) {
30         count = read(fd,&ev_key,sizeof(struct input_event));
31         for(i=0; i<(int)count/sizeof(struct input_event); i++)
32         if(EV_KEY==ev_key.type)
33         printf("type:%d,code:%d,value:%d\n", ev_key.type,ev_key.code,ev_key.value);
34         if(EV_SYN==ev_key.type)
35         printf("syn event\n");
36      }
37          close(fd);
38          return 0;
39 }
我的板子CT。系统为debian。

我这边的红外是对应/dev/input/event0(有可能event1,event2等等)。可以通过以下方法查看。
root@cubietruck:# cat /sys/class/input/event0/device/name
sunxi-ir



$arm-linux-gnueabihf-gcc lirc.c - o lirc
拷贝lirc到板子上

$ modprobe sunxi-ir(a10的话modprobe sun4i-ir,a20有些版本是:modprobe sun7i-ir)
$./lirc
然后使用遥控器按键。返回按键类型,按键码,键值。最好使用mele遥控。






bruce 发表于 2014-8-21 18:13:12

学习了   

smileFei 发表于 2014-9-11 10:29:14

学习了,不错
页: [1]
查看完整版本: 红外测试代码