Export (0) Print
Expand All

Filtering data

In order to optimize data throughput, your sensor device must apply filter criteria to the data-update events so that they are only raised when needed. This filtering results in lower CPU utilization (due to reduced sensor throughput) and less power consumption (both for the sensor and the CPU).

There are two values (or properties) that support a sensor device’s filter criteria. The first is the current report interval (CRI) and the second is the change sensitivity (CS). Both of these properties can be set by a sensor application.

The current report interval is the minimum period, in milliseconds, between data updates which a client wishes to receive when meaningful change has occurred. The change sensitivity is the value (or percentage) used to specify meaningful change.

So, a weather-station application may specify a current report interval (CRI) for a temperature sensor of 60,000 (or one minute). And, the temperature sensor would require a change-sensitivity value (as opposed to a percentage). For example, if this temperature sensor returns degrees Celsius and the change sensitivity value temperature was 2.0, this particular sensor would only raise the data-updated event when the temperature increased, or decreased, by 2.0 degrees Celsius over the requested report interval (in this case, one minute).

An ambient light sensor (ALS) is an example of a sensor that would require change-sensitivity to be specified as a percentage. For example, if the change sensitivity value for Illuminance was 2.0, this sensor would interpret the value as a percentage and only raise the data-updated event when the LUX value had either dropped or increased by 2%.

The following table lists six common sensors, the data associated with each, and the corresponding change sensitivity.

SensorDatafieldChange Sensitivity Value
Light SensorLUX% change in lux
AccelerometerAcceleration XAcceleration G-force
Acceleration YAcceleration G-force
Acceleration ZAcceleration G-force
3D GyrometerAngular Speed XAngular Speed (degrees per second)
Angular Speed YAngular Speed (degrees per second)
Angular Speed ZAngular Speed (degrees per second)
CompassMagnetic North HeadingDegrees
True North HeadingDegrees
InclinometerYawDegrees
PitchDegrees
RollDegrees
Device OrientationQuaternionDegrees Movement
Rotation MatrixDegrees Movement

 

The following table lists the recommended Current Report Interval (CRI) defaults. In addition, it lists the defaults supported by the sensors HID class driver, the Sensor Service, the Windows runtime, and the ACPI for Ambient Light Sensors (ALS). These values are listed in milliseconds.

Sensor TypeWindows Driver Kit (recommended)HID Class DriverSensor Service WinRTACPI ALS
Ambient Light50001001500N/A1000
Accelerometer100100125N/AN/A
Gyrometer100100N/AN/AN/A
Compass100100N/AN/AN/A
Inclinometer5050N/AN/AN/A
Orientation5050N/AN/AN/A

 

The following table lists the recommended Change Sensitivity (CS) defaults. In addition, it lists the defaults supported by the sensors HID class driver, the Sensor Service, the Windows runtime, and the ACPI for Ambient Light Sensors (ALS).

Sensor TypeWindows Driver Kit (recommended)HID Class DriverSensor ServiceWinRT (at or below this RI)ACPI ALS
16 ms32 msMax RI
Ambient Light501.0025.001.001.005.0010.00
Accelerometer0.020.020.020.010.020.05N/A
Gyrometer0.500.50N/A0.100.501.00N/A
Compass0.200.20N/A0.010.502.00N/A
Inclinometer0.500.50N/A0.010.502.00N/A
Orientation0.500.20N/A0.010.502.00N/A

 

Change Sensitivity (CS) for the Inclinometer and Orientation Sensors

Change sensitivity for the inclinometer and orientation sensor should be calculated as the angle between two quaternions. Mathematically, this expressed as:

2*cos-1(dot product(q1, q2))

This calculation ensures consistency across various tablet (or device) orientations.

Effective Current Report Interval (CRI) and Change Sensitivity (CS)

Multiple applications can set both the Current Report Interval (CRI) and the Change Sensitivity (CS) properties for a given sensor. It is the responsibility of your driver to determine which requested property applies. The properties set by the driver are referred to as the Effective Current Report-Interval (E-CRI) and the Effective Change-Sensitivity (E-CS).

Setting the E-CRI and E-CS for Client Applications

Whenever a client application establishes a connection to a sensor, your driver needs to set the E-CRI and E-CS values. These values are stored in what’s referred to as a client container. The following table lists six methods supported by a sensor driver and specifies what your driver should do with its client container and the E-CRI and E-CS properties.

Event of InterestEvent Handler Activities
ISensorDriver::OnClientConnect

Add client item to client container

Read default CRI and CS values as appropriate, store in client container

ISensorDriver::OnClientDisconnect

Remove client from client container and set the E-CRI and E-CS as appropriate based on the remaining clients

ISensorDriver::OnClientSubscribeToEvents

Update “subscribed to events” field – (set to true) for the sensor in question. Turn on event reporting from the sensor.

ISensorDriver::OnClientUnSubscribeToEvents

Update “subscribed to events” field – (set to false) for the sensor in question. If no subscribers remain, turn off event reporting from the device.

ISensorDriver::OnSetProperties

If CS or CRI properties are set, update appropriate client container fields.

IFileCallbackCleanup::OnCleanupFile

The client has crashed or stopped responding. The client should be removed from the client container.

 

The following table represents the client container for a 3D accelerometer with 4 connected client applications. Two of these client apps (corresponding to the 2nd and 4th row) have subscribed to events.

Client File HandleSubscribed To EventsCRICS (X)CX (Y)CS (Z)
FF80A267 FALSE50.001.001.001
FF802489TRUE70.02.02.02
FF80D345FALSE15NULLNULLNULL
FF803287TRUE100.005.005.005

 

After the driver evaluated this set of connected clients, it chose the following values for E-CRI and E-CS:

  • E-CRI: 70ms
  • E-CS values: (could collapse to single value using smallest threshold)
    • X:.005
    • Y:.005
    • Z: .005

Notice in this example that clients that do not have an event sink set (first and third rows) are disregarded since event filtering does not apply to those clients.

Filtering data update events by evaluating the effective CRI and CS values (E-CRI, E-CS)

Once the current E-CRI and E-CS values have been determined and are updated as sensor connection states change, your sensor device will use these values to filter events that are raised to connected client applications. These values are compared against the difference between the “current” data value(s) and the previous data value(s). If the E-CS values have been exceeded for a time period equal to or greater than the E-CRI, then, and only then, should a data event be raised. The only exception to this is sensor device startup when the default value(s) are applied so that clients can receive the proper notification.

The following illustration demonstrates how time filtering of raw sensor data is evaluated in order to determine when data events should be raised.

Time-filtered sensor data

In the previous illustration, the red data in the lower portion of the diagram represents the raw sensor data. The green line represents data that would be returned to clients that poll for data (one of many ways to implement this behavior) and the “X” values represent when data events are fired. Blue lines are the thresholds for the E-CS boundaries (+/- E-CS relative to last data event value).

By implementing this event filtering logic, the number of data updated events can be greatly reduced, and applications can still get notified when meaningful changes in sensor data occur.

Device runtime optimizations for data filtering

This section describes several runtime optimizations you should consider as you develop a sensor driver.

Support interrupts

Your driver should rely on interrupts instead of polling the device. This will result in performance and power-management improvements. These improvements include the following.

  1. Your device can enter a lower power state based on the current change sensitivity and report interval.
  2. Using interrupts will reduce unnecessary code execution in both the driver and the sensor firmware.
  3. Using interrupts will reduce bus activity.

Note  If a driver relies on interrupts but the current report interval and change-sensitivity logic exists in the driver, the driver will potentially receive a significant number of interrupts between data updates. As a result, the driver may need to disable (or mask) interrupts until the current-report interval expires.

Move change-sensitivity support to the device

If your sensor hardware, or firmware, supports threshold detection you should use this feature to support change sensitivity. By moving the support to the device, and then responding to the corresponding interrupt, you reduce processing overhead in your driver.

Move report-interval support to the devices

If your sensor hardware, or firmware, supports the notion of a report interval you should use this feature.

If your sensor does not provide native report-interval support, consider disabling interrupts for a subset of the current report interval. Then, once this time ellapses, retrieve the current device data.

Related topics

The Sensors Geolocation Driver Sample

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft