免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5032 | 回复: 11
打印 上一主题 下一主题

input子系统问题 [复制链接]

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-04 19:50 |只看该作者 |倒序浏览
比如一个进程读取/dev/input/event0,现在有触摸屏,鼠标等各种设备,在用户程序中怎样判断是谁report的event阿,这个应该怎样实现?

论坛徽章:
0
2 [报告]
发表于 2011-08-04 20:11 |只看该作者
/dev/input/event0
/dev/input/event1
不同设备都不是对应同一个,打开哪个读的就是哪个设备的

论坛徽章:
0
3 [报告]
发表于 2011-08-04 21:07 |只看该作者
它们发的事件都是不一样的,比如触摸屏上报ABS,再上报一个按下的KEY事件,多点也类似。
鼠标的话上报的是相对值事件。

如果你去读设备节点,获得的包数据是不一样的事件类似。

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
4 [报告]
发表于 2011-08-04 22:40 |只看该作者
回复 3# lengyuex

请问您可是友善论坛里的版主?

论坛徽章:
0
5 [报告]
发表于 2011-08-05 09:51 |只看该作者
回复  lengyuex

请问您可是友善论坛里的版主?
embeddedlwp 发表于 2011-08-04 22:40



    没听过这论坛,也没当过版主,哈哈。

论坛徽章:
0
6 [报告]
发表于 2011-08-05 12:05 |只看该作者
cat /proc/bus/input/devices
里面可以看到
input子系统里面会将handler和device绑定

  1. 144 /*
  2. 145  * Event types
  3. 146  */                                       
  4. 147
  5. 148 #define EV_SYN          0x00
  6. 149 #define EV_KEY          0x01
  7. 150 #define EV_REL          0x02                                               
  8. 151 #define EV_ABS          0x03                                                   
  9. 152 #define EV_MSC          0x04
  10. 153 #define EV_SW           0x05
  11. 154 #define EV_LED          0x11
  12. 155 #define EV_SND          0x12
  13. 156 #define EV_REP          0x14
  14. 157 #define EV_FF           0x15
  15. 158 #define EV_PWR          0x16
  16. 159 #define EV_FF_STATUS        0x17
  17. 160 #define EV_MAX          0x1f
  18. 161 #define EV_CNT          (EV_MAX+1)
  19. 162
  20. 163 /*
  21. 164  * Synchronization events.
  22. 165  */
  23. 166
  24. 167 #define SYN_REPORT      0
  25. 168 #define SYN_CONFIG      1
  26. 169 #define SYN_MT_REPORT       2
  27. 170 #define SYN_DROPPED     3

复制代码
一般是

  1. 330 /**
  2. 331  * input_event() - report new input event
  3. 332  * @dev: device that generated the event
  4. 333  * @type: type of the event
  5. 334  * @code: event code
  6. 335  * @value: value of the event
  7. 336  *
  8. 337  * This function should be used by drivers implementing various input
  9. 338  * devices to report input events. See also input_inject_event().
  10. 339  *
  11. 340  * NOTE: input_event() may be safely used right after input device was
  12. 341  * allocated with input_allocate_device(), even before it is registered
  13. 342  * with input_register_device(), but the event will not reach any of the   
  14. 343  * input handlers. Such early invocation of input_event() may be used         
  15. 344  * to 'seed' initial state of a switch or initial position of absolute
  16. 345  * axis, etc.
  17. 346  */
  18. 347 void input_event(struct input_dev *dev,
  19. 348          unsigned int type, unsigned int code, int value)
  20. 349 {
  21. 350     unsigned long flags;
  22. 351
  23. 352     if (is_event_supported(type, dev->evbit, EV_MAX)) {
  24. 353
  25. 354         spin_lock_irqsave(&dev->event_lock, flags);
  26. 355         add_input_randomness(type, code, value);
  27. 356         input_handle_event(dev, type, code, value);
  28. 357         spin_unlock_irqrestore(&dev->event_lock, flags);
  29. 358     }
  30. 359 }

复制代码
这么玩的




