Determining which Applications a device uses

Refer to the HID specification for more details on what an application is, and refer to HID Usage Tables, HID Usage Tables for Power Devices, Monitor Class Specification or HID Point of Sale Usage Tables for the valid applications.

You can determine the application (or applications) that the device supports using the HIDIOCAPPLICATION ioctl call.

Lets look at an example of the HIDIOCDEVINFO ioctl call.

NoteAbout this example
 

This example is intentionally a code fragment, and is not complete,nor is it meant to show good programming style.

A complete form of this example (that will compile with gcc -Wall -W) is provided in the second part of this document.

Example 3. HIDIOCDEVINFO example

  ioctl(fd, HIDIOCGDEVINFO, &device_info);

 /* Now that we have the number of applications (in the
  * device_info.num_applications field), 
  * we can retrieve them using the HIDIOCAPPLICATION ioctl()
  * applications are indexed from 0..{num_applications-1}
  */
  for (yalv = 0; yalv < device_info.num_applications; yalv++) {
    appl = ioctl(fd, HIDIOCAPPLICATION, yalv);
    if (appl > 0) {
	printf("Application %i is 0x%x ", yalv, appl);
	/* The magic values come from various usage table specs */
	switch ( appl >> 16)
	    {
	    case 0x01 :
		printf("(Generic Desktop Page)\n");
		break;
	    case 0x0c :
		printf("(Consumer Product Page)\n");
		break;
	    case 0x80 :
		printf("(USB Monitor Page)\n");
		break;
	    case 0x81 :
		printf("(USB Enumerated Values Page)\n");
		break;
	    case 0x82 :
		printf("(VESA Virtual Controls Page)\n");
		break;
	    case 0x83 :
		printf("(Reserved Monitor Page)\n");
		break;
	    case 0x84 :
		printf("(Power Device Page)\n");
		break;
	    case 0x85 :
		printf("(Battery System Page)\n");
		break;
	    case 0x86 :
	    case 0x87 :
		printf("(Reserved Power Device Page)\n");
		break;
	    default :
		printf("(Unknown page - needs to be added)\n");
	    }
    }
  }

This example uses the HIDIOCDEVINFO ioctl that we saw in the previous example, which allows us to determine how many applications the device has. The actual applications are the return value from the ioctl call. To determine all applications, the third argument is iterated from 0 to the total number applications, less one (since it is zero based).