Linux Input Subsystem __linux

Source: Internet
Author: User
Tags unique id
Linux Input Subsystem Event interface detailed: Get Input device Information(2013-06-06-15:24:27)
In the previous work, we often encountered the requirements of the event device operation and setup in the input subsystem. But has not been summed up. The opportunity to sum up.

In the Linux input subsystem, each input device can create a device. For example, when inserting a USB mouse,usb keyboard, or using Uinput to establish input device. The corresponding device is generated in the system/dev/input/directory. such as:/dev/input/event0,/DEV/INPUT/MOUSE0,/dev/input/misc and so on.

You can read these device to get information about input device input. At the same time, it is possible to obtain and set (mainly obtain) information about these device through a series of IOCTL (). Here, we mainly analyze the IOCTL () of this event Interface.

0. Basic information: 0.1: Key structure body input_event information:struct Input_event {struct timeval time; __u16 type; __u16 code; __s32 value;};
Type : Device type. Can be set to: #define Ev_syn          0x00     indicates that the device supports all events #define EV_ Key          0x01     keyboard or key, indicating a key code   #define EV_ REL          0x02     Mouse device, indicating a relative cursor position result #define Ev_abs          0x03     Handwriting Pad produces a value that is an absolute integer value   #define Ev_ MSC          0x04     Other types   #define EV_LED           0X11    led Lamp Equipment #define EV_SND           0x12     Buzzer, input voice   #define EV_REP           0x14     allow repeat key type   #define EV_PWR           0x16     Power Management event   #define EV_FF_STATUS 0x17 #defineEv_max 0x1f #define EV_CNT (ev_max+1)
code: The meaning is different depending on the type. For example, when type is Ev_key, code represents the keyboard code or the mouse button value. Value range: #define Ev_syn 0x00 to: #define key_min_interesting key_mute #define KEY_MAX 0x2ff #define KEY_CNT (key_max+1)

When type is Ev_rel, the code represents which axis the operation is, such as: Rel_x,rel_y. (Because the mouse has x,y two axes, so one mouse movement, will produce two input_event) value range: #define REL_X 0x00 #define REL_Y 0x01 #define REL_Z 0x02 #define REL_RX 0x0 3 #define REL_RY 0x04 #define REL_RZ 0x05 #define Rel_hwheel 0x06 #define Rel_dial 0x07 #define REL_WHEEL 0x08 #define REL _misc 0x09 #define REL_MAX 0x0f #define REL_CNT (rel_max+1) type is Ev_abs, the code represents an absolute axis to.

value: The meaning is different depending on the type. For example: When type is Ev_key, value:0 indicates that the key is raised. 1 means press the key. (4 means to keep pressing the inferior.) )。 When type is Ev_rel, value: Indicates the value and direction of the move (positive and negative). When type is Ev_abs, the code represents an absolute position.

0.2:device ID structure body information:struct INPUT_ID {__u16 bustype; __u16 vendor; __u16 product; __u16 version;};
BusType: Some enumeration types. such as USB, PCI and so on. Value range: #define BUS_PCI 0x01 #define BUS_ISAPNP 0x02 #define BUS_USB 0x03 #define Bus_hil 0x04 #define Bus_bluetooth 0x05 #d Efine bus_virtual 0x06
#define BUS_ISA 0x10 #define BUS_I8042 0x11 #define BUS_XTKBD 0x12 #define BUS_RS232 0x13 #define Bus_gameport 0x14 #defin E bus_parport 0x15 #define BUS_AMIGA 0x16 #define BUS_ADB 0x17 #define BUS_I2C 0x18 #define BUS_HOST 0x19 #define BUS_GSC 0x1A #define Bus_atari 0x1b #define BUS_SPI 0x1c
Vendor, product,version: Factory firm, product number, version number.


1. Various IOCTL: 1.1: Get driver Version:#define Eviocgversion _ior (' E ', 0x01, int) int implies that the IOCTL () parameter three can get an int value.
Example: vesion = 0; IOCTL (FD, eviocgversion, &vesion); printf ("\ndriver version:[0x%x]\n", vesion);

1.2: Get device ID:#define Eviocgid _ior (' E ', 0x02, struct input_id) The struct input_id implies that the IOCTL parameter three can obtain this structure body content. 2. Device ID. memset (&device_id, 0, sizeof (struct input_id)); IOCTL (FD, Eviocgid, &device_id); printf ("\nbustype:[%d]." VENDOR:[%D]. PRODUCT:[%D]. Version:[%d]\n ", Device_id.bustype, Device_id.vendor, Device_id.product, device_id.version);

1.3: Get and set repeat speed:#define EVIOCGREP _ior (' e ', 0x03, unsigned int[2]) #define EVIOCSREP _iow (' e ', 0x03, unsigned int[2]) implied from unsigned int[2], The third parameter of IOCTL is the array of numbers.
int rep[2]; IOCTL (FD, EVIOCGREP, Rep); printf ("[0]=%d, [1] =%d\n", rep[0], rep[1]);
Note that some of these device do not support get Set Repeat. At this point, IOCTL will complain. Another: Parameter description: Rep[0] represents the delay time before the keystroke repeats, Rep[1] represents the time interval at which the key repeats itself.