详情参考

  1. 1165 static int __init input_proc_init(void)                                                                                            
  2. 1166 {                                                                                                                                 
  3. 1167     struct proc_dir_entry *entry;                                                                                                  
  4. 1168                                                                                                                                    
  5. 1169     proc_bus_input_dir = proc_mkdir("bus/input", NULL);                                                                           
  6. 1170     if (!proc_bus_input_dir)                                                                                                      
  7. 1171         return -ENOMEM;                                                                                                            
  8. 1172                                                                                                                                    
  9. 1173     entry = proc_create("devices", 0, proc_bus_input_dir,                                                                          
  10. 1174                 &input_devices_fileops);                                                                                          
  11. 1175     if (!entry)                                                                                                                    
  12. 1176         goto fail1;                                                                                                               
  13. 1177                                                                                                                                    
  14. 1178     entry = proc_create("handlers", 0, proc_bus_input_dir,                                                                        
  15. 1179                 &input_handlers_fileops);                                                                                          
  16. 1180     if (!entry)                                                                                                                    
  17. 1181         goto fail2;                                                                                                               
  18. 1182                                                                                                                                    
  19. 1183     return 0;
  20. 1184
  21. 1185  fail2: remove_proc_entry("devices", proc_bus_input_dir);
  22. 1186  fail1: remove_proc_entry("bus/input", NULL);
  23. 1187     return -ENOMEM;
  24. 1188 }



  25. 2139 static int __init input_init(void)
  26. 2140 {   
  27. 2141     int err;                                                                                                                       
  28. 2142                                                                                                                                    
  29. 2143     err = class_register(&input_class);                                                                                            
  30. 2144     if (err) {                                                                                                                     
  31. 2145         pr_err("unable to register input_dev class\n");                                                                           
  32. 2146         return err;                                                                                                               
  33. 2147     }
  34. 2148     
  35. 2149     err = input_proc_init();                                                                                                      
  36. 2150     if (err)                                                                                                                       
  37. 2151         goto fail1;
  38. 2152                 
  39. 2153     err = register_chrdev(INPUT_MAJOR, "input", &input_fops);                                                                     
  40. 2154     if (err) {
  41. 2155         pr_err("unable to register char major %d", INPUT_MAJOR);                                                                  
  42. 2156         goto fail2;
  43. 2157     }           
  44. 2158     
  45. 2159     return 0;
  46. 2160                                                                                                                                    
  47. 2161  fail2: input_proc_exit();
  48. 2162  fail1: class_unregister(&input_class);
  49. 2163     return err;
  50. 2164 }



复制代码

评分

参与人数 1可用积分 +6 收起 理由
Godbach + 6 感谢分享

查看全部评分

论坛徽章:
16
2015亚冠之吉达阿赫利
日期:2015-08-17 11:21:462015年迎新春徽章
日期:2015-03-04 09:58:11酉鸡
日期:2014-12-07 09:06:19水瓶座
日期:2014-11-04 14:23:29天秤座
日期:2014-03-02 08:57:52双鱼座
日期:2014-02-22 13:07:56午马
日期:2014-02-14 11:08:18双鱼座
日期:2014-02-13 11:09:37卯兔
日期:2014-02-06 15:10:34子鼠
日期:2014-01-20 14:48:19戌狗
日期:2013-12-19 09:37:46射手座
日期:2013-12-19 09:33:47
7 [报告]
发表于 2011-08-05 17:34 |只看该作者
回复 6# 1jjk


    这也只是说明,是Event types中的就可以阿,如果有触摸屏,鼠标等各种设备,如何区分是谁的事件阿

