CubieBoard中文论坛

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

是否有 ir 的 c code 範例? *問題解決 附上Code

[复制链接]
发表于 2013-4-1 11:28:50 | 显示全部楼层 |阅读模式
本帖最后由 sky 于 2013-4-1 17:16 编辑

參考了版上的 ir 設定, 可以使用 cat 讀取到 ir 的訊號
我該如何使用 c 語言 讀取 ir 的資料呢?
是否有簡單的範例可以參考
回复

使用道具 举报

发表于 2013-4-1 11:44:26 | 显示全部楼层
呵呵,台湾的朋友?

这里有一个ir使用的贴子:

http://cn.cubieboard.org/forum.p ... &extra=page%3D1

是脚本例子
c语言的话,直接read 文件节点就好了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-1 12:47:34 | 显示全部楼层
hipboi 发表于 2013-4-1 11:44
呵呵,台湾的朋友?

这里有一个ir使用的贴子:

是的,我來自台灣

謝謝囉

我來好好研究  ^^
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-1 16:57:44 | 显示全部楼层
感謝二樓大大的指導+Google 搜尋出來的一些資訊

以下是簡單的範例  XD 自己用 gcc 編譯吧
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <dirent.h>
  8. #include <linux/input.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/select.h>
  12. #include <sys/time.h>
  13. #include <termios.h>
  14. #include <signal.h>

  15. void handler (int sig)
  16. {
  17.         printf ("nexiting...(%d)n", sig);
  18.         exit (0);
  19. }

  20. void perror_exit (char *error)
  21. {
  22.         perror (error);
  23.         handler (9);
  24. }

  25. int main (int argc, char *argv[])
  26. {
  27.         struct input_event ev[64];
  28.         int fd, rd, value, size = sizeof (struct input_event);
  29.         char name[256] = "Unknown";
  30.         char *device = NULL;

  31.         //Setup check
  32.         if (argv[1] == NULL){
  33.                 printf("Please specify (on the command line) the path to the dev event interface devicen");
  34.                 exit (0);
  35.         }
  36.        
  37.         if ((getuid ()) != 0){
  38.                 printf ("You are not root! This may not work...n");
  39.         }
  40.        
  41.         if (argc > 1){
  42.                 device = argv[1];
  43.         }

  44.         //Open Device
  45.         if ((fd = open (device, O_RDONLY)) == -1){
  46.                 printf ("%s is not a vaild device.n", device);
  47.         }
  48.        
  49.         //Print Device Name
  50.         ioctl (fd, EVIOCGNAME (sizeof (name)), name);
  51.         printf ("Reading From : %s (%s)\n", device, name);
  52.        
  53.         while (1){
  54.                 if ((rd = read (fd, ev, size * 64)) < size){
  55.                         perror_exit ("read()");      
  56.                 }

  57.                 value = ev[0].value;
  58.                 if( ev[0].value == 1 ){
  59.                         printf ("Key in: %d \n", (ev[0].code));
  60.                 }else if( ev[0].value == 0 ){
  61.                         printf ("Key up: %d \n", (ev[0].code));
  62.                 }
  63.                
  64.         }

  65.         return 0;
  66. }
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-8 04:00 , Processed in 0.020634 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部