IOHIDFamily: Difference between revisions

From iPhone Development Wiki
(Created page with ''''IOHIDFamily''' is a kernel extension that provides an abstract interface of with human interface devices (HID), e.g. the touchscreen, buttons, accelerometer, etc. In the user-…')
 
Line 8: Line 8:
Displays are, obviously, the LCD screen. The <tt>IOHIDDisplay</tt> class can only control the brightness, ''not'' colors of individual pixels (Drawing is controlled by the VRAM). You only can control the displays indirectly by changing properties of the event system.
Displays are, obviously, the LCD screen. The <tt>IOHIDDisplay</tt> class can only control the brightness, ''not'' colors of individual pixels (Drawing is controlled by the VRAM). You only can control the displays indirectly by changing properties of the event system.


IOHID defines 20 types of events, of which the {{applink|SpringBoard}} only handles 4 of them: button, digitizer (i.e. touchscreen), accelerometer and proximity events (temperature events are handled by IOKit directly). Each event may contain sub-events.
IOHID defines 20 types of events, of which the {{applink|SpringBoard}} only handles 4 of them: keyboard (for buttons), digitizer (i.e. touchscreen), accelerometer and proximity events (temperature events are handled by IOKit directly). Each event may contain sub-events.


== Example ==
== Example ==

Revision as of 21:18, 1 January 2010

IOHIDFamily is a kernel extension that provides an abstract interface of with human interface devices (HID), e.g. the touchscreen, buttons, accelerometer, etc. In the user-land, there are 2 kinds of APIs associated to the IOHIDFamily: (1) the "public" ones, which are intended for HID driver writers; (2) the "private" ones, which are intended for event processing. This document will only outline the private APIs. References to the public one can be found in [1].

Class structure

Users of IOHID always first create an IOHIDEventSystem object that interfaces with the whole HID system. An event system consists of multiple IOHIDServices and IOHIDDisplays.

Services are various interfaces to the IOHIDLibPlugin kernel plugin (located at /System/Library/Extensions/IOHIDFamily.kext/PlugIns/IOHIDLib.plugin/IOHIDLib). They accept direct human input, and are the sources of all IOHIDEvents.

Displays are, obviously, the LCD screen. The IOHIDDisplay class can only control the brightness, not colors of individual pixels (Drawing is controlled by the VRAM). You only can control the displays indirectly by changing properties of the event system.

IOHID defines 20 types of events, of which the SpringBoard only handles 4 of them: keyboard (for buttons), digitizer (i.e. touchscreen), accelerometer and proximity events (temperature events are handled by IOKit directly). Each event may contain sub-events.

Example

#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
  // handle the events here.
  printf("Received event of type %2d from service %p.\n", IOHIDEventGetType(event), service);
}

int main () {
  // Create and open an event system.
  IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
  IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);

  printf("HID Event system should now be running. Hit enter to quit any time.\n");
  getchar();

  IOHIDEventSystemClose(system, NULL);
  CFRelease(system);
  return 0;
}

Services

To access the services, you have to first match them using IOHIDEventSystemCopyMatchingServices. These criteria can be obtained using ioreg -l.

Service Name match CFBundleIdentifier PrimaryUsagePage PrimaryUsage
AppleLIS302DL (Accelerometer) accelerometer,lis302dl com.apple.driver.AppleEmbeddedAccelerometer 0xff00 3
AppleISL29003 (ALS) als,isl29003 com.apple.driver.AppleEmbeddedLightSensor 0xff00 4
AppleM68Buttons (Buttons) buttons com.apple.driver.AppleM68Buttons 11 1
AppleMultitouchZ2SPI (Touchscreen) multi-touch,z2 com.apple.driver.AppleMultitouchSPI - -

References