论坛徽章:
0
8 [报告]
发表于 2011-08-05 17:50 |只看该作者

  1. I: Bus=0019 Vendor=0000 Product=0005 Version=0000
  2. N: Name="Lid Switch"
  3. P: Phys=PNP0C0D/button/input0
  4. S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0
  5. U: Uniq=
  6. H: Handlers=event0
  7. B: EV=21
  8. B: SW=1

  9. I: Bus=0019 Vendor=0000 Product=0001 Version=0000
  10. N: Name="Power Button"
  11. P: Phys=PNP0C0C/button/input0
  12. S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input1
  13. U: Uniq=
  14. H: Handlers=kbd event1
  15. B: EV=3
  16. B: KEY=10000000000000 0

  17. I: Bus=0019 Vendor=0000 Product=0003 Version=0000
  18. N: Name="Sleep Button"
  19. P: Phys=PNP0C0E/button/input0
  20. S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0E:00/input/input2
  21. U: Uniq=
  22. H: Handlers=kbd event2
  23. B: EV=3
  24. B: KEY=4000 0 0

  25. I: Bus=0019 Vendor=0000 Product=0001 Version=0000
  26. N: Name="Power Button"
  27. P: Phys=LNXPWRBN/button/input0
  28. S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3
  29. U: Uniq=
  30. H: Handlers=kbd event3
  31. B: EV=3
  32. B: KEY=10000000000000 0

  33. I: Bus=0017 Vendor=0001 Product=0001 Version=0100
  34. N: Name="Macintosh mouse button emulation"
  35. P: Phys=
  36. S: Sysfs=/devices/virtual/input/input4
  37. U: Uniq=
  38. H: Handlers=mouse0 event4
  39. B: EV=7
  40. B: KEY=70000 0 0 0 0
  41. B: REL=3

  42. I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
  43. N: Name="AT Translated Set 2 keyboard"
  44. P: Phys=isa0060/serio0/input0
  45. S: Sysfs=/devices/platform/i8042/serio0/input/input5
  46. U: Uniq=
  47. H: Handlers=kbd event5
  48. B: EV=120013
  49. B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
  50. B: MSC=10
  51. B: LED=7

  52. I: Bus=0011 Vendor=0002 Product=0007 Version=01b1
  53. N: Name="SynPS/2 Synaptics TouchPad"
  54. P: Phys=isa0060/serio4/input0
  55. S: Sysfs=/devices/platform/i8042/serio4/input/input6
  56. U: Uniq=
  57. H: Handlers=mouse1 event6
  58. B: EV=b
  59. B: KEY=420 70000 0 0 0 0
  60. B: ABS=11000003

  61. I: Bus=0019 Vendor=0000 Product=0006 Version=0000
  62. N: Name="Video Bus"
  63. P: Phys=LNXVIDEO/video/input0
  64. S: Sysfs=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/LNXVIDEO:00/input/input7
  65. U: Uniq=
  66. H: Handlers=kbd event7
  67. B: EV=3
  68. B: KEY=3f000b00000000 0 0 0

  69. I: Bus=0011 Vendor=0002 Product=000a Version=0000
  70. N: Name="TPPS/2 IBM TrackPoint"
  71. P: Phys=synaptics-pt/serio0/input0
  72. S: Sysfs=/devices/platform/i8042/serio4/serio5/input/input8
  73. U: Uniq=
  74. H: Handlers=mouse2 event8
  75. B: EV=7
  76. B: KEY=70000 0 0 0 0
  77. B: REL=3

  78. I: Bus=0003 Vendor=17ef Product=481d Version=0221
  79. N: Name="Integrated Camera"
  80. P: Phys=usb-0000:00:1d.7-6/button
  81. S: Sysfs=/devices/pci0000:00/0000:00:1d.7/usb2/2-6/2-6:1.0/input/input9
  82. U: Uniq=
  83. H: Handlers=kbd event9
  84. B: EV=3
  85. B: KEY=100000 0 0 0

  86. [root@btg lk]#

复制代码
这个就是你写driver的时候的事了
以上的这个足够说明问题了吧

论坛徽章:
0
9 [报告]
发表于 2011-08-05 17:54 |只看该作者

  1. 1474 static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
  2. 1475 {
  3. 1476     input_event(dev, EV_KEY, code, !!value);
  4. 1477 }
  5. 1478
  6. 1479 static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value)
  7. 1480 {
  8. 1481     input_event(dev, EV_REL, code, value);
  9. 1482 }
  10. 1483
  11. 1484 static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
  12. 1485 {
  13. 1486     input_event(dev, EV_ABS, code, value);
  14. 1487 }
  15. 1488
  16. 1489 static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value)
  17. 1490 {
  18. 1491     input_event(dev, EV_FF_STATUS, code, value);
  19. 1492 }
  20. 1493
  21. 1494 static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value)
  22. 1495 {
  23. 1496     input_event(dev, EV_SW, code, !!value);
  24. 1497 }

复制代码
关于report的类型,已经封装的现成的接口了
其实最后都是用的input_event来报的

只要看input_event来看就可以了
比如touch一般是EV_ABS
按键一般是EV_KEY,
鼠标看了一下,貌似是EV_REL

论坛徽章:
0
10 [报告]
发表于 2011-08-05 18:02 |只看该作者
再补充一帖

Documentation/input/input-programming.txt

这个里面也有说明,是上报的rel,就是mouse了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP