none
Sensor API: Retrieve info from multiple sensors RRS feed

  • Question

  • I am using the Windows Sensor API to get info from various sensors including accelerometer and gyroscope. 

    My initial implementation of sensor driver for accelerometer worked - I asynchronously can get the values for that sensor. 

    But when I try to add another sensor driver for gyroscope, it does not work; only accelerometer info is retrieved. 

    Can you provide an example how to setup the sensor driver for more than two sensor drivers? Right now, I am doing the below twice, for each sensors. 

    HRESULT hr = S_OK;
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    ISensorManager* pSensorManager = NULL;
    ISensorCollection* pSensorColl = NULL;
    ISensor* accelerometer = NULL;

    hr = CoCreateInstance(CLSID_SensorManager,
    NULL, CLSCTX_INPROC_SERVER,
    IID_PPV_ARGS(&pSensorManager));

    if (hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DISABLED_BY_POLICY))
    {
    // Unable to retrieve sensor manager due to 
    // group policy settings. Alert the user.
    printf("Failed getting sensor manager due to disabled policy...\n");

    }

    hr = pSensorManager->GetSensorsByType(SENSOR_TYPE_ACCELEROMETER_3D, &pSensorColl);

                   // do more stuff here....

    Wednesday, January 23, 2019 8:40 PM