none
C++ COM integration with Orientation Sensor on Windows 10

    Question

  • Hi Everyone!

    Overview:

    We're currently building an app that interfaces with the Windows Sensor API using the SensorManager COM. This is a C++, non-UWP project. Specifically, we're integrating with an aggregated orientation sensor (SENSOR_TYPE_AGGREGATED_DEVICE_ORIENTATION) on a Surface tablet. This works perfectly in Windows 8. We've recently upgraded our machines to Windows 10 and are now experiencing extremely slow reporting intervals from the orientation sensor. One report every ~500-1500ms, regardless of setting the SENSOR_PROPERTY_MIN_REPORT_INTERVAL, etc. Has anyone observed this behavior on Windows 10, or have a reason/solution to this issue? Thanks!

    Details:

    This is a Visual Studio 2015, C++ project using Cinder. Our sensor manager is being initialized as follows:

    hr = ::CoCreateInstance(
        CLSID_SensorManager,
        nullptr,
        CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS( &mSensorManager ) );

    After acquiring a collection of applicable sensors and validating, we persist our sensor, then set the event sink. Code below: 

    STDMETHODIMP OrientationSensor::OnDataUpdated( ISensor *sensor, ISensorDataReport *report )
    {
    	HRESULT hr;
    
    	PROPVARIANT pvQuat;
    	PropVariantInit( &pvQuat );
    	hr = report->GetSensorValue( SENSOR_DATA_TYPE_QUATERNION, &pvQuat );
    	
    	if( SUCCEEDED( hr ) ) {
    
    		if( pvQuat.vt == ( VT_VECTOR | VT_UI1 ) ) {
    			float* pElement = (float*) pvQuat.caub.pElems;
    
    			// SET orientation quaternion
    			mOrientation = ci::quat( pElement[3], pElement[0], pElement[1], pElement[2] );
    		}
    	}
    
    	// CLEAR prop variant
    	PropVariantClear( &pvQuat );
    
    	return hr;
    }

    AddRef(), Release() and QueryInterface() are implemented as defined in all development guides.

    We _do_ receive correct data, simply at slow and long intervals, regardless of settings. We're trying to understand why this is, and why we only see this on Windows 10.

    To confirm that the sensor was nominal, we compiled the UWP Orientation Sample. Indeed, this reported fast and correct readings from the orientation sensor. We're specifically looking for a solution that allows us to interface with the orientation sensor, through the sensor manager COM API.

    Noted, we're using Visual Studio 2015.

    Thanks for all!

    Justin

    Tuesday, August 11, 2015 11:52 PM