Changes between Initial Version and Version 1 of epics/powermate-event


Ignore:
Timestamp:
06/19/12 22:54:32 (13 years ago)
Author:
Takashi Obina
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • epics/powermate-event

    v1 v1  
     1= /dev/inputについて =
     2
     3Linuxではキーボード・マウス等のデバイスを/dev/input以下にある デバイスファイル経由で操作することができます。 まずは利用可能なデバイスの一覧を表示するには
     4
     5{{{
     6~% cat /proc/bus/input/devices
     7
     8I: Bus=0011 Vendor=0001 Product=0001 Version=ab54
     9N: Name="AT Translated Set 2 keyboard"
     10P: Phys=isa0060/serio0/input0
     11H: Handlers=kbd event0
     12B: EV=120013
     13B: KEY=4 2000000 3802078 f840d001 f2ffffdf ffefffff ffffffff fffffffe
     14B: MSC=10
     15B: LED=7
     16
     17I: Bus=0011 Vendor=0002 Product=0001 Version=0000
     18N: Name="PS/2 Generic Mouse"
     19P: Phys=isa0060/serio4/input0
     20H: Handlers=mouse0 event1
     21B: EV=7
     22B: KEY=70000 0 0 0 0 0 0 0 0
     23B: REL=3
     24
     25I: Bus=0003 Vendor=054c Product=0270 Version=0110
     26N: Name="SONY SONY Mouse"
     27P: Phys=usb-0000:00:1d.0-1/input0
     28H: Handlers=mouse1 event2
     29B: EV=f
     30B: KEY=70000 0 0 0 0 0 0 0 0
     31B: REL=103
     32B: ABS=100 0
     33}}}
     34
     35これをみると、
     36{{{
     37event0  : キーボード
     38event1  : PS/2 マウス....これはノートPCのタッチパッドのこと
     39event2  : 外付けUSBマウス(Sony製)
     40}}}
     41の3つのデバイスが接続されていて、それぞれのイベントを取得 できることが分かります。 rootになってから
     42{{{
     43# cat /dev/input/event1 | od -t x1
     44}}}
     45とやってやり、イベントコードを取得してみます。
     46この状態でマウスパッドをたたくと
     47{{{
     480000000 cc 80 c7 44 84 81 05 00 01 00 10 01 01 00 00 00
     490000020 cc 80 c7 44 8c 81 05 00 00 00 00 00 00 00 00 00
     500000040 cc 80 c7 44 ed f6 07 00 01 00 10 01 00 00 00 00
     510000060 cc 80 c7 44 f4 f6 07 00 00 00 00 00 00 00 00 00
     52}}}
     53
     54マウスを動かすと
     55{{{
     560000000 11 81 c7 44 4f 5e 04 00 02 00 01 00 01 00 00 00
     570000020 11 81 c7 44 59 5e 04 00 00 00 00 00 00 00 00 00
     580000040 11 81 c7 44 96 10 08 00 02 00 01 00 01 00 00 00
     590000060 11 81 c7 44 a2 10 08 00 00 00 00 00 00 00 00 00
     60}}}
     61等と表示されます。
     62イベントコードは /usr/src/kernels/2.6.9-34.0.2.EL-i686/include/linux/input.h で定義されており、
     63{{{
     64struct input_event {
     65        struct timeval time;
     66        __u16 type;
     67        __u16 code;
     68        __s32 value;
     69};
     70}}}
     71の形になっているので、先ほどのデータは
     72{{{
     730000000 11 81 c7 44 4f 5e 04 00 02 00 01 00 01 00 00 00
     740000020 11 81 c7 44 59 5e 04 00 00 00 00 00 00 00 00 00
     75        ======================= ===== ===== ===========
     76                  time          type  code     value
     77}}}
     78となっていることが分かる。当然ですがLittle Endianですね。
     79
     80
     81おまけ:
     82{{{
     83int main (int argc, char *argv[])
     84{
     85  printf("sizeT : %d\n", sizeof(struct timeval));
     86  printf("u16   : %d\n", sizeof(__u16));
     87  printf("u32   : %d\n", sizeof(__s32));
     88  return 0;
     89}
     90}}}
     91
     92
     93input.hファイルにtype,codeについて書いてあり、
     94{{{
     95/*
     96 * Event types
     97 */
     98
     99#define EV_SYN                  0x00
     100#define EV_KEY                  0x01
     101#define EV_REL                  0x02
     102}}}
     103となっているので、キーボード入力はEV_KEY, マウスはEV_RELというタイプ。
     104さて、次にPowerMateを挿してみましょう。
     105{{{
     106~% cat /proc/bus/input/devices
     107I: Bus=0003 Vendor=077d Product=0410 Version=0321
     108N: Name="Griffin PowerMate"
     109P: Phys=
     110H: Handlers=event3
     111B: EV=17
     112B: KEY=1 0 0 0 0 0 0 0 0
     113B: REL=80
     114B: MSC=2
     115}}}
     116
     117event3を監視します。
     118{{{
     119[root@obinalx obina]#  cat /dev/input/event3 | od -t x1
     120右回し
     1210000000 1d 8c c7 44 dd 5b 09 00 02 00 07 00 01 00 00 00
     1220000020 1d 8c c7 44 df 5b 09 00 00 00 00 00 00 00 00 00
     123左回し
     1240000040 1f 8c c7 44 71 4d 06 00 02 00 07 00 ff ff ff ff
     1250000060 1f 8c c7 44 73 4d 06 00 00 00 00 00 00 00 00 00
     126ボタン Press
     1270000100 21 8c c7 44 f8 33 0a 00 01 00 00 01 01 00 00 00
     1280000120 21 8c c7 44 fa 33 0a 00 00 00 00 00 00 00 00 00
     129ボタン Release
     1300000140 23 8c c7 44 ed d4 09 00 01 00 00 01 00 00 00 00
     1310000160 23 8c c7 44 f0 d4 09 00 00 00 00 00 00 00 00 00
     132}}}
     133
     134type,code,valueのところだけ16進表記にすると
     135{{{
     136type=0x0002, code=0x0007, value=1
     137type=0x0000, code=0x0000, value=0
     138type=0x0002, code=0x0007, value=-1
     139type=0x0000, code=0x0000, value=0
     140type=0x0001, code=0x0100, value=1
     141type=0x0000, code=0x0000, value=0
     142type=0x0001, code=0x0100, value=0
     143type=0x0000, code=0x0000, value=0
     144}}}
     145
     146type,code,value全て0が返ってきている行はEV_SYNなので、今は気にしないことにする。
     147{{{
     148右回し          :       type=2, code=7, value=1
     149左回し          :       type=2, code=7, value=-1
     150ボタン Press    :       type=1, code=256, value=1
     151ボタン Release  ;       type=1, code=256, value=0
     152}}}
     153
     154(前述の通り、type=2はEV_REL, type=1はEV_KEY)
     155
     156codeは
     157{{{
     158EV_REL に対しては
     159  #define REL_DIAL                0x07
     160EV_KEY に対しては
     161  #define BTN_MISC                0x100
     162}}}
     163
     164PowerMateを操作したときのイベントはEV_RELとEV_KEYのみ。 どうやら プログラム側からLED設定を変える場合にはEV_MSCが発生するらしいので、これは後で 確認したい。