Using the sensor class extension to raise events

Sensor applications can retrieve the current sensor data by either registering to receive event notifications from the driver or by invoking the ISensor::GetData method to retrieve the sensor’s current data field. The sample driver supports both. If an application registers for data-update events, the driver raises these events every time that data arrives from the sensor. The frequency of these event notifications corresponds to the current report-interval property.

In addition to raising events when new data arrives from the sensor, the sample driver also raises events when the sensor cannot send data or when the sensor is ready to start to send data. These events are known as state-change events.

The states supported by the sample driver correspond to two constants found in the SensorState enumeration:

Event-State ConstantSignificance
SENSOR_STATE_NO_DATA Indicates that the sensor is not available.
SENSOR_STATE_READY Indicates that the sensor is connected and ready to send data.

 

The sensor class extension handles the event linkage between a sensor driver and the Sensor API. When the driver invokes the ISensorClassExtension::PostStateChange method, the class extension forwards the notification to the API. The sample driver invokes this method within CSensorManager::SetState. When the driver invokes the ISensorClassExtension::PostEvent method and supplies the property key for the data-updated event, the class extension forwards the notification to the Sensor API. The sample driver invokes this method within CSensorManager::PostDataEvent.

The two sensor manager methods, ::SetState and ::PostDataEvent, are invoked within the sample driver’s thread procedure for events CSensorManager::_SensorEventThreadProc. The event handlers are maintained in a separate thread procedure to prevent the event activity from blocking synchronous procedures in the driver, such as callback functions.

Note the following sequence for handling a data event, the driver should:

  1. Set the sensor state to SENSOR_STATE_READY.
  2. Fire a state-change event.
  3. Fire the data event.

Related topics

The Sensor Diagnostic Tool
The Sensors HID Driver Sample
Writing a Sensor Device Driver

 

 

Send comments about this topic to Microsoft

Build date: 11/29/2012

Show: