CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 8278|回复: 2

红外测试代码

[复制链接]
发表于 2014-8-21 11:03:06 | 显示全部楼层 |阅读模式
本帖最后由 sunbeyond 于 2014-8-21 11:05 编辑
  1.   lirc.c



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






回复

使用道具 举报

发表于 2014-8-21 18:13:12 | 显示全部楼层
学习了   
回复 支持 反对

使用道具 举报

发表于 2014-9-11 10:29:14 | 显示全部楼层
学习了,不错
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-4-19 09:25 , Processed in 0.020203 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部