1.4: Get Scankey and Keymap. This feature Sam has not been tested. So not specifically discussed. #define Eviocgkeycode _ior (' e ', 0x04, unsigned int[2]) #define Eviocskeycode _iow (' e ', 0x04, unsigned int[2])

1.5: Get devicename:#define Eviocgname (len)_IOC (_ioc_read, ' E ', 0x06, Len) implies the IOCTL parameter two: Eviocgname (len)
Char name[256]= "Unknown"; IOCTL (FD, Eviocgname (sizeof (name)), name); printf ("\ndevice name:[%s]." \ n ", name);

1.6: Get the device physical location:#define Eviocgphys (len) _ioc (_ioc_read, ' E ', 0x07, Len)//get physical location This implies that parameter two is: Eviocgphys (len)Although device identity information and name information are often useful, it may not provide enough information to tell you which device is currently in use. For example, you currently have two identical remote control rods, and you need to determine which port to use. This usually belongs to the topology information (topology information) and can be obtained using Eviocgphys IOCTL:
Char physic[256]= "Unknown"; if (IOCTL (FD, Eviocgphys (sizeof (physic)), physic) < 0) {perror ("Eviocgphys ioctl"); else printf ("Phys location is%s \ n ", physic); The result is usually: Phys location is: USB-HIUSB-EHCI-2.1/INPUT1Phys location is: Usb-hiusb-ehci-2.1/input2Meaning: The USB part means that this uses a physical topology of the USB system.  2.1 represents the path from the root hub to the device, where the uplink hub is connected to the 2nd port of the root hub, and the device is connected to the 1th port of the uplink hub. Input0 says this is the 1th event device node for the device.

1.7: Get the unique ID:#define EVIOCGUNIQ (len) _ioc (_ioc_read, ' E ', 0x08, Len)//get unique identifier here imply IOCTL () parameter two: Eviocguniq (len)
Char uniq[256]= "Unknown"; if (FD, Eviocguniq (sizeof (UNIQ), Uniq) < 0) {perror ("Eviocguniq ioctl"); else printf ("UID is%s\n", uniq); most devices do not have such a unique number, so you use the IOCTL to return an empty string

1.8: Get the global Key/button state to see if it is pressed or released:#define EVIOCGKEY (len) _ioc (_ioc_read, ' E ', 0x18, Len) implies that the IOCTL () parameter two is: Eviocgkey (len)With this IOCTL, the information is obtained from the parameter three. It sets whether each Key/button is released in the bit array.

1.9: Get LED Status:#define EVIOCGLED (len) _ioc (_ioc_read, ' E ', 0x19, Len)
The LEDs are arranged as follows: #define LED_NUML 0x00 #define LED_CAPSL 0x01 #define LED_SCROLLL 0x02 #define LED_COMPOSE 0x03 #define Led_kana 0 X04 #define LED_SLEEP 0x05 #define Led_suspend 0x06 #define Led_mute 0x07 #define LED_MISC 0x08 #define Led_mail 0x09 #def INE led_charging 0x0a #define LED_MAX 0x0f #define LED_CNT (led_max+1)


1.10: Get device Ability Set:

The ability and characteristics of the device can be obtained using eviocgbit IOCTL. It tells you if the device has a key or a button.

Eviocgbit IOCTL handles 4 parameters (IOCTL (FD, Eviocgbit (Ev_type, max_bytes), Bitfield)). Ev_type is the returned type feature (0 is a special case that returns all of the type features supported by the device). Max_bytes represents the maximum number of bytes returned. The Bitfield field is a memory pointer to the saved result. return value represents the actual number of bytes of the saved result, and a negative value if the call fails.


Find the corresponding bit in the addr. See if it is 1.

static int test_bit (int nr, const volatile unsigned long *addr)

{

Return 1UL & (Addr[bit_word (NR)] >> (NR & (Bits_per_long-1));

}



memset (pevtype, 0, sizeof (pevtype));

if (IOCTL (FD, eviocgbit (0, Ev_max), Pevtype) < 0)

{

printf ();

}

for (Yalv = 0; Yalv < Ev_max; yalv++)

{

if (Test_bit (Yalv, Pevtype))

{

printf ("Event type 0xx", YALV);

Switch (YALV)

{

Case Ev_syn:

printf ("(Synch Events) \ n");

Break

Case Ev_key:

printf ("(Keys or Buttons) \ n");

Break

Case Ev_rel:

printf ("(relative Axes) \ n");

Break

Case Ev_abs:

printf ("(absolute Axes) \ n");

Break

Case EV_MSC:

printf ("(Miscellaneous) \ n");

Break

Case ev_led:

printf ("(LEDs) \ n");

Break

Case EV_SND:

printf ("(Sounds) \ n");

Break

Case EV_REP:

printf ("(Repeat) \ n");

Break

Case EV_FF:

Case Ev_ff_status:

printf ("(Force Feedback) \ n");

Break

Case EV_PWR:

printf ("(Power Management) \ n");

Break

Default

printf ("(UNKNOWN:0XHX) \ n", Yalv);

}

}

}



Through this approach, you can get to the ability set. Example: Event type 0x00 (Synch Events) event Type 0x01 (Keys or Buttons) event type 0x02 (relative Axes) </

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.