4 #if (_MSC_FULL_VER < 180031101) 5 #error At least Visual Studio 2013 Update 4 is required to compile this backend 17 #include <PortableDeviceTypes.h> 19 #include <PortableDevice.h> 21 #include <Sensorsapi.h> 25 #include <propkeydef.h> 29 #pragma comment(lib, "Sensorsapi.lib") 30 #pragma comment(lib, "PortableDeviceGuids.lib") 53 if (iid == __uuidof(IUnknown))
55 *ppv =
static_cast<IUnknown*
>(
this);
57 else if (iid == __uuidof(ISensorEvents))
59 *ppv =
static_cast<ISensorEvents*
>(
this);
72 return InterlockedIncrement(&
m_cRef);
93 IPortableDeviceValues *pEventData)
104 if (
NULL == report ||
113 report->GetTimestamp(&sys_time);
115 PROPVARIANT var = {};
117 auto hr = (report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE1, &var));
118 if (FAILED(hr))
return S_OK;
119 auto customTimestampLow = var.ulVal;
122 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE2, &var));
123 auto customTimestampHigh = var.ulVal;
126 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE6, &var));
128 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_CUSTOM_VALUE7, &var));
133 SENSOR_TYPE_ID
type{};
137 double rawX, rawY, rawZ;
140 if (
type == SENSOR_TYPE_ACCELEROMETER_3D)
142 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ACCELERATION_X_G, &var));
145 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ACCELERATION_Y_G, &var));
148 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ACCELERATION_Z_G, &var));
151 static constexpr
double accelerator_transform_factor = 1000.0;
153 rawX *= accelerator_transform_factor;
154 rawY *= accelerator_transform_factor;
155 rawZ *= accelerator_transform_factor;
157 else if (
type == SENSOR_TYPE_GYROMETER_3D)
160 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, &var));
164 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, &var));
168 CHECK_HR(report->GetSensorValue(SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, &var));
171 static constexpr
double gyro_transform_factor = 10.0;
173 rawX *= gyro_transform_factor;
174 rawY *= gyro_transform_factor;
175 rawZ *= gyro_transform_factor;
183 PropVariantClear(&var);
191 meta_data.header.timestamp = customTimestampLow | (customTimestampHigh < 32);
198 meta_data.report_type.imu_report.custom_timestamp = customTimestampLow | (customTimestampHigh < 32);
199 meta_data.report_type.imu_report.imu_counter = imu_count;
200 meta_data.report_type.imu_report.usb_counter = usb_count;
205 data.ts_low = customTimestampLow;
206 data.ts_high = customTimestampHigh;
208 pSensor->GetFriendlyName(&fName);
209 d.sensor.name = CW2A(fName);
210 SysFreeString(fName);
213 d.fo.metadata = &meta_data;
215 d.fo.frame_size =
sizeof(
data);
216 d.fo.backend_time = 0;
217 if (SystemTimeToFileTime(&sys_time, &file_time))
220 d.fo.backend_time = ll_now * 0.0001;
229 REFSENSOR_ID sensorID)
252 if (state == SENSOR_STATE_READY)
254 wprintf_s(L
"\nTime sensor is now ready.");
256 else if (state == SENSOR_STATE_ACCESS_DENIED)
258 wprintf_s(L
"\nNo permission for the time sensor.\n");
259 wprintf_s(L
"Enable the sensor in the control panel.\n");
275 for (
auto& profile_to_open : iio_profiles)
277 for (
auto& connected_sensor : _connected_sensors)
279 if (profile_to_open.sensor_name == connected_sensor->get_sensor_name())
283 IPortableDeviceValues* pPropsToSet =
NULL;
284 IPortableDeviceValues* pPropsReturn =
NULL;
287 CHECK_HR(CoCreateInstance(__uuidof(PortableDeviceValues),
NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pPropsToSet)));
290 hr = pPropsToSet->SetUnsignedIntegerValue(SENSOR_PROPERTY_CURRENT_REPORT_INTERVAL, profile_to_open.frequency);
294 hr = connected_sensor->get_sensor()->SetProperties(pPropsToSet, &pPropsReturn);
297 _opened_sensors.push_back(connected_sensor);
298 pPropsReturn->Release();
302 pPropsToSet->Release();
309 for (
auto& connected_sensor : _connected_sensors)
311 connected_sensor.reset();
313 _connected_sensors.clear();
321 for (
auto& open_sensor : _opened_sensors)
325 _opened_sensors.clear();
332 ISensorEvents* sensorEvents =
nullptr;
333 CHECK_HR(_cb->QueryInterface(IID_PPV_ARGS(&sensorEvents)));
335 for (
auto&
sensor : _opened_sensors)
343 for (
auto&
sensor : _opened_sensors)
352 std::vector<hid_sensor> sensors;
354 for (
auto&
sensor : _hid_profiles)
355 sensors.push_back({
sensor.sensor_name });
362 return std::vector<uint8_t>();
370 CComPtr<ISensorManager> pSensorManager =
nullptr;
371 CComPtr<ISensorCollection> pSensorCollection =
nullptr;
372 CComPtr<ISensor> pSensor =
nullptr;
373 ULONG sensorCount = 0;
376 CHECK_HR(CoCreateInstance(CLSID_SensorManager,
NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pSensorManager)));
379 LOG_HR(
res=pSensorManager->GetSensorsByCategory(SENSOR_CATEGORY_ALL, &pSensorCollection));
383 CHECK_HR(pSensorCollection->GetCount(&sensorCount));
385 for (ULONG
i = 0;
i < sensorCount;
i++)
388 if (SUCCEEDED(pSensorCollection->GetAt(
i, &pSensor.p)))
392 LOG_HR(
res = pSensor->GetFriendlyName(&fName));
394 fName= L
"Unidentified HID sensor";
401 SENSOR_TYPE_ID
type{};
404 CComPtr<IPortableDeviceValues> pValues =
nullptr;
408 auto hr = pSensor->GetProperties(
nullptr, &pValues);
412 DWORD propertyCount = 0;
413 hr = pValues->GetCount(&propertyCount);
416 PROPERTYKEY propertyKey;
417 PROPVARIANT propertyValue = {};
420 for (DWORD properyIndex = 0; properyIndex < propertyCount; properyIndex++)
423 hr = pValues->GetAt(properyIndex, &propertyKey, &propertyValue);
426 if (IsEqualPropertyKey(propertyKey, SENSOR_PROPERTY_DEVICE_PATH))
450 info.unique_id = node.get_parent().get_uid();
454 LOG_WARNING(
"Parent for HID device not available: " <<
info.device_path );
462 if (IsEqualPropertyKey(propertyKey, SENSOR_PROPERTY_SERIAL_NUMBER))
470 PropVariantClear(&propertyValue);
477 SysFreeString(fName);
484 LOG_INFO(
"Could not enumerate HID devices!");
constexpr uint8_t metadata_hid_raw_size
GLsizei const GLchar *const * string
def info(name, value, persistent=False)
constexpr uint8_t metadata_imu_report_size
unsigned __int64 uint64_t
constexpr uint64_t WIN_FILETIME_2_UNIX_SYSTIME
LOG_INFO("Log message using LOG_INFO()")
GLuint GLenum GLenum transform
std::string to_string(T value)