diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a59c738 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,38 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +# Declare files that will always have CRLF line endings on checkout. +*.appxmanifest text eol=crlf +*.c text eol=crlf +*.cpp text eol=crlf +*.cs text eol=crlf +*.csproj text eol=crlf +*.css text eol=crlf +*.def text eol=crlf +*.filters text eol=crlf +*.h text eol=crlf +*.htm text eol=crlf +*.html text eol=crlf +*.idl text eol=crlf +*.js text eol=crlf +*.jsproj text eol=crlf +*.rc text eol=crlf +*.rgs text eol=crlf +*.sln text eol=crlf +*.vcxproj text eol=crlf +*.xaml text eol=crlf + +# Declare files that are encoded in UTF-16 +*.inf text diff working-tree-encoding=UTF-16LE-BOM eol=crlf +*.inx text diff working-tree-encoding=UTF-16LE-BOM eol=crlf + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +*.cs diff=csharp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21d9208..4f34f57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: platform: [x64] runs-on: windows-2022 # env: - # Solution_Path: SensorsComboDriver\SensorsComboDriver.sln + # Solution_Path: FrameworkSensors\FrameworkSensors.sln steps: - name: Check out repository code uses: actions/checkout@v4 @@ -21,8 +21,7 @@ jobs: # msbuild ${{ env.Solution_Path }} -p:Configuration:${{ env.Configuration }} -p:Platform:${{ env.Platform }} - name: Build solution run: | - msbuild SensorsComboDriver\SensorsComboDriver.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }} - msbuild SimpleDeviceOrientationSensor\SimpleDeviceOrientationSensor.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }} + msbuild FrameworkSensors\FrameworkSensors.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }} env: Configuration: ${{ matrix.configuration }} Platform: ${{ matrix.platform }} diff --git a/SensorsComboDriver/AlsClient.cpp b/FrameworkSensors/AlsClient.cpp similarity index 97% rename from SensorsComboDriver/AlsClient.cpp rename to FrameworkSensors/AlsClient.cpp index eb7080a..753e873 100644 --- a/SensorsComboDriver/AlsClient.cpp +++ b/FrameworkSensors/AlsClient.cpp @@ -9,6 +9,7 @@ // Windows User-Mode Driver Framework (WUDF) #include "Clients.h" +#include "EcCommunication.h" #include "AlsClient.tmh" @@ -165,7 +166,7 @@ AlsDevice::Initialize( &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", + InitPropVariantFromString(L"Framework Computer Inc", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; @@ -462,7 +463,6 @@ AlsDevice::Initialize( } - //------------------------------------------------------------------------------ // Function: GetData // @@ -478,6 +478,7 @@ AlsDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS AlsDevice::GetData( + _In_ HANDLE Handle ) { BOOLEAN DataReady = FALSE; @@ -486,6 +487,15 @@ AlsDevice::GetData( SENSOR_FunctionEnter(); + UINT8 als[4] = {0}; + CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 0, &als[0]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 1, &als[1]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 2, &als[2]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 3, &als[3]); + m_CachedData.Lux = (float) (als[0] + (als[1] << 8) + (als[2] << 16) + (als[3] << 24)); + TraceInformation("Read ALS value %02x %02x %02x %02x (%f)\n", + als[0], als[1], als[2], als[3], m_CachedData.Lux); + // new sample? if (m_FirstSample != FALSE) { diff --git a/SensorsComboDriver/Clients.cpp b/FrameworkSensors/Clients.cpp similarity index 99% rename from SensorsComboDriver/Clients.cpp rename to FrameworkSensors/Clients.cpp index 4524b6b..4673356 100644 --- a/SensorsComboDriver/Clients.cpp +++ b/FrameworkSensors/Clients.cpp @@ -47,7 +47,7 @@ OnTimerExpire( // Get data and push to clx Lock(pDevice->m_Lock); - Status = pDevice->GetData(); + Status = pDevice->GetData(pDevice->m_CrosEcHandle); if (!NT_SUCCESS(Status) && Status != STATUS_DATA_NOT_ACCEPTED) { TraceError("COMBO %!FUNC! GetData Failed %!STATUS!", Status); diff --git a/SensorsComboDriver/Clients.h b/FrameworkSensors/Clients.h similarity index 62% rename from SensorsComboDriver/Clients.h rename to FrameworkSensors/Clients.h index a8992fa..3dee88a 100644 --- a/SensorsComboDriver/Clients.h +++ b/FrameworkSensors/Clients.h @@ -126,6 +126,7 @@ typedef class _ComboDevice ULONG m_StartTime; ULONGLONG m_SampleCount; BOOLEAN m_WakeEnabled; + HANDLE m_CrosEcHandle; // // Sensor Specific Properties @@ -142,7 +143,7 @@ typedef class _ComboDevice // Sensor specific functions // virtual NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj) = NULL; - virtual NTSTATUS GetData() = NULL; + virtual NTSTATUS GetData(_In_ HANDLE Handle) = NULL; virtual NTSTATUS UpdateCachedThreshold() = NULL; virtual NTSTATUS EnableWake() { return STATUS_NOT_SUPPORTED; } virtual NTSTATUS DisableWake() { return STATUS_NOT_SUPPORTED; } @@ -197,127 +198,13 @@ typedef class _AlsDevice : public _ComboDevice public: NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); + NTSTATUS GetData(_In_ HANDLE Device); NTSTATUS UpdateCachedThreshold(); } AlsDevice, *PAlsDevice; -// -// Barometer -------------------------------------------------------------- -// -typedef class _BarDevice : public _ComboDevice -{ -private: - - FLOAT m_CachedThresholds; - FLOAT m_CachedData; - FLOAT m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} BarDevice, *PBarDevice; - - - -// -// Gyroscope ------------------------------------------------------------------ -// -typedef class _GyrDevice : public _ComboDevice -{ -private: - - VEC3D m_CachedThresholds; - VEC3D m_CachedData; - VEC3D m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} GyrDevice, *PGyrDevice; - - - -// -// Magnetometer --------------------------------------------------------------- -// -typedef struct _MagData -{ - VEC3D Axis; - ULONG Accuracy; -} MagData, *PMagData; - -typedef class _MagDevice : public _ComboDevice -{ -private: - - VEC3D m_CachedThresholds; - MagData m_CachedData; - MagData m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} MagDevice, *PMagDevice; - - - -// -// Proximity ------------------------------------------------------------------ -// -typedef struct -{ - BOOL Detected; - ULONG DistanceMillimeters; -} PrxData, *PPrxData; - -typedef class _PrxDevice : public _ComboDevice -{ -private: - - PrxData m_CachedData; - PrxData m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} PrxDevice, *PPrxDevice; - - - -// -// Relative Fusion ------------------------------------------------------------------ -// -typedef class _RelativeFusionDevice : public _ComboDevice -{ -private: - - QUATERNION m_CachedThresholds; - QUATERNION m_CachedData; - QUATERNION m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} RelativeFusionDevice, *PRelativeFusionDevice; - // // Linear Accelerometer -------------------------------------------------------------- // @@ -338,52 +225,34 @@ typedef class _LinearAccelerometerDevice : public _ComboDevice public: NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); + NTSTATUS GetData(_In_ HANDLE Device); NTSTATUS UpdateCachedThreshold(); } LinearAccelerometerDevice, *PLinearAccelerometerDevice; -// -// Gravity Vector -------------------------------------------------------------- -// -typedef class _GravityVectorDevice : public _ComboDevice -{ -private: - - VEC3D m_CachedThresholds; - VEC3D m_CachedData; - VEC3D m_LastSample; - -public: - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} GravityVectorDevice, *PGravityVectorDevice; // -// Geomagnetic Orientation ------------------------------------------------------------------ +// Simple Device Orientation -------------------------------------------------- // -typedef class _GeomagneticOrientationDevice : public _ComboDevice +typedef class _SimpleDeviceOrientationDevice : public _ComboDevice { private: - typedef struct _GeomagneticOrientationSample + typedef struct _SimpleDeviceOrientationSample { - QUATERNION Quaternion; - FLOAT RotationAngle_Degrees; - FLOAT DeclinationAngle_Degrees; - } GeomagneticOrientationSample, *PGeomagneticOrientationSample; + FLOAT X; + BOOL Shake; + } SimpleDeviceOrientationSample, *PSimpleDeviceOrientationSample; - GeomagneticOrientationSample m_CachedThresholds; - GeomagneticOrientationSample m_CachedData; - GeomagneticOrientationSample m_LastSample; + SimpleDeviceOrientationSample m_CachedThresholds; + SimpleDeviceOrientationSample m_CachedData; + SimpleDeviceOrientationSample m_LastSample; public: NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); + NTSTATUS GetData(_In_ HANDLE Device); NTSTATUS UpdateCachedThreshold(); -} GeomagneticOrientationDevice, *PGeomagneticOrientationDevice; +} SimpleDeviceOrientationDevice, *PSimpleDeviceOrientationDevice; diff --git a/SensorsComboDriver/Device.cpp b/FrameworkSensors/Device.cpp similarity index 85% rename from SensorsComboDriver/Device.cpp rename to FrameworkSensors/Device.cpp index b93bbbd..51b5220 100644 --- a/SensorsComboDriver/Device.cpp +++ b/FrameworkSensors/Device.cpp @@ -3,7 +3,7 @@ // Abstract: // // This module contains the implementation of WDF callback functions -// for combo driver. +// for Framework Sensors driver. // // Environment: // @@ -11,25 +11,31 @@ #include "Clients.h" #include "Driver.h" +#include "EcCommunication.h" #include +#include #include "Device.tmh" +#define ENABLE_ALS_SENSOR 0 +#define ENABLE_ORIENTATION_SENSOR 0 +#define ENABLE_ACCEL_SENSOR 1 + //--------------------------------------- // Declare and map devices below //--------------------------------------- enum Device { - Device_Als = 0, - Device_Bar, - Device_GeomagneticOrientation, - Device_GravityVector, - Device_Gyr, +#if ENABLE_ALS_SENSOR + Device_Als, +#endif +#if ENABLE_ORIENTATION_SENSOR + Device_SimpleDeviceOrientation, +#endif +#if ENABLE_ACCEL_SENSOR Device_LinearAccelerometer, - Device_Mag, - Device_Prx, - Device_RelativeFusion, +#endif // Keep this last Device_Count }; @@ -43,15 +49,15 @@ inline size_t GetDeviceSizeAtIndex( size_t result = 0; switch (static_cast(Index)) { +#if ENABLE_ALS_SENSOR case Device_Als: result = sizeof(AlsDevice); break; - case Device_Bar: result = sizeof(BarDevice); break; - case Device_GeomagneticOrientation: result = sizeof(GeomagneticOrientationDevice); break; - case Device_GravityVector: result = sizeof(GravityVectorDevice); break; - case Device_Gyr: result = sizeof(GyrDevice); break; +#endif +#if ENABLE_ORIENTATION_SENSOR + case Device_SimpleDeviceOrientation:result = sizeof(SimpleDeviceOrientationDevice); break; +#endif +#if ENABLE_ACCEL_SENSOR case Device_LinearAccelerometer: result = sizeof(LinearAccelerometerDevice); break; - case Device_Mag: result = sizeof(MagDevice); break; - case Device_Prx: result = sizeof(PrxDevice); break; - case Device_RelativeFusion: result = sizeof(RelativeFusionDevice); break; +#endif default: break; // invalid } return result; @@ -64,25 +70,57 @@ void AllocateDeviceAtIndex( { switch (static_cast(Index)) { +#if ENABLE_ALS_SENSOR case Device_Als: *ppDevice = new(*ppDevice) AlsDevice; break; - case Device_Bar: *ppDevice = new(*ppDevice) BarDevice; break; - case Device_GeomagneticOrientation: *ppDevice = new(*ppDevice) GeomagneticOrientationDevice; break; - case Device_GravityVector: *ppDevice = new(*ppDevice) GravityVectorDevice; break; - case Device_Gyr: *ppDevice = new(*ppDevice) GyrDevice; break; +#endif +#if ENABLE_ORIENTATIONACCEL_SENSOR + case Device_SimpleDeviceOrientation:*ppDevice = new(*ppDevice) SimpleDeviceOrientationDevice; break; +#endif +#if ENABLE_ACCEL_SENSOR case Device_LinearAccelerometer: *ppDevice = new(*ppDevice) LinearAccelerometerDevice; break; - case Device_Mag: *ppDevice = new(*ppDevice) MagDevice; break; - case Device_Prx: *ppDevice = new(*ppDevice) PrxDevice; break; - case Device_RelativeFusion: *ppDevice = new(*ppDevice) RelativeFusionDevice; break; +#endif default: break; // invalid (let driver fail) } } +NTSTATUS ConnectToEc( + _In_ WDFDEVICE FxDevice, + _Inout_ HANDLE *Handle +) { + SENSOR_FunctionEnter(); + NTSTATUS Status = STATUS_SUCCESS; + + UNREFERENCED_PARAMETER(FxDevice); + + *Handle = CreateFileW( + LR"(\\.\GLOBALROOT\Device\CrosEC)", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + + if (*Handle == INVALID_HANDLE_VALUE) { + Status = STATUS_INVALID_HANDLE; + TraceError("COMBO %!FUNC! CreateFileW failed %!STATUS!", Status); + goto Exit; + } + +Exit: + SENSOR_FunctionExit(Status); + + return Status; +} + + + //------------------------------------------------------------------------------ // // Function: OnDeviceAdd // -// This routine is the AddDevice entry point for the combo client +// This routine is the AddDevice entry point for the Framework Sensors client // driver. This routine is called by the framework in response to AddDevice // call from the PnP manager. It will create and initialize the device object // to represent a new instance of the sensor client. @@ -213,9 +251,43 @@ OnPrepareHardware( ) { NTSTATUS Status = STATUS_SUCCESS; + ULONG i; + HANDLE Handle; + DWORD retb{}; + CROSEC_READMEM rm{}; SENSOR_FunctionEnter(); + Status = ConnectToEc(Device, &Handle); + if (!NT_SUCCESS(Status)) { + TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status); + goto Exit; + } + + rm.bytes = 0xfe; + rm.offset = 0; + Status = DeviceIoControl(Handle, + (DWORD) IOCTL_CROSEC_RDMEM, + &rm, + sizeof(rm), + &rm, + sizeof(rm), + &retb, + nullptr); + if (!NT_SUCCESS(Status)) { + TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status); + goto Exit; + } + + UINT8 *EcMem = rm.buffer; + for (i = 0; i < 0xfe-16; i+=16) { + TraceInformation( + "%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", + EcMem[i], EcMem[i+1], EcMem[i+2], EcMem[i+3], EcMem[i+4], EcMem[i + 5], EcMem[i + 6], EcMem[i + 7], + EcMem[i + 8], EcMem[i+9], EcMem[i+10], EcMem[i+11], EcMem[i+12], EcMem[i + 13], EcMem[i + 14], EcMem[i + 15] + ); + } + for (ULONG Count = 0; Count < SensorInstanceCount; Count++) { PComboDevice pDevice = nullptr; @@ -245,6 +317,8 @@ OnPrepareHardware( AllocateDeviceAtIndex(Count, &pDevice); + pDevice->m_CrosEcHandle = Handle; + // Fill out properties Status = pDevice->Initialize(Device, SensorInstance); if (!NT_SUCCESS(Status)) @@ -345,8 +419,6 @@ OnReleaseHardware( return Status; } - - //------------------------------------------------------------------------------ // // Function: OnD0Entry @@ -377,6 +449,7 @@ OnD0Entry( SENSOR_FunctionEnter(); + // // Get sensor instances // diff --git a/SensorsComboDriver/Driver.cpp b/FrameworkSensors/Driver.cpp similarity index 98% rename from SensorsComboDriver/Driver.cpp rename to FrameworkSensors/Driver.cpp index 1ebc7a0..db2b57c 100644 --- a/SensorsComboDriver/Driver.cpp +++ b/FrameworkSensors/Driver.cpp @@ -2,7 +2,7 @@ // // Abstract: // -// This module contains the implementation of entry and exit point of combo driver. +// This module contains the implementation of entry and exit point of Framework Sensors driver. // // Environment: // diff --git a/SensorsComboDriver/Driver.h b/FrameworkSensors/Driver.h similarity index 90% rename from SensorsComboDriver/Driver.h rename to FrameworkSensors/Driver.h index de30727..c348183 100644 --- a/SensorsComboDriver/Driver.h +++ b/FrameworkSensors/Driver.h @@ -2,7 +2,7 @@ // // Abstract: // -// This module contains the type definitions for the combo +// This module contains the type definitions for the Framework Sensors // driver callback class. // // Environment: diff --git a/FrameworkSensors/EcCommunication.cpp b/FrameworkSensors/EcCommunication.cpp new file mode 100644 index 0000000..9adac8d --- /dev/null +++ b/FrameworkSensors/EcCommunication.cpp @@ -0,0 +1,43 @@ + +// Only need EC commands to use EC_CMD_MOTION_SENSE_CMD to determine which accel sensors there are and which position they are +// ALl the rest can be done using memory map reads + +#include "Clients.h" +#include "EcCommunication.h" +#include +#include + +#include "EcCommunication.tmh" + +int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest) +{ + NTSTATUS Status = STATUS_SUCCESS; + DWORD retb{}; + CROSEC_READMEM rm{}; + + if (Handle == INVALID_HANDLE_VALUE) { + Status = STATUS_INVALID_HANDLE; + TraceError("COMBO %!FUNC! Invalid Handle"); + return 0; + } + + rm.bytes = 0x01; + rm.offset = offset; + Status = DeviceIoControl(Handle, + (DWORD) IOCTL_CROSEC_RDMEM, + &rm, + sizeof(rm), + &rm, + sizeof(rm), + &retb, + nullptr); + if (!NT_SUCCESS(Status)) { + TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status); + return 0; + } + + TraceInformation("COMBO %!FUNC! Successfully read %d bytes from EC memory at %02x. First one %02x. retb=%d", rm.bytes, rm.offset, rm.buffer[0], retb); + *dest = rm.buffer[0]; + + return rm.bytes; +} diff --git a/FrameworkSensors/EcCommunication.h b/FrameworkSensors/EcCommunication.h new file mode 100644 index 0000000..df830e0 --- /dev/null +++ b/FrameworkSensors/EcCommunication.h @@ -0,0 +1,55 @@ +//Copyright (C) Framework Computer Inc +//Copyright (C) 2014 The ChromiumOS Authors +// +//Abstract: +// +// Definitions for accessing EC + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Command version mask */ +#define EC_VER_MASK(version) (1UL << (version)) + +#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ +/* Unused 0x84 - 0x8f */ +#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ +/* Unused 0x91 */ +#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ +/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ +/* 0x94 - 0x99: 1st Accelerometer */ +/* 0x9a - 0x9f: 2nd Accelerometer */ + +/* Define the format of the accelerometer mapped memory status byte. */ +#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f +// BIT(4) +#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4) +// BIT(7) +#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7) + +#define FILE_DEVICE_CROS_EMBEDDED_CONTROLLER 0x80EC + +#define IOCTL_CROSEC_XCMD \ + CTL_CODE(FILE_DEVICE_CROS_EMBEDDED_CONTROLLER, 0x801, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA) +#define IOCTL_CROSEC_RDMEM CTL_CODE(FILE_DEVICE_CROS_EMBEDDED_CONTROLLER, 0x802, METHOD_BUFFERED, FILE_READ_DATA) + +#define CROSEC_CMD_MAX_REQUEST 0x100 +#define CROSEC_CMD_MAX_RESPONSE 0x100 +#define CROSEC_MEMMAP_SIZE 0xFF + +typedef struct _CROSEC_READMEM { + ULONG offset; + ULONG bytes; + UCHAR buffer[CROSEC_MEMMAP_SIZE]; +} * PCROSEC_READMEM, CROSEC_READMEM; + +int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest); + +#ifdef __cplusplus +} +#endif diff --git a/FrameworkSensors/FrameworkSensors.inx b/FrameworkSensors/FrameworkSensors.inx new file mode 100644 index 0000000..d833c79 --- /dev/null +++ b/FrameworkSensors/FrameworkSensors.inx @@ -0,0 +1,81 @@ +/*++ +; +;Copyright (c) Microsoft Corporation. All rights reserved. +;Copyright (c) Framework Computer Inc. All rights reserved. +; +;Module Name: +; FrameworkSensors.INF +; +;Abstract: +; INF file for installing the Framework Sensor Driver +; +;--*/ +[Version] +Signature = "$WINDOWS NT$" +Class = Sensor +ClassGuid = {5175D334-C371-4806-B3BA-71FD53C9258D} +Provider = %PROVIDER% +CatalogFile = FrameworkSensors.cat +DriverVer = 8/29/2014,2.00.00.03 +PnpLockdown = 1 + +[SourceDisksNames] +1 = %MediaDescription%,,,"" + +[SourceDisksFiles] +FrameworkSensors.dll = 1,, + +[Manufacturer] +%PROVIDER% = FrameworkSensors_Device, NT$ARCH$.10.0...22000 + +;******************************* +; Framework Sensors Driver Install Section +;******************************* + +[FrameworkSensors_Device.NT$ARCH$.10.0...22000] +; DisplayName Section DeviceId +; ----------- ------- -------- +%FrameworkSensors_DevDesc% = FrameworkSensors_Inst, ACPI\FRMWC006 + +[FrameworkSensors_Inst.NT] +Include=WUDFRD.inf +Needs=WUDFRD.NT +CopyFiles = FrameworkSensorsCopy + +[FrameworkSensorsCopy] +FrameworkSensors.dll + +[FrameworkSensors_Inst.NT.HW] +Include=WUDFRD.inf +Needs=WUDFRD.NT.HW + +[DestinationDirs] +;12 == Windows\System32\Drivers\UMDF +DefaultDestDir = 12,UMDF + +;-------------- Service installation +[FrameworkSensors_Inst.NT.Services] +Include=WUDFRD.inf +Needs=WUDFRD.NT.Services + +;-------------- WDF specific section + +[FrameworkSensors_Inst.NT.Wdf] +UmdfService = FrameworkSensors, FrameworkSensors_Install +UmdfServiceOrder = FrameworkSensors +UmdfDirectHardwareAccess = AllowDirectHardwareAccess +UmdfFileObjectPolicy = AllowNullAndUnknownFileObjects +UmdfFsContextUsePolicy = CannotUseFsContexts + +[FrameworkSensors_Install] +UmdfLibraryVersion = $UMDFVERSION$ +ServiceBinary = %12%\UMDF\FrameworkSensors.dll +UmdfExtensions = SensorsCx0102 + +[Strings] +;Localizable Strings +MediaDescription = "Framework Computer Sensor Driver" +PROVIDER = "Framework Computer Inc" +FrameworkSensors_DevDesc = "Sensor Driver - ALS, Accelerometer, Orientation" + +;Non-Localizable Strings diff --git a/SensorsComboDriver/SensorsComboDriver.sln b/FrameworkSensors/FrameworkSensors.sln similarity index 89% rename from SensorsComboDriver/SensorsComboDriver.sln rename to FrameworkSensors/FrameworkSensors.sln index cc1759f..ff6285a 100644 --- a/SensorsComboDriver/SensorsComboDriver.sln +++ b/FrameworkSensors/FrameworkSensors.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0 MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SensorsComboDriver", "SensorsComboDriver.vcxproj", "{C3964BD1-B485-4236-8BB4-E2981B800AC1}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FrameworkSensors", "FrameworkSensors.vcxproj", "{C3964BD1-B485-4236-8BB4-E2981B800AC1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj b/FrameworkSensors/FrameworkSensors.vcxproj similarity index 94% rename from SensorsComboDriver/SensorsComboDriver.vcxproj rename to FrameworkSensors/FrameworkSensors.vcxproj index 6c7fcd2..7cc55ee 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/FrameworkSensors/FrameworkSensors.vcxproj @@ -28,6 +28,7 @@ + true Windows10 False Universal @@ -36,6 +37,7 @@ DynamicLibrary + true Windows10 False Universal @@ -44,6 +46,7 @@ DynamicLibrary + true Windows10 True Universal @@ -52,6 +55,7 @@ DynamicLibrary + true Windows10 True Universal @@ -76,29 +80,29 @@ - + true true - SensorsComboDriver + FrameworkSensors sensorstrace.h - + $(InfArch) true - .\$(IntDir)\SensorsComboDriver.inf + .\$(IntDir)\FrameworkSensors.inf - SensorsComboDriver + FrameworkSensors - SensorsComboDriver + FrameworkSensors - SensorsComboDriver + FrameworkSensors - SensorsComboDriver + FrameworkSensors diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters b/FrameworkSensors/FrameworkSensors.vcxproj.Filters similarity index 72% rename from SensorsComboDriver/SensorsComboDriver.vcxproj.Filters rename to FrameworkSensors/FrameworkSensors.vcxproj.Filters index 7e7513b..6bb862f 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/FrameworkSensors/FrameworkSensors.vcxproj.Filters @@ -22,9 +22,6 @@ Source Files - - Source Files - Source Files @@ -34,33 +31,21 @@ Source Files - + Source Files - - Source Files - - + Source Files Source Files - - Source Files - - - Source Files - - - Source Files - - + Source Files - + Driver Files diff --git a/SensorsComboDriver/SensorsTrace.h b/FrameworkSensors/SensorsTrace.h similarity index 100% rename from SensorsComboDriver/SensorsTrace.h rename to FrameworkSensors/SensorsTrace.h diff --git a/SensorsComboDriver/GravityVectorClient.cpp b/FrameworkSensors/SimpleDeviceOrientationClient.cpp similarity index 65% rename from SensorsComboDriver/GravityVectorClient.cpp rename to FrameworkSensors/SimpleDeviceOrientationClient.cpp index 4dc53d7..a92fd22 100644 --- a/SensorsComboDriver/GravityVectorClient.cpp +++ b/FrameworkSensors/SimpleDeviceOrientationClient.cpp @@ -10,33 +10,30 @@ #include "Clients.h" -#include "GravityVectorClient.tmh" +#include "SimpleDeviceOrientationClient.tmh" +#define SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER 'sodS' +#define SimpleDeviceOrientationDevice_Default_MinDataInterval (4) +#define SimpleDeviceOrientationDevice_Default_Axis_Threshold (1.0f) +#define SimpleDeviceOrientationDevice_Axis_Resolution (4.0f / 65536.0f) // in delta g +#define SimpleDeviceOrientationDevice_Axis_Minimum (-2.0f) // in g +#define SimpleDeviceOrientationDevice_Axis_Maximum (2.0f) // in g -#define SENSORV2_POOL_TAG_GRAVITY_VECTOR '6ArG' - -#define GravityVectorDevice_Default_MinDataInterval (4) -#define GravityVectorDevice_Default_Axis_Threshold (1.0f) -#define GravityVectorDevice_Axis_Resolution (4.0f / 65536.0f) // in delta g -#define GravityVectorDevice_Axis_Minimum (-2.0f) // in g -#define GravityVectorDevice_Axis_Maximum (2.0f) // in g - - -// Linear Accelerometer Unique ID -// {56E11473-2BB7-41E4-863A-DA014200C0DC} -DEFINE_GUID(GUID_GravityVectorDevice_UniqueID, - 0x56e11473, 0x2bb7, 0x41e4, 0x86, 0x3a, 0xda, 0x1, 0x42, 0x0, 0xc0, 0xdc); +// Simple Device Orientation ID +// {4A303B3E-332A-4044-A35A-282F3D6D56E5} +DEFINE_GUID(GUID_SimpleDeviceOrientationDevice_UniqueID, + 0x4a303b3e, 0x332a, 0x4044, 0xa3, 0x5a, 0x28, 0x2f, 0x3d, 0x6d, 0x56, + 0xe5); // Sensor data typedef enum { - GRAVITY_VECTOR_DATA_X = 0, - GRAVITY_VECTOR_DATA_Y, - GRAVITY_VECTOR_DATA_Z, - GRAVITY_VECTOR_DATA_TIMESTAMP, - GRAVITY_VECTOR_DATA_COUNT -} GRAVITY_VECTOR_DATA_INDEX; + LINEAR_ACCELEROMETER_DATA_X = 0, + LINEAR_ACCELEROMETER_DATA_TIMESTAMP, + LINEAR_ACCELEROMETER_DATA_SHAKE, + LINEAR_ACCELEROMETER_DATA_COUNT +} LINEAR_ACCELEROMETER_DATA_INDEX; //------------------------------------------------------------------------------ // Function: Initialize @@ -51,7 +48,7 @@ typedef enum // NTSTATUS code //------------------------------------------------------------------------------ NTSTATUS -GravityVectorDevice::Initialize( +SimpleDeviceOrientationDevice::Initialize( _In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorInstance ) @@ -73,7 +70,7 @@ GravityVectorDevice::Initialize( Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); if (!NT_SUCCESS(Status)) { - TraceError("COMBO %!FUNC! GRA WdfWaitLockCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfWaitLockCreate failed %!STATUS!", Status); goto Exit; } @@ -93,7 +90,7 @@ GravityVectorDevice::Initialize( Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); if (!NT_SUCCESS(Status)) { - TraceError("COMBO %!FUNC! GRA WdfTimerCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfTimerCreate failed %!STATUS!", Status); goto Exit; } } @@ -111,13 +108,13 @@ GravityVectorDevice::Initialize( MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pEnumerationProperties); if (!NT_SUCCESS(Status) || m_pEnumerationProperties == nullptr) { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } @@ -125,15 +122,15 @@ GravityVectorDevice::Initialize( m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_GravityVector, + InitPropVariantFromCLSID(GUID_SensorType_SimpleDeviceOrientation, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", + InitPropVariantFromString(L"Framework Computer Inc", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Gravity Vector Sensor", + InitPropVariantFromString(L"Simple Device Orientation", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; @@ -142,7 +139,7 @@ GravityVectorDevice::Initialize( &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_GravityVectorDevice_UniqueID, + InitPropVariantFromCLSID(GUID_SimpleDeviceOrientationDevice_UniqueID, &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; @@ -156,30 +153,29 @@ GravityVectorDevice::Initialize( { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(GRAVITY_VECTOR_DATA_COUNT); + ULONG Size = SENSOR_PROPERTY_LIST_SIZE(LINEAR_ACCELEROMETER_DATA_COUNT); MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pSupportedDataFields); if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = GRAVITY_VECTOR_DATA_COUNT; + m_pSupportedDataFields->Count = LINEAR_ACCELEROMETER_DATA_COUNT; - m_pSupportedDataFields->List[GRAVITY_VECTOR_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[GRAVITY_VECTOR_DATA_X] = PKEY_SensorData_AccelerationX_Gs; - m_pSupportedDataFields->List[GRAVITY_VECTOR_DATA_Y] = PKEY_SensorData_AccelerationY_Gs; - m_pSupportedDataFields->List[GRAVITY_VECTOR_DATA_Z] = PKEY_SensorData_AccelerationZ_Gs; + m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; + m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_X] = PKEY_SensorData_AccelerationX_Gs; + m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_SHAKE] = PKEY_SensorData_Shake; } // @@ -188,7 +184,7 @@ GravityVectorDevice::Initialize( { WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GRAVITY_VECTOR_DATA_COUNT); + ULONG Size = SENSOR_COLLECTION_LIST_SIZE(LINEAR_ACCELEROMETER_DATA_COUNT); FILETIME Time = {0}; MemoryHandle = NULL; @@ -196,46 +192,41 @@ GravityVectorDevice::Initialize( MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pData); if (!NT_SUCCESS(Status) || m_pData == nullptr) { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = GRAVITY_VECTOR_DATA_COUNT; + m_pData->Count = LINEAR_ACCELEROMETER_DATA_COUNT; - m_pData->List[GRAVITY_VECTOR_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; + m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[GRAVITY_VECTOR_DATA_TIMESTAMP].Value)); + InitPropVariantFromFileTime(&Time, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].Value)); - m_pData->List[GRAVITY_VECTOR_DATA_X].Key = PKEY_SensorData_AccelerationX_Gs; - InitPropVariantFromFloat(0.0, &(m_pData->List[GRAVITY_VECTOR_DATA_X].Value)); + m_pData->List[LINEAR_ACCELEROMETER_DATA_X].Key = PKEY_SensorData_AccelerationX_Gs; + InitPropVariantFromFloat(0.0, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_X].Value)); - m_pData->List[GRAVITY_VECTOR_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; - InitPropVariantFromFloat(0.0, &(m_pData->List[GRAVITY_VECTOR_DATA_Y].Value)); - - m_pData->List[GRAVITY_VECTOR_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; - InitPropVariantFromFloat(0.0, &(m_pData->List[GRAVITY_VECTOR_DATA_Z].Value)); + m_pData->List[LINEAR_ACCELEROMETER_DATA_SHAKE].Key = PKEY_SensorData_Shake; + InitPropVariantFromBoolean(FALSE, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_SHAKE].Value)); m_CachedData.X = 0.0f; - m_CachedData.Y = 0.0f; - m_CachedData.Z = 0.0f; + m_CachedData.Shake = FALSE; m_LastSample.X = 0.0f; - m_LastSample.Y = 0.0f; - m_LastSample.Z = 0.0f; + m_LastSample.Shake = FALSE; } // // Sensor Properties // { - m_IntervalMs = GravityVectorDevice_Default_MinDataInterval; + m_IntervalMs = SimpleDeviceOrientationDevice_Default_MinDataInterval; WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; @@ -246,13 +237,13 @@ GravityVectorDevice::Initialize( MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pProperties); if (!NT_SUCCESS(Status) || m_pProperties == nullptr) { - TraceError("GRA %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); + TraceError("LAC %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } @@ -264,7 +255,7 @@ GravityVectorDevice::Initialize( &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(GravityVectorDevice_Default_MinDataInterval, + InitPropVariantFromUInt32(SimpleDeviceOrientationDevice_Default_MinDataInterval, &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; @@ -272,7 +263,7 @@ GravityVectorDevice::Initialize( &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_GravityVector, + InitPropVariantFromCLSID(GUID_SensorType_SimpleDeviceOrientation, &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); } @@ -289,13 +280,13 @@ GravityVectorDevice::Initialize( MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pDataFieldProperties); if (!NT_SUCCESS(Status) || m_pDataFieldProperties == nullptr) { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } @@ -303,15 +294,15 @@ GravityVectorDevice::Initialize( m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(GravityVectorDevice_Axis_Resolution, + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Axis_Resolution, &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(GravityVectorDevice_Axis_Minimum, + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Axis_Minimum, &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(GravityVectorDevice_Axis_Maximum, + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Axis_Maximum, &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); } @@ -322,41 +313,31 @@ GravityVectorDevice::Initialize( WDF_OBJECT_ATTRIBUTES MemoryAttributes; WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GRAVITY_VECTOR_DATA_COUNT - 1); // Timestamp does not have thresholds + ULONG Size = SENSOR_COLLECTION_LIST_SIZE(LINEAR_ACCELEROMETER_DATA_COUNT - 2); // Timestamp and shake do not have thresholds MemoryHandle = NULL; WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); MemoryAttributes.ParentObject = SensorInstance; Status = WdfMemoryCreate(&MemoryAttributes, PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, Size, &MemoryHandle, (PVOID*)&m_pThresholds); if (!NT_SUCCESS(Status) || m_pThresholds == nullptr) { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); goto Exit; } SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = GRAVITY_VECTOR_DATA_COUNT - 1; - - m_pThresholds->List[GRAVITY_VECTOR_DATA_X].Key = PKEY_SensorData_AccelerationX_Gs; - InitPropVariantFromFloat(GravityVectorDevice_Default_Axis_Threshold, - &(m_pThresholds->List[GRAVITY_VECTOR_DATA_X].Value)); - - m_pThresholds->List[GRAVITY_VECTOR_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; - InitPropVariantFromFloat(GravityVectorDevice_Default_Axis_Threshold, - &(m_pThresholds->List[GRAVITY_VECTOR_DATA_Y].Value)); + m_pThresholds->Count = LINEAR_ACCELEROMETER_DATA_COUNT - 2; - m_pThresholds->List[GRAVITY_VECTOR_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; - InitPropVariantFromFloat(GravityVectorDevice_Default_Axis_Threshold, - &(m_pThresholds->List[GRAVITY_VECTOR_DATA_Z].Value)); + m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_X].Key = PKEY_SensorData_AccelerationX_Gs; + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, + &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_X].Value)); - m_CachedThresholds.X = GravityVectorDevice_Default_Axis_Threshold; - m_CachedThresholds.Y = GravityVectorDevice_Default_Axis_Threshold; - m_CachedThresholds.Z = GravityVectorDevice_Default_Axis_Threshold; + m_CachedThresholds.X = SimpleDeviceOrientationDevice_Default_Axis_Threshold; m_FirstSample = TRUE; } @@ -382,13 +363,16 @@ GravityVectorDevice::Initialize( // NTSTATUS code //------------------------------------------------------------------------------ NTSTATUS -GravityVectorDevice::GetData( +SimpleDeviceOrientationDevice::GetData( + _In_ HANDLE Device ) { BOOLEAN DataReady = FALSE; FILETIME TimeStamp = {0}; NTSTATUS Status = STATUS_SUCCESS; + UNREFERENCED_PARAMETER(Device); + SENSOR_FunctionEnter(); // new sample? @@ -398,7 +382,7 @@ GravityVectorDevice::GetData( if (!NT_SUCCESS(Status)) { m_StartTime = 0; - TraceError("COMBO %!FUNC! GRA GetPerformanceTime %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC GetPerformanceTime %!STATUS!", Status); } m_SampleCount = 0; @@ -409,9 +393,7 @@ GravityVectorDevice::GetData( { // Compare the change of data to threshold, and only push the data back to // clx if the change exceeds threshold. This is usually done in HW. - if ( (abs(m_CachedData.X - m_LastSample.X) >= m_CachedThresholds.X) || - (abs(m_CachedData.Y - m_LastSample.Y) >= m_CachedThresholds.Y) || - (abs(m_CachedData.Z - m_LastSample.Z) >= m_CachedThresholds.Z)) + if ( (abs(m_CachedData.X - m_LastSample.X) >= m_CachedThresholds.X)) { DataReady = TRUE; } @@ -421,16 +403,16 @@ GravityVectorDevice::GetData( { // update last sample m_LastSample.X = m_CachedData.X; - m_LastSample.Y = m_CachedData.Y; - m_LastSample.Z = m_CachedData.Z; + + m_LastSample.Shake = m_CachedData.Shake; // push to clx - InitPropVariantFromFloat(m_LastSample.X, &(m_pData->List[GRAVITY_VECTOR_DATA_X].Value)); - InitPropVariantFromFloat(m_LastSample.Y, &(m_pData->List[GRAVITY_VECTOR_DATA_Y].Value)); - InitPropVariantFromFloat(m_LastSample.Z, &(m_pData->List[GRAVITY_VECTOR_DATA_Z].Value)); + InitPropVariantFromFloat(m_LastSample.X, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_X].Value)); + + InitPropVariantFromBoolean(m_LastSample.Shake, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_SHAKE].Value)); GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[GRAVITY_VECTOR_DATA_TIMESTAMP].Value)); + InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].Value)); SensorsCxSensorDataReady(m_SensorInstance, m_pData); m_FirstSample = FALSE; @@ -438,7 +420,7 @@ GravityVectorDevice::GetData( else { Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! GRA Data did NOT meet the threshold"); + TraceInformation("COMBO %!FUNC! LAC Data did NOT meet the threshold"); } SENSOR_FunctionExit(Status); @@ -459,7 +441,7 @@ GravityVectorDevice::GetData( // NTSTATUS code //------------------------------------------------------------------------------ NTSTATUS -GravityVectorDevice::UpdateCachedThreshold( +SimpleDeviceOrientationDevice::UpdateCachedThreshold( ) { NTSTATUS Status = STATUS_SUCCESS; @@ -471,29 +453,11 @@ GravityVectorDevice::UpdateCachedThreshold( &m_CachedThresholds.X); if (!NT_SUCCESS(Status)) { - TraceError("COMBO %!FUNC! GRA PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AccelerationY_Gs, - &m_CachedThresholds.Y); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GRA PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AccelerationZ_Gs, - &m_CachedThresholds.Z); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GRA PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); + TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); goto Exit; } Exit: SENSOR_FunctionExit(Status); return Status; -} \ No newline at end of file +} diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/FrameworkSensors/linearaccelerometerclient.cpp similarity index 90% rename from SensorsComboDriver/linearaccelerometerclient.cpp rename to FrameworkSensors/linearaccelerometerclient.cpp index 036c294..6f9db5f 100644 --- a/SensorsComboDriver/linearaccelerometerclient.cpp +++ b/FrameworkSensors/linearaccelerometerclient.cpp @@ -9,6 +9,7 @@ // Windows User-Mode Driver Framework (UMDF) #include "Clients.h" +#include "EcCommunication.h" #include "LinearAccelerometerClient.tmh" @@ -123,15 +124,15 @@ LinearAccelerometerDevice::Initialize( m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_LinearAccelerometer, + InitPropVariantFromCLSID(GUID_SensorType_Accelerometer3D, &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", + InitPropVariantFromString(L"Framework Computer Inc", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Linear Accelerometer", + InitPropVariantFromString(L"Accelerometer", &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; @@ -387,6 +388,7 @@ LinearAccelerometerDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS LinearAccelerometerDevice::GetData( + _In_ HANDLE Handle ) { BOOLEAN DataReady = FALSE; @@ -395,6 +397,41 @@ LinearAccelerometerDevice::GetData( SENSOR_FunctionEnter(); + UINT8 acc_status = 0; + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_STATUS, &acc_status); + TraceInformation("Status: (%02x), Present: %d, Busy: %d\n", + acc_status, + (acc_status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT) > 0, + (acc_status & EC_MEMMAP_ACC_STATUS_BUSY_BIT) > 0); + + UINT8 lid_angle_bytes[2] = {0}; + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 0, &lid_angle_bytes[0]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 1, &lid_angle_bytes[1]); + UINT16 lid_angle = lid_angle_bytes[0] + (lid_angle_bytes[1] << 8); + TraceInformation("Lid Angle Status: %dDeg%s", lid_angle, lid_angle == 500 ? "(Unreliable)" : ""); + + UINT16 Sensor1[6] = {0}; + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 2, (UINT8*)&Sensor1[0]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 3, (UINT8*)&Sensor1[1]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 4, (UINT8*)&Sensor1[2]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 5, (UINT8*)&Sensor1[3]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 6, (UINT8*)&Sensor1[4]); + CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_DATA + 7, (UINT8*)&Sensor1[5]); + m_CachedData.Axis.X = (float) (Sensor1[0] + (Sensor1[1] << 8)); + m_CachedData.Axis.Y = (float) (Sensor1[2] + (Sensor1[3] << 8)); + m_CachedData.Axis.Z = (float) (Sensor1[4] + (Sensor1[5] << 8)); + #define quarter (0xFFFF/4) + m_CachedData.Axis.X = -((float) (INT16) m_CachedData.Axis.X) / quarter; + m_CachedData.Axis.Y = -((float) (INT16) m_CachedData.Axis.Y) / quarter; + m_CachedData.Axis.Z = -((float) (INT16) m_CachedData.Axis.Z) / quarter; + TraceInformation("Read Accel Value %02x %02x %02x %02x %02x %02x - x: %f, y: %f, z: %f\n", + Sensor1[0], Sensor1[1], + Sensor1[2], Sensor1[3], + Sensor1[4], Sensor1[5], + m_CachedData.Axis.X, + m_CachedData.Axis.Y, + m_CachedData.Axis.Z); + // new sample? if (m_FirstSample != FALSE) { diff --git a/README.md b/README.md index 99d5e6e..63c6378 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ # framework-win-sensor-driver Sensor Driver for Windows on Framework systems + +``` +# Build +msbuild .\SensorsComboDriver\SensorsComboDriver.sln /property:Platform=x64 /property:Configuration=Debug + +# Distributing +.\SensorsComboDriver\x64\Debug\ + SensorsComboDriver.pdb + SensorsComboDriver\sensorscombodriver.cat + SensorsComboDriver\sensorscombodriver.dll + SensorsComboDriver\sensorscombodriver.inf +# Use signtool to sign .cat file and package all 4 files + +# Install +> sudo pnputil /add-driver SensorsComboDriver.inf /install + +``` + +Check if the driver is installed and loaded: + +``` +# Framework EC driver +> pnputil /enum-devices /deviceid "acpi\frmwc004" +Microsoft PnP Utility + +Instance ID: ACPI\FRMWC004\1 +Device Description: Framework EC +Class Name: System +Class GUID: {4d36e97d-e325-11ce-bfc1-08002be10318} +Manufacturer Name: Framework +Status: Started +Driver Name: oem2.inf + +# Sensor driver +> pnputil /enum-devices /deviceid "acpi\frmwc006" +Microsoft PnP Utility + +Instance ID: ACPI\FRMWC006\1 +Device Description: Sensor Driver - ALS, Accelerometer, Orientation +Class Name: Sensor +Class GUID: {5175d334-c371-4806-b3ba-71fd53c9258d} +Manufacturer Name: Framework Computer Inc +Status: Started +Driver Name: oem194.inf +``` diff --git a/SensorsComboDriver/BarClient.cpp b/SensorsComboDriver/BarClient.cpp deleted file mode 100644 index 97135c5..0000000 --- a/SensorsComboDriver/BarClient.cpp +++ /dev/null @@ -1,464 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#include "Clients.h" - -#include "BarClient.tmh" - -#define SENSORV2_POOL_TAG_BAROMETER '2RaB' - -#define Bar_Initial_MinDataInterval_Ms (10) // 100Hz -#define Bar_Initial_Threshold_Bar (0.001f) // 1 mBar ~= 10 meter - -#define BarDevice_Minimum_Bar (0.3f) -#define BarDevice_Maximum_Bar (1.1f) -#define BarDevice_Precision (65536.0f) // 65536 = 2^16, 16 bit data -#define BarDevice_Range_Bar (BarDevice_Maximum_Bar - BarDevice_Minimum_Bar) -#define BarDevice_Resolution_Bar (BarDevice_Range_Bar / BarDevice_Precision) - -// Barometer Unique ID -// {46CB48CE-272D-4402-8E09-07748F8940CA} -DEFINE_GUID(GUID_BarDevice_UniqueID, - 0x46cb48ce, 0x272d, 0x4402, 0x8e, 0x9, 0x7, 0x74, 0x8f, 0x89, 0x40, 0xca); - -// Sensor data -typedef enum -{ - BAR_DATA_TIMESTAMP = 0, - BAR_DATA_PRESSURE, - BAR_DATA_COUNT -} BAR_DATA_INDEX; - -// Sensor thresholds -typedef enum -{ - BAR_THRESHOLD_PRESSURE = 0, - BAR_THRESHOLD_COUNT -} BAR_THRESHOLD_INDEX; - - - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -BarDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! BAR WdfWaitLockCreate failed %!STATUS!", Status); - } - - // - // Create timer object for polling sensor samples - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! BAR WdfTimerCreate failed %!STATUS!", Status); - } - } - - // - // Sensor Enumeration Properties - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEnumerationProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Barometer, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Barometer", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_BarDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - } - } - - // - // Supported Data-Fields - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(BAR_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pSupportedDataFields)); - if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = BAR_DATA_COUNT; - - m_pSupportedDataFields->List[BAR_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[BAR_DATA_PRESSURE] = PKEY_SensorData_AtmosphericPressure_Bars; - } - } - - // - // Data - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(BAR_DATA_COUNT); - FILETIME Time = {}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pData)); - if (!NT_SUCCESS(Status) || nullptr == m_pData) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = BAR_DATA_COUNT; - - m_pData->List[BAR_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[BAR_DATA_TIMESTAMP].Value)); - - m_pData->List[BAR_DATA_PRESSURE].Key = PKEY_SensorData_AtmosphericPressure_Bars; - InitPropVariantFromFloat(0.0f, &(m_pData->List[BAR_DATA_PRESSURE].Value)); - - m_CachedData = 1.013f; - m_LastSample = 0.0f; - } - } - - // - // Sensor Properties - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pProperties) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(Bar_Initial_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = Bar_Initial_MinDataInterval_Ms; - m_MinimumIntervalMs = Bar_Initial_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Barometer, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - } - - // - // Data filed properties - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pDataFieldProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(BarDevice_Resolution_Bar, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(BarDevice_Minimum_Bar, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(BarDevice_Maximum_Bar, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - } - - // - // Set default threshold - // - if (NT_SUCCESS(Status)) - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(BAR_THRESHOLD_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_BAROMETER, - Size, - &MemoryHandle, - reinterpret_cast(&m_pThresholds)); - if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) - { - TraceError("COMBO %!FUNC! BAR WdfMemoryCreate failed %!STATUS!", Status); - } - else - { - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = BAR_THRESHOLD_COUNT; - - m_pThresholds->List[BAR_THRESHOLD_PRESSURE].Key = PKEY_SensorData_AtmosphericPressure_Bars; - InitPropVariantFromFloat(Bar_Initial_Threshold_Bar, - &(m_pThresholds->List[BAR_THRESHOLD_PRESSURE].Value)); - - m_CachedThresholds = Bar_Initial_Threshold_Bar; - m_FirstSample = TRUE; - } - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -BarDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (FALSE != m_FirstSample) - { - Status = GetPerformanceTime (&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! BAR GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of data to threshold, and only push the data back to - // clx if the change exceeds threshold. This is usually done in HW. - if ((abs(m_CachedData - m_LastSample) >= m_CachedThresholds)) - { - DataReady = TRUE; - } - } - - if (FALSE != DataReady) - { - // update last sample - m_LastSample = m_CachedData; - - // push to clx - InitPropVariantFromFloat(m_LastSample, &(m_pData->List[BAR_DATA_PRESSURE].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[BAR_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! BAR Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -BarDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_UNSUCCESSFUL; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AtmosphericPressure_Bars, - &m_CachedThresholds); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! BAR PropKeyFindKeyGetFloat for pressure failed %!STATUS!", Status); - } - - SENSOR_FunctionExit(Status); - return Status; -} \ No newline at end of file diff --git a/SensorsComboDriver/GeomagneticOrientationClient.cpp b/SensorsComboDriver/GeomagneticOrientationClient.cpp deleted file mode 100644 index b20339a..0000000 --- a/SensorsComboDriver/GeomagneticOrientationClient.cpp +++ /dev/null @@ -1,485 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (WUDF) - -#include "Clients.h" - -#include "GeomagneticOrientationClient.tmh" - -#define SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION '9OeG' - -#define GeomagneticOrientation_Initial_MinDataInterval_Ms (10) // 100Hz - -#define GeomagneticOrientation_Quarternion_Maximum (1.0f) -#define GeomagneticOrientation_Quarternion_Minimum (-1.0f) -#define GeomagneticOrientation_Quarternion_Resolution ((GeomagneticOrientation_Quarternion_Maximum-GeomagneticOrientation_Quarternion_Minimum)/65536) - -// Geomagnetic Orientation Sensor Unique ID -// {E4F5FDEA-F268-480F-9D88-A368D381C4C2} -DEFINE_GUID(GUID_GeomagneticOrientationDevice_UniqueID, - 0xe4f5fdea, 0xf268, 0x480f, 0x9d, 0x88, 0xa3, 0x68, 0xd3, 0x81, 0xc4, 0xc2); - -// Sensor data -typedef enum -{ - GEOMAGNETIC_ORIENTATION_DATA_TIMESTAMP = 0, - GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_W, - GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_X, - GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Y, - GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Z, - GEOMAGNETIC_ORIENTATION_DATA_ROTATION_ANGLE_DEGREES, - GEOMAGNETIC_ORIENTATION_DATA_DECLINATION_ANGLE_DEGREES, - GEOMAGNETIC_ORIENTATION_DATA_COUNT -} GEOMAGNETIC_ORIENTATION_DATA_INDEX; - -// Sensor thresholds -typedef enum -{ - GEOMAGNETIC_ORIENTATION_THRESHOLD_ROTATION_ANGLES_DEGREES = 0, - GEOMAGNETIC_ORIENTATION_THRESHOLD_COUNT -} GEOMAGNETIC_ORIENTATION_THRESHOLD_INDEX; - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GeomagneticOrientationDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! Geomagnetic Orientation WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEnumerationProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_GeomagneticOrientation, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Geomagnetic Orientation Sensor", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_GeomagneticOrientationDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - } - - // - // Supported Data-Fields - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(GEOMAGNETIC_ORIENTATION_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pSupportedDataFields)); - if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = GEOMAGNETIC_ORIENTATION_DATA_COUNT; - - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_W] = PKEY_SensorData_QuaternionW; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_X] = PKEY_SensorData_QuaternionX; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Y] = PKEY_SensorData_QuaternionY; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Z] = PKEY_SensorData_QuaternionZ; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_ROTATION_ANGLE_DEGREES] = PKEY_SensorData_RotationAngle_Degrees; - m_pSupportedDataFields->List[GEOMAGNETIC_ORIENTATION_DATA_DECLINATION_ANGLE_DEGREES] = PKEY_SensorData_DeclinationAngle_Degrees; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GEOMAGNETIC_ORIENTATION_DATA_COUNT); - FILETIME Time = {0}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pData)); - if (!NT_SUCCESS(Status) || nullptr == m_pData) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = GEOMAGNETIC_ORIENTATION_DATA_COUNT; - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_TIMESTAMP].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_W].Key = PKEY_SensorData_QuaternionW; - InitPropVariantFromFloat(1.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_W].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_X].Key = PKEY_SensorData_QuaternionX; - InitPropVariantFromFloat(0.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_X].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Y].Key = PKEY_SensorData_QuaternionY; - InitPropVariantFromFloat(0.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Y].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Z].Key = PKEY_SensorData_QuaternionZ; - InitPropVariantFromFloat(0.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Z].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_ROTATION_ANGLE_DEGREES].Key = PKEY_SensorData_RotationAngle_Degrees; - InitPropVariantFromFloat(0.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_ROTATION_ANGLE_DEGREES].Value)); - - m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_DECLINATION_ANGLE_DEGREES].Key = PKEY_SensorData_DeclinationAngle_Degrees; - InitPropVariantFromFloat(0.0, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_DECLINATION_ANGLE_DEGREES].Value)); - - ZeroMemory(&m_LastSample, sizeof(m_LastSample)); - ZeroMemory(&m_CachedData, sizeof(m_CachedData)); - m_CachedData.Quaternion.W = 1.0f; // This is the initial position - m_CachedData.Quaternion.X = 0.0f; // This is the initial position - m_CachedData.Quaternion.Y = 0.0f; // This is the initial position - m_CachedData.Quaternion.Z = 0.0f; // This is the initial position - m_CachedData.RotationAngle_Degrees = 0.0f; // This is the initial position - m_CachedData.DeclinationAngle_Degrees = 0.0f; // This is the initial position - } - - // - // Sensor Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pProperties) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(GeomagneticOrientation_Initial_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = GeomagneticOrientation_Initial_MinDataInterval_Ms; - m_MinimumIntervalMs = GeomagneticOrientation_Initial_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_GeomagneticOrientation, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - - // - // Data filed properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pDataFieldProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(GeomagneticOrientation_Quarternion_Resolution, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(GeomagneticOrientation_Quarternion_Minimum, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(GeomagneticOrientation_Quarternion_Maximum, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GEOMAGNETIC_ORIENTATION_THRESHOLD_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GEOMAGNETIC_ORIENTATION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pThresholds)); - if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = GEOMAGNETIC_ORIENTATION_THRESHOLD_COUNT; - - m_pThresholds->List[GEOMAGNETIC_ORIENTATION_THRESHOLD_ROTATION_ANGLES_DEGREES].Key = PKEY_SensorData_RotationAngle_Degrees; - InitPropVariantFromFloat(0.0f, &(m_pThresholds->List[GEOMAGNETIC_ORIENTATION_THRESHOLD_ROTATION_ANGLES_DEGREES].Value)); - - ZeroMemory(&m_CachedThresholds, sizeof(m_CachedThresholds)); - m_FirstSample = TRUE; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GeomagneticOrientationDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {0}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (FALSE != m_FirstSample) - { - Status = GetPerformanceTime (&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of data to threshold, and only push the data back to - // clx if the change exceeds threshold. This is usually done in HW. - if ((abs(m_CachedData.RotationAngle_Degrees - m_LastSample.RotationAngle_Degrees) >= m_CachedThresholds.RotationAngle_Degrees)) - { - DataReady = TRUE; - } - } - - if (FALSE != DataReady) - { - // update last sample - m_LastSample = m_CachedData; - - // push to clx - InitPropVariantFromFloat(m_LastSample.Quaternion.W, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_W].Value)); - InitPropVariantFromFloat(m_LastSample.Quaternion.X, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_X].Value)); - InitPropVariantFromFloat(m_LastSample.Quaternion.Y, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Y].Value)); - InitPropVariantFromFloat(m_LastSample.Quaternion.Z, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_QUATERNION_Z].Value)); - InitPropVariantFromFloat(m_LastSample.RotationAngle_Degrees, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_ROTATION_ANGLE_DEGREES].Value)); - InitPropVariantFromFloat(m_LastSample.DeclinationAngle_Degrees, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_DECLINATION_ANGLE_DEGREES].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[GEOMAGNETIC_ORIENTATION_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! GeomagneticOrientationDevice Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GeomagneticOrientationDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_UNSUCCESSFUL; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_RotationAngle_Degrees, - &m_CachedThresholds.RotationAngle_Degrees); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GeomagneticOrientationDevice PropKeyFindKeyGetFloat for Rotation Angle failed! %!STATUS!", Status); - goto Exit; - } -Exit: - SENSOR_FunctionExit(Status); - return Status; -} \ No newline at end of file diff --git a/SensorsComboDriver/GyrClient.cpp b/SensorsComboDriver/GyrClient.cpp deleted file mode 100644 index 389e6e8..0000000 --- a/SensorsComboDriver/GyrClient.cpp +++ /dev/null @@ -1,510 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (WUDF) - -#include "Clients.h" - -#include "GyrClient.tmh" - -#define SENSORV2_POOL_TAG_GYROSCOPE '2oyG' - -// Chasis says 5-250Hz but unit test fails if below 250Hz??? -#define Gyr_MinDataInterval_Ms (4) // 250Hz -#define Gyr_Initial_Threshold_DegreesPerSecond (10.0f) - -#define GyrDevice_Minimum_DegreesPerSecond (-2000.0f) -#define GyrDevice_Maximum_DegreesPerSecond (2000.0f) -#define GyrDevice_Precision (65536.0f) // 65536 = 2^16, 16 bit data -#define GyrDevice_Range_DegreesPerSecond \ - (GyrDevice_Maximum_DegreesPerSecond - GyrDevice_Minimum_DegreesPerSecond) -#define GyrDevice_Resolution_DegreesPerSecond \ - (GyrDevice_Range_DegreesPerSecond / GyrDevice_Precision) - -// Gyroscope Unique ID -// {61A61B96-1E4C-47C6-8697-654680101446} -DEFINE_GUID(GUID_GyrDevice_UniqueID, - 0x61a61b96, 0x1e4c, 0x47c6, 0x86, 0x97, 0x65, 0x46, 0x80, 0x10, 0x14, 0x46); - -// Sensor data -typedef enum -{ - GYR_DATA_TIMESTAMP = 0, - GYR_DATA_X, - GYR_DATA_Y, - GYR_DATA_Z, - GYR_DATA_COUNT -} GYR_DATA_INDEX; - -// Sensor thresholds -typedef enum -{ - GYR_THRESHOLD_X = 0, - GYR_THRESHOLD_Y, - GYR_THRESHOLD_Z, - GYR_THRESHOLD_COUNT -} GYR_THRESHOLD_INDEX; - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GyrDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - TimerConfig.TolerableDelay = 0; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pEnumerationProperties); - if (!NT_SUCCESS(Status) || m_pEnumerationProperties == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Gyrometer3D, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"GYR", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_GyrDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - } - - // - // Supported Data-Fields - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(GYR_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pSupportedDataFields); - if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = GYR_DATA_COUNT; - - m_pSupportedDataFields->List[GYR_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[GYR_DATA_X] = PKEY_SensorData_AngularVelocityX_DegreesPerSecond; - m_pSupportedDataFields->List[GYR_DATA_Y] = PKEY_SensorData_AngularVelocityY_DegreesPerSecond; - m_pSupportedDataFields->List[GYR_DATA_Z] = PKEY_SensorData_AngularVelocityZ_DegreesPerSecond; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GYR_DATA_COUNT); - FILETIME Time = {0}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pData); - if (!NT_SUCCESS(Status) || m_pData == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = GYR_DATA_COUNT; - - m_pData->List[GYR_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[GYR_DATA_TIMESTAMP].Value)); - - m_pData->List[GYR_DATA_X].Key = PKEY_SensorData_AngularVelocityX_DegreesPerSecond; - InitPropVariantFromFloat(0.0f, &(m_pData->List[GYR_DATA_X].Value)); - - m_pData->List[GYR_DATA_Y].Key = PKEY_SensorData_AngularVelocityY_DegreesPerSecond; - InitPropVariantFromFloat(0.0f, &(m_pData->List[GYR_DATA_Y].Value)); - - m_pData->List[GYR_DATA_Z].Key = PKEY_SensorData_AngularVelocityZ_DegreesPerSecond; - InitPropVariantFromFloat(0.0f, &(m_pData->List[GYR_DATA_Z].Value)); - - m_CachedData.X = 0.0f; - m_CachedData.Y = 0.0f; - m_CachedData.Z = 0.0f; - - m_LastSample.X = 0.0f; - m_LastSample.Y = 0.0f; - m_LastSample.Z = 0.0f; - } - - // - // Sensor Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pProperties); - if (!NT_SUCCESS(Status) || m_pProperties == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(Gyr_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = Gyr_MinDataInterval_Ms; - m_MinimumIntervalMs = Gyr_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Gyrometer3D, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - - // - // Data filed properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pDataFieldProperties); - if (!NT_SUCCESS(Status) || m_pDataFieldProperties == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(GyrDevice_Resolution_DegreesPerSecond, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(GyrDevice_Minimum_DegreesPerSecond, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(GyrDevice_Maximum_DegreesPerSecond, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GYR_THRESHOLD_COUNT); // Timestamp and shake do not have thresholds - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GYROSCOPE, - Size, - &MemoryHandle, - (PVOID*)&m_pThresholds); - if (!NT_SUCCESS(Status) || m_pThresholds == nullptr) - { - TraceError("COMBO %!FUNC! GYR WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = GYR_THRESHOLD_COUNT; - - m_pThresholds->List[GYR_THRESHOLD_X].Key = PKEY_SensorData_AngularVelocityX_DegreesPerSecond; - InitPropVariantFromFloat(Gyr_Initial_Threshold_DegreesPerSecond, - &(m_pThresholds->List[GYR_THRESHOLD_X].Value)); - - m_pThresholds->List[GYR_THRESHOLD_Y].Key = PKEY_SensorData_AngularVelocityY_DegreesPerSecond; - InitPropVariantFromFloat(Gyr_Initial_Threshold_DegreesPerSecond, - &(m_pThresholds->List[GYR_THRESHOLD_Y].Value)); - - m_pThresholds->List[GYR_THRESHOLD_Z].Key = PKEY_SensorData_AngularVelocityZ_DegreesPerSecond; - InitPropVariantFromFloat(Gyr_Initial_Threshold_DegreesPerSecond, - &(m_pThresholds->List[GYR_THRESHOLD_Z].Value)); - - m_CachedThresholds.X = Gyr_Initial_Threshold_DegreesPerSecond; - m_CachedThresholds.Y = Gyr_Initial_Threshold_DegreesPerSecond; - m_CachedThresholds.Z = Gyr_Initial_Threshold_DegreesPerSecond; - - m_FirstSample = TRUE; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GyrDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {0}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (m_FirstSample != FALSE) - { - Status = GetPerformanceTime (&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! GYR GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of data to threshold, and only push the data back to - // clx if the change exceeds threshold. This is usually done in HW. - if ( (abs(m_CachedData.X - m_LastSample.X) >= m_CachedThresholds.X) || - (abs(m_CachedData.Y - m_LastSample.Y) >= m_CachedThresholds.Y) || - (abs(m_CachedData.Z - m_LastSample.Z) >= m_CachedThresholds.Z)) - { - DataReady = TRUE; - } - } - - if (DataReady != FALSE) - { - // update last sample - m_LastSample.X = m_CachedData.X; - m_LastSample.Y = m_CachedData.Y; - m_LastSample.Z = m_CachedData.Z; - - // push to clx - InitPropVariantFromFloat(m_LastSample.X, &(m_pData->List[GYR_DATA_X].Value)); - InitPropVariantFromFloat(m_LastSample.Y, &(m_pData->List[GYR_DATA_Y].Value)); - InitPropVariantFromFloat(m_LastSample.Z, &(m_pData->List[GYR_DATA_Z].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[GYR_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! GYR Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -GyrDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AngularVelocityX_DegreesPerSecond, - &m_CachedThresholds.X); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AngularVelocityY_DegreesPerSecond, - &m_CachedThresholds.Y); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AngularVelocityZ_DegreesPerSecond, - &m_CachedThresholds.Z); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); - goto Exit; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} \ No newline at end of file diff --git a/SensorsComboDriver/MagClient.cpp b/SensorsComboDriver/MagClient.cpp deleted file mode 100644 index 5768cbc..0000000 --- a/SensorsComboDriver/MagClient.cpp +++ /dev/null @@ -1,537 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (WUDF) - -#include "Clients.h" - -#include "MagClient.tmh" - -#define SENSORV2_POOL_TAG_MAGNETOMETER '2ngM' - -#define Mag_Initial_MinDataInterval_Ms (10) // 100Hz -#define Mag_Initial_Threshold_Microteslas (5.0f) // 5uT - -#define MagDevice_Minimum_Microteslas (-2000.0f) -#define MagDevice_Maximum_Microteslas (2000.0f) -#define MagDevice_Precision (65536.0f) // 65536 = 2^16, 16 bit data -#define MagDevice_Range_Microteslas \ - (MagDevice_Maximum_Microteslas - MagDevice_Minimum_Microteslas) -#define MagDevice_Resolution_Microteslas \ - (MagDevice_Range_Microteslas / MagDevice_Precision) - -// Magnetometer Sensor Unique ID -// {0746712D-DFB1-42A7-8AAE-6089D2423CDE} -DEFINE_GUID(GUID_MagDevice_UniqueID, - 0x746712d, 0xdfb1, 0x42a7, 0x8a, 0xae, 0x60, 0x89, 0xd2, 0x42, 0x3c, 0xde); - -// Sensor data -typedef enum -{ - MAG_DATA_TIMESTAMP = 0, - MAG_DATA_X, - MAG_DATA_Y, - MAG_DATA_Z, - MAG_DATA_ACCURACY, - MAG_DATA_COUNT -} MAG_DATA_INDEX; - -// Sensor thresholds -typedef enum -{ - MAG_THRESHOLD_X = 0, - MAG_THRESHOLD_Y, - MAG_THRESHOLD_Z, - MAG_THRESHOLD_COUNT -} MAG_THRESHOLD_INDEX; - -// -// Sensor Enumeration Properties -// -typedef enum -{ - SENSOR_MAG_NAME = SENSOR_ENUMERATION_PROPERTIES_COUNT, // SENSOR_MAG_ENUMERATION_PROPERTIES_INDEX is adding SENSOR_MAG_NAME to the base SENSOR_ENUMERATION_PROPERTIES_INDEX enum. - // In order to keep the SENSOR_MAG_ENUMERATION_PROPERTIES_INDEX enum indexing coherent with the SENSOR_ENUMERATION_PROPERTIES_INDEX enum, - // set SENSOR_MAG_NAME to the index of the last value in the SENSOR_ENUMERATION_PROPERTIES_INDEX enum - SENSOR_MAG_ENUMERATION_PROPERTIES_COUNT -} SENSOR_MAG_ENUMERATION_PROPERTIES_INDEX; - - - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -MagDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! GYR WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! MAG WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_MAG_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pEnumerationProperties); - if (!NT_SUCCESS(Status) || m_pEnumerationProperties == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_MAG_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Magnetometer3D, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"MAG", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_MagDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - // - // Alternate name used by SensorOpen - // - - m_pEnumerationProperties->List[SENSOR_MAG_NAME].Key = DEVPKEY_Sensor_Name; - InitPropVariantFromString(L"\\\\.\\Mag", - &(m_pEnumerationProperties->List[SENSOR_MAG_NAME].Value)); - } - - // - // Supported Data-Fields - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(MAG_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pSupportedDataFields); - if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = MAG_DATA_COUNT; - - m_pSupportedDataFields->List[MAG_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[MAG_DATA_X] = PKEY_SensorData_MagneticFieldStrengthX_Microteslas; - m_pSupportedDataFields->List[MAG_DATA_Y] = PKEY_SensorData_MagneticFieldStrengthY_Microteslas; - m_pSupportedDataFields->List[MAG_DATA_Z] = PKEY_SensorData_MagneticFieldStrengthZ_Microteslas; - m_pSupportedDataFields->List[MAG_DATA_ACCURACY] = PKEY_SensorData_MagnetometerAccuracy; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(MAG_DATA_COUNT); - FILETIME Time = {0}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pData); - if (!NT_SUCCESS(Status) || m_pData == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = MAG_DATA_COUNT; - - m_pData->List[MAG_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[MAG_DATA_TIMESTAMP].Value)); - - m_pData->List[MAG_DATA_X].Key = PKEY_SensorData_MagneticFieldStrengthX_Microteslas; - InitPropVariantFromFloat(0.0f, &(m_pData->List[MAG_DATA_X].Value)); - - m_pData->List[MAG_DATA_Y].Key = PKEY_SensorData_MagneticFieldStrengthY_Microteslas; - InitPropVariantFromFloat(0.0f, &(m_pData->List[MAG_DATA_Y].Value)); - - m_pData->List[MAG_DATA_Z].Key = PKEY_SensorData_MagneticFieldStrengthZ_Microteslas; - InitPropVariantFromFloat(0.0f, &(m_pData->List[MAG_DATA_Z].Value)); - - m_pData->List[MAG_DATA_ACCURACY].Key = PKEY_SensorData_MagnetometerAccuracy; - InitPropVariantFromUInt32(MagnetometerAccuracy_Unknown, &(m_pData->List[MAG_DATA_ACCURACY].Value)); - - m_CachedData.Axis.X = 0.0f; - m_CachedData.Axis.Y = 1.0f; - m_CachedData.Axis.Z = 0.0f; - m_CachedData.Accuracy = MagnetometerAccuracy_High; - - m_LastSample.Axis.X = 0.0f; - m_LastSample.Axis.Y = 0.0f; - m_LastSample.Axis.Z = 0.0f; - m_LastSample.Accuracy = MagnetometerAccuracy_Unknown; - } - - // - // Sensor Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pProperties); - if (!NT_SUCCESS(Status) || m_pProperties == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(Mag_Initial_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = Mag_Initial_MinDataInterval_Ms; - m_MinimumIntervalMs = Mag_Initial_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Magnetometer3D, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - - // - // Data field properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pDataFieldProperties); - if (!NT_SUCCESS(Status) || m_pDataFieldProperties == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(MagDevice_Resolution_Microteslas, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(MagDevice_Minimum_Microteslas, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(MagDevice_Maximum_Microteslas, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(MAG_THRESHOLD_COUNT); // Timestamp and shake do not have thresholds - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_MAGNETOMETER, - Size, - &MemoryHandle, - (PVOID*)&m_pThresholds); - if (!NT_SUCCESS(Status) || m_pThresholds == nullptr) - { - TraceError("COMBO %!FUNC! MAG WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = MAG_THRESHOLD_COUNT; - - m_pThresholds->List[MAG_THRESHOLD_X].Key = PKEY_SensorData_MagneticFieldStrengthX_Microteslas; - InitPropVariantFromFloat(Mag_Initial_Threshold_Microteslas, - &(m_pThresholds->List[MAG_THRESHOLD_X].Value)); - - m_pThresholds->List[MAG_THRESHOLD_Y].Key = PKEY_SensorData_MagneticFieldStrengthY_Microteslas; - InitPropVariantFromFloat(Mag_Initial_Threshold_Microteslas, - &(m_pThresholds->List[MAG_THRESHOLD_Y].Value)); - - m_pThresholds->List[MAG_THRESHOLD_Z].Key = PKEY_SensorData_MagneticFieldStrengthZ_Microteslas; - InitPropVariantFromFloat(Mag_Initial_Threshold_Microteslas, - &(m_pThresholds->List[MAG_THRESHOLD_Z].Value)); - - m_CachedThresholds.X = Mag_Initial_Threshold_Microteslas; - m_CachedThresholds.Y = Mag_Initial_Threshold_Microteslas; - m_CachedThresholds.Z = Mag_Initial_Threshold_Microteslas; - - m_FirstSample = TRUE; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -MagDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {0}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (m_FirstSample != FALSE) - { - Status = GetPerformanceTime (&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! MAG GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of data to threshold, and only push the data back to - // clx if the change exceeds threshold. This is usually done in HW. - if ( (abs(m_CachedData.Axis.X - m_LastSample.Axis.X) >= m_CachedThresholds.X) || - (abs(m_CachedData.Axis.Y - m_LastSample.Axis.Y) >= m_CachedThresholds.Y) || - (abs(m_CachedData.Axis.Z - m_LastSample.Axis.Z) >= m_CachedThresholds.Z)) - { - DataReady = TRUE; - } - } - - if (DataReady != FALSE) - { - // update last sample - m_LastSample.Axis.X = m_CachedData.Axis.X; - m_LastSample.Axis.Y = m_CachedData.Axis.Y; - m_LastSample.Axis.Z = m_CachedData.Axis.Z; - m_LastSample.Accuracy = m_CachedData.Accuracy; - - // push to clx - InitPropVariantFromFloat (m_LastSample.Axis.X, &(m_pData->List[MAG_DATA_X].Value)); - InitPropVariantFromFloat (m_LastSample.Axis.Y, &(m_pData->List[MAG_DATA_Y].Value)); - InitPropVariantFromFloat (m_LastSample.Axis.Z, &(m_pData->List[MAG_DATA_Z].Value)); - InitPropVariantFromUInt32(m_LastSample.Accuracy, &(m_pData->List[MAG_DATA_ACCURACY].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[MAG_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! MAG Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -MagDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_MagneticFieldStrengthX_Microteslas, - &m_CachedThresholds.X); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! MAG PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_MagneticFieldStrengthY_Microteslas, - &m_CachedThresholds.Y); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! MAG PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_MagneticFieldStrengthZ_Microteslas, - &m_CachedThresholds.Z); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! MAG PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); - goto Exit; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} \ No newline at end of file diff --git a/SensorsComboDriver/PrxClient.cpp b/SensorsComboDriver/PrxClient.cpp deleted file mode 100644 index fa10e09..0000000 --- a/SensorsComboDriver/PrxClient.cpp +++ /dev/null @@ -1,458 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (WUDF) - -#include "Clients.h" - -#include "PrxClient.tmh" - -#define SENSORV2_POOL_TAG_PROXIMITY '2ixP' - -static const ULONG Prx_MinDataInterval_Ms = 10; // 100Hz - -static const ULONG PrxDevice_Minimum_Millimeters = 3; -static const ULONG PrxDevice_Maximum_Millimeters = 50; -static const ULONG PrxDevice_Resolution_Millimeters = 1; - -// Proximity Sensor Unique ID -// {4B6BE805-2432-4B6B-A5E3-DEA67CA43225} -DEFINE_GUID(GUID_PrxDevice_UniqueID, - 0x4b6be805, 0x2432, 0x4b6b, 0xa5, 0xe3, 0xde, 0xa6, 0x7c, 0xa4, 0x32, 0x25); - -// Sensor data -typedef enum -{ - PRX_DATA_TIMESTAMP = 0, - PRX_DATA_DETECT, - PRX_DATA_DISTANCE, - PRX_DATA_COUNT -} PRX_DATA_INDEX; - -static const ULONG PRX_THRESHOLD_COUNT = 0; // proxmity sensor has no threshold - -// -// Additional Sensor Properties -// -typedef enum -{ - SENSOR_PROPERTY_PRX_TYPE = SENSOR_ENUMERATION_PROPERTIES_COUNT, // SENSOR_PRX_PROPERTIES_INDEX is adding SENSOR_PROPERTY_PRX_TYPE to the base SENSOR_PROPERTIES_INDEX enum. - // In order to keep the SENSOR_PRX_PROPERTIES_INDEX enum indexing coherent with the SENSOR_PROPERTIES_INDEX enum, - // set SENSOR_PROPERTY_PRX_TYPE to the index of the last value in the SENSOR_PROPERTIES_INDEX enum - SENSOR_ISWAKECAPABLE = SENSOR_PROPERTY_PRX_TYPE + 1, - SENSOR_PRX_ENUMERATION_PROPERTY_COUNT -} SENSOR_PRX_PROPERTIES_INDEX; - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -PrxDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! PRX WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! PRX WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_PRX_ENUMERATION_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEnumerationProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - m_pEnumerationProperties->Count = SENSOR_PRX_ENUMERATION_PROPERTY_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Proximity, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"PRX", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_PrxDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - - m_pEnumerationProperties->List[SENSOR_PROPERTY_PRX_TYPE].Key = DEVPKEY_Sensor_ProximityType; - InitPropVariantFromUInt32(PROXIMITY_TYPE::ProximityType_HumanProximity, - &(m_pEnumerationProperties->List[SENSOR_PROPERTY_PRX_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_ISWAKECAPABLE].Key = PKEY_Sensor_WakeCapable; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISWAKECAPABLE].Value)); - - } - - // - // Supported Data-Fields - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(PRX_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - (PVOID*)&m_pSupportedDataFields); - if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = PRX_DATA_COUNT; - - m_pSupportedDataFields->List[PRX_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[PRX_DATA_DETECT] = PKEY_SensorData_ProximityDetection; - m_pSupportedDataFields->List[PRX_DATA_DISTANCE] = PKEY_SensorData_ProximityDistanceMillimeters; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(PRX_DATA_COUNT); - FILETIME Time = {}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - reinterpret_cast(&m_pData)); - if (!NT_SUCCESS(Status) || nullptr == m_pData) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = PRX_DATA_COUNT; - - m_pData->List[PRX_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[PRX_DATA_TIMESTAMP].Value)); - - m_pData->List[PRX_DATA_DETECT].Key = PKEY_SensorData_ProximityDetection; - InitPropVariantFromBoolean(FALSE, &(m_pData->List[PRX_DATA_DETECT].Value)); - - m_pData->List[PRX_DATA_DISTANCE].Key = PKEY_SensorData_ProximityDistanceMillimeters; - InitPropVariantFromUInt32(FALSE, &(m_pData->List[PRX_DATA_DISTANCE].Value)); - - m_CachedData.Detected = FALSE; - m_CachedData.DistanceMillimeters = PrxDevice_Maximum_Millimeters; - - m_LastSample.Detected = FALSE; - m_LastSample.DistanceMillimeters = PrxDevice_Maximum_Millimeters; - } - - // - // Sensor Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - reinterpret_cast(&m_pProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pProperties) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(Prx_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = Prx_MinDataInterval_Ms; - m_MinimumIntervalMs = Prx_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_Proximity, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - - // - // Data field properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - reinterpret_cast(&m_pDataFieldProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromUInt32(PrxDevice_Resolution_Millimeters, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromUInt32(PrxDevice_Minimum_Millimeters, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromUInt32(PrxDevice_Maximum_Millimeters, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(PRX_THRESHOLD_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_PROXIMITY, - Size, - &MemoryHandle, - reinterpret_cast(&m_pThresholds)); - if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) - { - TraceError("COMBO %!FUNC! PRX WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - - m_FirstSample = TRUE; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -PrxDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {0}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (m_FirstSample != FALSE) - { - Status = GetPerformanceTime(&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! PRX GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of detection state, and only push the data back to - // clx. This is usually done in HW. - if (m_CachedData.Detected != m_LastSample.Detected) - { - DataReady = TRUE; - } - } - - if (DataReady != FALSE) - { - // update last sample - m_LastSample = m_CachedData; - - // push to clx - InitPropVariantFromBoolean(m_LastSample.Detected, &(m_pData->List[PRX_DATA_DETECT].Value)); - InitPropVariantFromUInt32(m_LastSample.DistanceMillimeters, &(m_pData->List[PRX_DATA_DISTANCE].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[PRX_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! PRX Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -PrxDevice::UpdateCachedThreshold( - ) -{ - TraceInformation("COMBO %!FUNC! PRX do not have threshold!"); - - return STATUS_SUCCESS; -} \ No newline at end of file diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx deleted file mode 100644 index 699be4d..0000000 Binary files a/SensorsComboDriver/SensorsComboDriver.inx and /dev/null differ diff --git a/SensorsComboDriver/readme.md b/SensorsComboDriver/readme.md deleted file mode 100644 index 44109a0..0000000 --- a/SensorsComboDriver/readme.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -page_type: sample -description: "Demonstrates how to write UMDF v2 drivers to control various types of virtual sensors." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# Sensors Combo Driver Sample - -The sensors combo driver sensor sample shows how to write UMDF v2 drivers to control various types of virtual sensors such as ambient light, barometer, gyroscope, magnetometer, geomagnetic, gravity vector, proximity, linear accelerometer and relative fusion. diff --git a/SensorsComboDriver/relativefusionclient.cpp b/SensorsComboDriver/relativefusionclient.cpp deleted file mode 100644 index 872099a..0000000 --- a/SensorsComboDriver/relativefusionclient.cpp +++ /dev/null @@ -1,515 +0,0 @@ -// Copyright (C) Microsoft Corporation, All Rights Reserved. -// -// Abstract: -// -// This module contains the implementation of sensor specific functions. -// -// Environment: -// -// Windows User-Mode Driver Framework (WUDF) - -#include "Clients.h" - -#include "RelativeFusionClient.tmh" - -#define SENSORV2_POOL_TAG_RELATIVE_FUSION '2FsR' - -#define RelativeFusion_Initial_MinDataInterval_Ms (10) // 100Hz - -#define RelativeFusion_Quarternion_Maximum (1.0f) -#define RelativeFusion_Quarternion_Minimum (-1.0f) -#define RelativeFusion_Quarternion_Resolution ((RelativeFusion_Quarternion_Maximum-RelativeFusion_Quarternion_Minimum)/65536) - -// Relative Fusion Sensor Unique ID -// {0D324DDF-05AD-4285-875A-B2BCF565D2BA} -DEFINE_GUID(GUID_RelativeFusionDevice_UniqueID, - 0xd324ddf, 0x5ad, 0x4285, 0x87, 0x5a, 0xb2, 0xbc, 0xf5, 0x65, 0xd2, 0xba); - - -// Sensor data -typedef enum -{ - RELATIVE_FUSION_DATA_TIMESTAMP = 0, - RELATIVE_FUSION_DATA_QUATERNION_W, - RELATIVE_FUSION_DATA_QUATERNION_X, - RELATIVE_FUSION_DATA_QUATERNION_Y, - RELATIVE_FUSION_DATA_QUATERNION_Z, - RELATIVE_FUSION_DATA_COUNT -} RELATIVE_FUSION_DATA_INDEX; - -// Sensor thresholds -typedef enum -{ - RELATIVE_FUSION_THRESHOLD_QUATERNION_W = 0, - RELATIVE_FUSION_THRESHOLD_QUATERNION_X, - RELATIVE_FUSION_THRESHOLD_QUATERNION_Y, - RELATIVE_FUSION_THRESHOLD_QUATERNION_Z, - RELATIVE_FUSION_THRESHOLD_COUNT -} RELATIVE_FUSION_THRESHOLD_INDEX; - - - -//------------------------------------------------------------------------------ -// Function: Initialize -// -// This routine initializes the sensor to its default properties -// -// Arguments: -// Device: IN: WDFDEVICE object -// SensorInstance: IN: SENSOROBJECT for each sensor instance -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -RelativeFusionDevice::Initialize( - _In_ WDFDEVICE Device, - _In_ SENSOROBJECT SensorInstance - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // - // Store device and instance - // - m_Device = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - // - // Create Lock - // - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! Relative Fusion WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEnumerationProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_RelativeOrientation, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Manufacturer name", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Relative Fusion Device", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Key = DEVPKEY_Sensor_ConnectionType; - // The DEVPKEY_Sensor_ConnectionType values match the SensorConnectionType enumeration - InitPropVariantFromUInt32(static_cast(SensorConnectionType::Integrated), - &(m_pEnumerationProperties->List[SENSOR_CONNECTION_TYPE].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_RelativeFusionDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); - } - - // - // Supported Data-Fields - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_PROPERTY_LIST_SIZE(RELATIVE_FUSION_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pSupportedDataFields)); - if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = RELATIVE_FUSION_DATA_COUNT; - - m_pSupportedDataFields->List[RELATIVE_FUSION_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[RELATIVE_FUSION_DATA_QUATERNION_W] = PKEY_SensorData_QuaternionW; - m_pSupportedDataFields->List[RELATIVE_FUSION_DATA_QUATERNION_X] = PKEY_SensorData_QuaternionX; - m_pSupportedDataFields->List[RELATIVE_FUSION_DATA_QUATERNION_Y] = PKEY_SensorData_QuaternionY; - m_pSupportedDataFields->List[RELATIVE_FUSION_DATA_QUATERNION_Z] = PKEY_SensorData_QuaternionZ; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(RELATIVE_FUSION_DATA_COUNT); - FILETIME Time = {0}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pData)); - if (!NT_SUCCESS(Status) || nullptr == m_pData) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = RELATIVE_FUSION_DATA_COUNT; - - m_pData->List[RELATIVE_FUSION_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[RELATIVE_FUSION_DATA_TIMESTAMP].Value)); - - m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_W].Key = PKEY_SensorData_QuaternionW; - InitPropVariantFromFloat(0.0, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_W].Value)); - - m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_X].Key = PKEY_SensorData_QuaternionX; - InitPropVariantFromFloat(0.0, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_X].Value)); - - m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Y].Key = PKEY_SensorData_QuaternionY; - InitPropVariantFromFloat(0.0, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Y].Value)); - - m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Z].Key = PKEY_SensorData_QuaternionZ; - InitPropVariantFromFloat(0.0, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Z].Value)); - - ZeroMemory(&m_LastSample, sizeof(m_LastSample)); - ZeroMemory(&m_CachedData, sizeof(m_CachedData)); - m_CachedData.W = 1.0f; // This is the initial position - } - - // - // Sensor Properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_COMMON_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pProperties) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_COMMON_PROPERTY_COUNT; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(RelativeFusion_Initial_MinDataInterval_Ms, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - m_IntervalMs = RelativeFusion_Initial_MinDataInterval_Ms; - m_MinimumIntervalMs = RelativeFusion_Initial_MinDataInterval_Ms; - - m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_RelativeOrientation, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_TYPE].Value)); - } - - // - // Data filed properties - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_DATA_FIELD_PROPERTY_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pDataFieldProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pDataFieldProperties) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pDataFieldProperties, Size); - m_pDataFieldProperties->Count = SENSOR_DATA_FIELD_PROPERTY_COUNT; - - m_pDataFieldProperties->List[SENSOR_RESOLUTION].Key = PKEY_SensorDataField_Resolution; - InitPropVariantFromFloat(RelativeFusion_Quarternion_Resolution, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(RelativeFusion_Quarternion_Minimum, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(RelativeFusion_Quarternion_Maximum, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(RELATIVE_FUSION_THRESHOLD_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_RELATIVE_FUSION, - Size, - &MemoryHandle, - reinterpret_cast(&m_pThresholds)); - if (!NT_SUCCESS(Status) || nullptr == m_pThresholds) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); - m_pThresholds->Count = RELATIVE_FUSION_THRESHOLD_COUNT; - - m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_W].Key = PKEY_SensorData_QuaternionW; - InitPropVariantFromFloat(0.0f, &(m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_W].Value)); - - m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_X].Key = PKEY_SensorData_QuaternionX; - InitPropVariantFromFloat(0.0f, &(m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_X].Value)); - - m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_Y].Key = PKEY_SensorData_QuaternionY; - InitPropVariantFromFloat(0.0f, &(m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_Y].Value)); - - m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_Z].Key = PKEY_SensorData_QuaternionZ; - InitPropVariantFromFloat(0.0f, &(m_pThresholds->List[RELATIVE_FUSION_THRESHOLD_QUATERNION_Z].Value)); - - ZeroMemory(&m_CachedThresholds, sizeof(m_CachedThresholds)); - m_FirstSample = TRUE; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: GetData -// -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. It simulates hardware thresholding by only generating data -// when the change of data is greater than threshold. -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -RelativeFusionDevice::GetData( - ) -{ - BOOLEAN DataReady = FALSE; - FILETIME TimeStamp = {0}; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // new sample? - if (FALSE != m_FirstSample) - { - Status = GetPerformanceTime (&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("COMBO %!FUNC! RelativeFusionDevice GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - - DataReady = TRUE; - } - else - { - // Compare the change of data to threshold, and only push the data back to - // clx if the change exceeds threshold. This is usually done in HW. - if ((abs(m_CachedData.W - m_LastSample.W) >= m_CachedThresholds.W) || - (abs(m_CachedData.X - m_LastSample.X) >= m_CachedThresholds.X) || - (abs(m_CachedData.Y - m_LastSample.Y) >= m_CachedThresholds.Y) || - (abs(m_CachedData.Z - m_LastSample.Z) >= m_CachedThresholds.Z)) - { - DataReady = TRUE; - } - } - - if (FALSE != DataReady) - { - // update last sample - m_LastSample = m_CachedData; - - // push to clx - InitPropVariantFromFloat(m_LastSample.W, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_W].Value)); - InitPropVariantFromFloat(m_LastSample.X, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_X].Value)); - InitPropVariantFromFloat(m_LastSample.Y, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Y].Value)); - InitPropVariantFromFloat(m_LastSample.Z, &(m_pData->List[RELATIVE_FUSION_DATA_QUATERNION_Z].Value)); - - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[RELATIVE_FUSION_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! RelativeFusionDevice Data did NOT meet the threshold"); - } - - SENSOR_FunctionExit(Status); - return Status; -} - - - -//------------------------------------------------------------------------------ -// Function: UpdateCachedThreshold -// -// This routine updates the cached threshold -// -// Arguments: -// None -// -// Return Value: -// NTSTATUS code -//------------------------------------------------------------------------------ -NTSTATUS -RelativeFusionDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_UNSUCCESSFUL; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_QuaternionW, - &m_CachedThresholds.W); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice PropKeyFindKeyGetFloat for W failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_QuaternionX, - &m_CachedThresholds.X); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_QuaternionY, - &m_CachedThresholds.Y); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_QuaternionZ, - &m_CachedThresholds.Z); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! RelativeFusionDevice PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); - goto Exit; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/Device.h b/SimpleDeviceOrientationSensor/Device.h deleted file mode 100644 index 3d1e677..0000000 --- a/SimpleDeviceOrientationSensor/Device.h +++ /dev/null @@ -1,137 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved -// -//Abstract: -// -// This module contains the type definitions for the client -// driver's device callback class. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#pragma once - -#include -#include -#include - -#include "SensorsTrace.h" -#include -#include - -#include "HardwareSimulator.h" - -#include - -#define SENSORV2_POOL_TAG_SDO 'sodS' - -#define Sdo_Mininum_DataInterval (20) // 50Hz -#define Sdo_Default_DataInterval (200) // 5Hz - -// -// Sensor Common Properties -// -typedef enum -{ - SENSOR_PROPERTY_STATE = 0, - SENSOR_PROPERTY_MIN_INTERVAL, - SENSOR_PROPERTY_MAX_DATAFIELDSIZE, - SENSOR_PROPERTY_SENSOR_TYPE, - SENSOR_PROPERTIES_COUNT -} SENSOR_COMMON_PROPERTIES_INDEX; - -// -// Sensor Enumeration Properties -// -typedef enum -{ - SENSOR_TYPE_GUID = 0, - SENSOR_MANUFACTURER, - SENSOR_MODEL, - SENSOR_PERSISTENT_UNIQUEID, - SENSOR_ISPRIMARY, - SENSOR_ENUMERATION_PROPERTIES_COUNT -} SENSOR_ENUMERATION_PROPERTIES_INDEX; - -// -// Supported Data Fields -// -typedef enum -{ - SDO_DATA_TIMESTAMP = 0, - SDO_DATA_SIMPLEDEVICEORIENTATION, - SDO_DATA_COUNT -} SDO_DATA_INDEX; - - -// -// Simple Device Orientation Driver Class -// - -typedef class _SdoDevice -{ -private: - // Simulator - WDFOBJECT m_SimulatorInstance; - - // WDF - WDFDEVICE m_FxDevice; - SENSOROBJECT m_SensorInstance; - WDFWAITLOCK m_Lock; - WDFTIMER m_Timer; - - // Sensor operation - BOOLEAN m_PoweredOn; - BOOLEAN m_Started; - - // Sensor Specific Properties - PSENSOR_PROPERTY_LIST m_pSupportedDataFields; - PSENSOR_COLLECTION_LIST m_pEnumerationProperties; - PSENSOR_COLLECTION_LIST m_pProperties; - PSENSOR_COLLECTION_LIST m_pEmptyThreshold; - - // - // SDO Operation ---------------------------------------------------- - // - - ULONG m_Interval; - BOOLEAN m_FirstSample; - ULONG m_StartTime; - ULONGLONG m_SampleCount; - - PSENSOR_COLLECTION_LIST m_pData; // Sdo data that is going to push to clx - ABI::Windows::Devices::Sensors::SimpleOrientation m_LastSample; - -public: - // WDF callbacks - static EVT_WDF_DRIVER_DEVICE_ADD OnDeviceAdd; - static EVT_WDF_DEVICE_PREPARE_HARDWARE OnPrepareHardware; - static EVT_WDF_DEVICE_RELEASE_HARDWARE OnReleaseHardware; - static EVT_WDF_DEVICE_D0_ENTRY OnD0Entry; - static EVT_WDF_DEVICE_D0_EXIT OnD0Exit; - static EVT_WDF_TIMER OnTimerExpire; - - - // CLX callbacks - static EVT_SENSOR_DRIVER_START_SENSOR OnStart; - static EVT_SENSOR_DRIVER_STOP_SENSOR OnStop; - static EVT_SENSOR_DRIVER_GET_SUPPORTED_DATA_FIELDS OnGetSupportedDataFields; - static EVT_SENSOR_DRIVER_GET_PROPERTIES OnGetProperties; - static EVT_SENSOR_DRIVER_GET_DATA_FIELD_PROPERTIES OnGetDataFieldProperties; - static EVT_SENSOR_DRIVER_GET_DATA_INTERVAL OnGetDataInterval; - static EVT_SENSOR_DRIVER_SET_DATA_INTERVAL OnSetDataInterval; - static EVT_SENSOR_DRIVER_GET_DATA_THRESHOLDS OnGetDataThresholds; - static EVT_SENSOR_DRIVER_SET_DATA_THRESHOLDS OnSetDataThresholds; - static EVT_SENSOR_DRIVER_DEVICE_IO_CONTROL OnIoControl; - -private: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - -} SdoDevice, *PSdoDevice; - -// -// Set up accessor function to retrieve device context -// -WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(SdoDevice, GetSdoContextFromSensorInstance); diff --git a/SimpleDeviceOrientationSensor/Driver.h b/SimpleDeviceOrientationSensor/Driver.h deleted file mode 100644 index 9718080..0000000 --- a/SimpleDeviceOrientationSensor/Driver.h +++ /dev/null @@ -1,19 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved -// -//Abstract: -// -// This module contains the type definitions for the simple device orientation sensor -// driver callback class. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#pragma once - -WDF_EXTERN_C_START - -DRIVER_INITIALIZE DriverEntry; -EVT_WDF_DRIVER_UNLOAD OnDriverUnload; - -WDF_EXTERN_C_END \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/HardwareSimulator.h b/SimpleDeviceOrientationSensor/HardwareSimulator.h deleted file mode 100644 index 7da0be1..0000000 --- a/SimpleDeviceOrientationSensor/HardwareSimulator.h +++ /dev/null @@ -1,58 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved -// -//Abstract: -// -// This module contains the type definitions for the simple device orientation sensor sample -// hardware simulator. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#pragma once - -#include -#include - -#include "SensorsTrace.h" -#include -#include - -#define HardwareSimulator_HardwareInterval (1000) - -typedef enum _SIMULATOR_STATE -{ - SimulatorState_NotInitialized = 0, - SimulatorState_Initialized, - SimulatorState_Started -} SIMULATOR_STATE; - -typedef class _HardwareSimulator -{ -private: - WDFTIMER m_Timer; - ULONG m_Index; - WDFWAITLOCK m_Lock; - SIMULATOR_STATE m_State; - WDFOBJECT m_SimulatorInstance; - -public: - _HardwareSimulator(); - ~_HardwareSimulator(); - - // WDF callbacks - static EVT_WDF_TIMER OnTimerExpire; - - static NTSTATUS Initialize(_In_ WDFDEVICE Device, _Out_ WDFOBJECT *SimulatorInstance); - NTSTATUS Cleanup(); - NTSTATUS Start(); - NTSTATUS Stop(); - ABI::Windows::Devices::Sensors::SimpleOrientation GetOrientation(); - -private: - NTSTATUS InitializeInternal(_In_ WDFOBJECT SimulatorInstance); - -} HardwareSimulator, *PHardwareSimulator; - -// Set up accessor function to retrieve device context -WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(HardwareSimulator, GetHardwareSimulatorContextFromInstance); diff --git a/SimpleDeviceOrientationSensor/SensorsTrace.h b/SimpleDeviceOrientationSensor/SensorsTrace.h deleted file mode 100644 index 6098864..0000000 --- a/SimpleDeviceOrientationSensor/SensorsTrace.h +++ /dev/null @@ -1,100 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved -// -//Abstract: -// -// Header file for the debug tracing related function defintions and macros. -// -//Environment: -// -// User mode - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -// Define the tracing flags. -// -// Tracing GUID - 3C773167-F26D-4F72-A1DE-95F1FD795840 - -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID( \ - SimpleDeviceOrientationSensorTraceGuid, (3C773167,F26D,4F72,A1DE,95F1FD795840), \ - WPP_DEFINE_BIT(EntryExit) \ - WPP_DEFINE_BIT(DataFlow) \ - WPP_DEFINE_BIT(Verbose) \ - WPP_DEFINE_BIT(Information) \ - WPP_DEFINE_BIT(Warning) \ - WPP_DEFINE_BIT(Error) \ - WPP_DEFINE_BIT(Fatal) \ - WPP_DEFINE_BIT(DriverStatus) \ - ) - -#define WPP_FLAG_LEVEL_LOGGER(flag, level) WPP_LEVEL_LOGGER(flag) - -#define WPP_FLAG_LEVEL_ENABLED(flag, level) (WPP_LEVEL_ENABLED(flag) && WPP_CONTROL(WPP_BIT_ ## flag).Level >= level) - -#define WPP_LEVEL_FLAGS_LOGGER(level,flags) WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(level, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= level) - -// This comment block is scanned by the trace preprocessor to define our -// Trace function. -// -// begin_wpp config -// -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// -// FUNC TraceFatal{LEVEL=TRACE_LEVEL_FATAL,FLAGS=Fatal}(MSG,...); -// FUNC TraceError{LEVEL=TRACE_LEVEL_ERROR,FLAGS=Error}(MSG,...); -// FUNC TraceWarning{LEVEL=TRACE_LEVEL_WARNING,FLAGS=Warning}(MSG,...); -// FUNC TraceInformation{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=Information}(MSG,...); -// FUNC TraceVerbose{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=Verbose}(MSG,...); -// FUNC TracePerformance{PERF=DUMMY,LEVEL=TRACE_LEVEL_PERF}(FLAGS,MSG,...); -// -// FUNC TraceData{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=DataFlow}(MSG,...); -// -// FUNC TraceDriverStatus{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=DriverStatus}(MSG,...); -// -// end_wpp - -// SENSOR ------------------------------------------------------------------------------------------------ - -// MACRO: SENSOR_FunctionEnter -// -// begin_wpp config -// USEPREFIX (SENSOR_FunctionEnter, "%!STDPREFIX! SENSOR %!FUNC! FunctionEnter"); -// FUNC SENSOR_FunctionEnter{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=EntryExit}(...); -// end_wpp - - -// MACRO: SENSOR_FunctionExit -// -// begin_wpp config -// USEPREFIX (SENSOR_FunctionExit, "%!STDPREFIX! SENSOR %!FUNC! FunctionExit: %!STATUS!", __status); -// FUNC SENSOR_FunctionExit{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=EntryExit}(SENSOREXIT); -// end_wpp -#define WPP_LEVEL_FLAGS_SENSOREXIT_ENABLED(LEVEL, FLAGS, status) WPP_LEVEL_FLAGS_ENABLED(LEVEL, FLAGS) -#define WPP_LEVEL_FLAGS_SENSOREXIT_LOGGER(LEVEL, FLAGS, status) WPP_LEVEL_FLAGS_LOGGER(LEVEL, FLAGS) - -#define WPP_LEVEL_FLAGS_SENSOREXIT_PRE(LEVEL, FLAGS, status) { \ - NTSTATUS __status = status; -#define WPP_LEVEL_FLAGS_SENSOREXIT_POST(LEVEL, FLAGS, status) /*TraceMessage()*/; \ - } - - - -// WPP Recorder ------------------------------------------------------------------------------------------- -// -// The following two macros are required to enable WPP Recorder functionality for clients of the Sensor Class Extension -// -#define WPP_RECORDER_LEVEL_FLAGS_SENSOREXIT_FILTER(LEVEL, FLAGS, status) WPP_RECORDER_LEVEL_FLAGS_FILTER(LEVEL, FLAGS) -#define WPP_RECORDER_LEVEL_FLAGS_SENSOREXIT_ARGS(LEVEL, FLAGS, status) WPP_RECORDER_LEVEL_FLAGS_ARGS(LEVEL, FLAGS) - - -#ifdef __cplusplus -} -#endif - - diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.def b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.def deleted file mode 100644 index aa44c9a..0000000 --- a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.def +++ /dev/null @@ -1,6 +0,0 @@ -; SimpleDeviceOrientationSensor.def : Declares the module parameters. - -LIBRARY SimpleDeviceOrientationSensor - -EXPORTS - diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx deleted file mode 100644 index b2ccfab..0000000 Binary files a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx and /dev/null differ diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.sln b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.sln deleted file mode 100644 index fecadaf..0000000 --- a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleDeviceOrientationSensor", "SimpleDeviceOrientationSensor.vcxproj", "{EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|ARM64 = Debug|ARM64 - Release|ARM64 = Release|ARM64 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Debug|ARM64.Build.0 = Debug|ARM64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Release|ARM64.ActiveCfg = Release|ARM64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Release|ARM64.Build.0 = Release|ARM64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Debug|x64.ActiveCfg = Debug|x64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Debug|x64.Build.0 = Debug|x64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Release|x64.ActiveCfg = Release|x64 - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj deleted file mode 100644 index eaee51a..0000000 --- a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj +++ /dev/null @@ -1,216 +0,0 @@ - - - - - Debug - ARM64 - - - Release - ARM64 - - - Debug - x64 - - - Release - x64 - - - - {EEA3DEEA-AF9A-45E3-B6AE-070677AC1032} - $(MSBuildProjectName) - 2 - Debug - x64 - {1854CF02-14B5-40BD-A09F-4C744EFB31A8} - - - - Windows10 - False - Universal - UMDF - WindowsUserModeDriver10.0 - DynamicLibrary - - - Windows10 - False - Universal - UMDF - WindowsUserModeDriver10.0 - DynamicLibrary - - - Windows10 - True - Universal - UMDF - WindowsUserModeDriver10.0 - DynamicLibrary - - - Windows10 - True - Universal - UMDF - WindowsUserModeDriver10.0 - DynamicLibrary - - - - $(IntDir) - - - - - - - - - - - - - - - - true - true - SimpleDeviceOrientationSensor - sensorstrace.h - - - $(InfArch) - true - .\$(IntDir)\SimpleDeviceOrientationSensor.inf - - - - SimpleDeviceOrientationSensor - - - SimpleDeviceOrientationSensor - - - SimpleDeviceOrientationSensor - - - SimpleDeviceOrientationSensor - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - true - Level4 - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(AdditionalDependencies);mincore.lib;propsys.lib;$(WDK_UM_LIB_PATH)\sensors\1.1\sensorscxstub.lib;sensorsutils.lib - SimpleDeviceOrientationSensor.def - - - sha256 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - true - Level4 - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(AdditionalDependencies);mincore.lib;propsys.lib;$(WDK_UM_LIB_PATH)\sensors\1.1\sensorscxstub.lib;sensorsutils.lib - SimpleDeviceOrientationSensor.def - - - sha256 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - true - Level4 - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(AdditionalDependencies);mincore.lib;propsys.lib;$(WDK_UM_LIB_PATH)\sensors\1.1\sensorscxstub.lib;sensorsutils.lib - SimpleDeviceOrientationSensor.def - - - sha256 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - true - Level4 - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(PreprocessorDefinitions);_UNICODE;UNICODE;WPP_MACRO_USE_KM_VERSION_FOR_UM - %(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(SDK_INC_PATH)\ABI;$(WDK_UM_INC_PATH)\sensors\1.1 - - - %(AdditionalDependencies);mincore.lib;propsys.lib;$(WDK_UM_LIB_PATH)\sensors\1.1\sensorscxstub.lib;sensorsutils.lib - SimpleDeviceOrientationSensor.def - - - sha256 - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj.Filters b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj.Filters deleted file mode 100644 index 45db253..0000000 --- a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj.Filters +++ /dev/null @@ -1,43 +0,0 @@ - - - - - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;* - {00557774-6CAE-4A42-9465-A85A4F048686} - - - h;hpp;hxx;hm;inl;inc;xsd - {68764800-116B-4343-8B60-49693688236E} - - - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml - {25662F7E-DB14-43DD-84A3-E8B7327B6ECE} - - - inf;inv;inx;mof;mc; - {372D6D06-B60D-4D04-901A-FC8530D3AC42} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Driver Files - - - \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/client.cpp b/SimpleDeviceOrientationSensor/client.cpp deleted file mode 100644 index c167b6c..0000000 --- a/SimpleDeviceOrientationSensor/client.cpp +++ /dev/null @@ -1,595 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved. -// -//Abstract: -// -// This module contains the implementation of driver callback function -// from clx to simple device orientation sensor. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#include "Device.h" -#include - -#include "Client.tmh" - -// This routine is called by worker thread to read a single sample, compare threshold -// and push it back to CLX. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::GetData() -{ - PHardwareSimulator pSimulator = nullptr; - FILETIME TimeStamp = {}; - NTSTATUS Status = STATUS_SUCCESS; - ABI::Windows::Devices::Sensors::SimpleOrientation Sample; - - SENSOR_FunctionEnter(); - - if (FALSE != m_FirstSample) - { - Status = GetPerformanceTime(&m_StartTime); - if (!NT_SUCCESS(Status)) - { - m_StartTime = 0; - TraceError("SDOS %!FUNC! GetPerformanceTime %!STATUS!", Status); - } - - m_SampleCount = 0; - } - - pSimulator = GetHardwareSimulatorContextFromInstance(m_SimulatorInstance); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - goto Exit; - } - - Sample = pSimulator->GetOrientation(); - - if (FALSE != m_FirstSample || m_LastSample != Sample) - { - m_LastSample = Sample; - - // push to clx - InitPropVariantFromUInt32(m_LastSample, &(m_pData->List[SDO_DATA_SIMPLEDEVICEORIENTATION].Value)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[SDO_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("SDOS %!FUNC! SDO Data did NOT meet the threshold"); - } - -Exit: - SENSOR_FunctionExit(Status); - - return Status; -} - -// This callback is called when interval wait time has expired and driver is ready -// to collect new sample. The callback reads current value, compare value to threshold, -// pushes it up to CLX framework, and schedule next wake up time. -VOID SdoDevice::OnTimerExpire( - _In_ WDFTIMER Timer // WDF timer object - ) -{ - PSdoDevice pDevice = nullptr; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - pDevice = GetSdoContextFromSensorInstance(WdfTimerGetParentObject(Timer)); - if (nullptr == pDevice) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetSdoContextFromSensorInstance failed %!STATUS!", Status); - } - - if (NT_SUCCESS(Status)) - { - // Get data and push to clx - WdfWaitLockAcquire(pDevice->m_Lock, NULL); - Status = pDevice->GetData(); - if (!NT_SUCCESS(Status) && Status != STATUS_DATA_NOT_ACCEPTED) - { - TraceError("SDOS %!FUNC! GetData Failed %!STATUS!", Status); - } - WdfWaitLockRelease(pDevice->m_Lock); - - // Schedule next wake up time - if (Sdo_Mininum_DataInterval <= pDevice->m_Interval && - FALSE != pDevice->m_PoweredOn && - FALSE != pDevice->m_Started) - { - LONGLONG WaitTime = 0; // in unit of 100ns - - if (0 == pDevice->m_StartTime) - { - // in case we fail to get sensor start time, use static wait time - WaitTime = WDF_REL_TIMEOUT_IN_MS(pDevice->m_Interval); - } - else - { - ULONG CurrentTimeMs = 0; - - // dynamically calculate wait time to avoid jitter - Status = GetPerformanceTime(&CurrentTimeMs); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! GetPerformanceTime %!STATUS!", Status); - WaitTime = WDF_REL_TIMEOUT_IN_MS(pDevice->m_Interval); - } - else - { - pDevice->m_SampleCount++; - if (CurrentTimeMs > (pDevice->m_StartTime + (pDevice->m_Interval * (pDevice->m_SampleCount + 1)))) - { - // If we skipped two or more beats, reschedule the timer with a zero due time to catch up on missing samples - WaitTime = 0; - } - else - { - WaitTime = (pDevice->m_StartTime + - (pDevice->m_Interval * (pDevice->m_SampleCount + 1))) - CurrentTimeMs; - } - WaitTime = WDF_REL_TIMEOUT_IN_MS(WaitTime); - } - } - WdfTimerStart(pDevice->m_Timer, WaitTime); - } - } - - SENSOR_FunctionExit(Status); -} - -// Called by Sensor CLX to begin continously sampling the sensor. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnStart( - _In_ SENSOROBJECT SensorInstance // sensor device object - ) -{ - PHardwareSimulator pSimulator = nullptr; - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Sensor(0x%p) parameter is invalid. Failed %!STATUS!", SensorInstance, Status); - } - else if (0 == pDevice->m_Interval) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Interval parameter is invalid (equal to 0). Failed %!STATUS!", Status); - } - - if (NT_SUCCESS(Status)) - { - // Get the simulator context - pSimulator = GetHardwareSimulatorContextFromInstance(pDevice->m_SimulatorInstance); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - } - } - - if (NT_SUCCESS(Status)) - { - // Start the simulator - pSimulator->Start(); - - pDevice->m_FirstSample = TRUE; - - // Start polling - pDevice->m_Started = TRUE; - - InitPropVariantFromUInt32(SensorState_Active, - &(pDevice->m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); - - - // Start the sample polling timer. - // Note: The polling timer is configured to allow for the first sample to be reported immediately. - // Some hardware may want to delay the first sample report a little to account for hardware start time. - WdfTimerStart(pDevice->m_Timer, 0); - } - - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to stop continously sampling the sensor. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnStop( - _In_ SENSOROBJECT SensorInstance // sensor device object - ) -{ - PHardwareSimulator pSimulator = nullptr; - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Sensor(0x%p) parameter is invalid. Failed %!STATUS!", SensorInstance, Status); - } - - if (NT_SUCCESS(Status)) - { - // Stop polling - - pDevice->m_Started = FALSE; - - // Waiting for the callback to complete, then stopping the timer - WdfTimerStop(pDevice->m_Timer, TRUE); - - InitPropVariantFromUInt32(SensorState_Idle, - &(pDevice->m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); - - // Stop the simulator - pSimulator = GetHardwareSimulatorContextFromInstance(pDevice->m_SimulatorInstance); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - goto Exit; - } - - pSimulator->Stop(); - } - -Exit: - SENSOR_FunctionExit(Status); - - return Status; -} - -// Called by Sensor CLX to get supported data fields. The typical usage is to call -// this function once with buffer pointer as NULL to acquire the required size -// for the buffer, allocate buffer, then call the function again to retrieve -// sensor information. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnGetSupportedDataFields( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _Inout_opt_ PSENSOR_PROPERTY_LIST pFields, // pointer to a list of supported properties - _Out_ PULONG pSize // number of bytes for the list of supported properties - ) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - ULONG size = 0; - - SENSOR_FunctionEnter(); - - if (nullptr == pSize) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! pSize: Invalid parameter! %!STATUS!", Status); - goto Exit; - } - - *pSize = 0; - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! pDevice: Invalid parameter! %!STATUS!", Status); - goto Exit; - } - - if (nullptr == pFields) - { - // Just return size - size = pDevice->m_pSupportedDataFields->AllocatedSizeInBytes; - } - else - { - if (pFields->AllocatedSizeInBytes < pDevice->m_pSupportedDataFields->AllocatedSizeInBytes) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! Buffer is too small. Failed %!STATUS!", Status); - goto Exit; - } - - // Fill out data - Status = PropertiesListCopy(pFields, pDevice->m_pSupportedDataFields); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! PropertiesListCopy failed %!STATUS!", Status); - goto Exit; - } - - size = pDevice->m_pSupportedDataFields->AllocatedSizeInBytes; - } - - *pSize = size; - -Exit: - if (!NT_SUCCESS(Status)) - { - *pSize = 0; - } - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to get sensor properties. The typical usage is to call -// this function once with buffer pointer as NULL to acquire the required size -// for the buffer, allocate buffer, then call the function again to retrieve -// sensor information. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnGetProperties( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _Inout_opt_ PSENSOR_COLLECTION_LIST pProperties, // pointer to a list of sensor properties - _Out_ PULONG pSize // number of bytes for the list of sensor properties - ) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - ULONG size = 0; - - SENSOR_FunctionEnter(); - - if (nullptr == pSize) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! pSize: Invalid parameter! %!STATUS!", Status); - goto Exit; - } - - *pSize = 0; - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! pDevice: Invalid parameter! %!STATUS!", Status); - goto Exit; - } - - if (nullptr == pProperties) - { - // Just return size - size = CollectionsListGetMarshalledSize(pDevice->m_pProperties); - } - else - { - if (pProperties->AllocatedSizeInBytes < - CollectionsListGetMarshalledSize(pDevice->m_pProperties)) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! Buffer is too small. Failed %!STATUS!", Status); - goto Exit; - } - - // Fill out all data - Status = CollectionsListCopyAndMarshall(pProperties, pDevice->m_pProperties); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! CollectionsListCopyAndMarshall failed %!STATUS!", Status); - goto Exit; - } - - size = CollectionsListGetMarshalledSize(pDevice->m_pProperties); - } - - *pSize = size; - -Exit: - if (!NT_SUCCESS(Status)) - { - *pSize = 0; - } - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to get data field properties. The typical usage is to call -// this function once with buffer pointer as NULL to acquire the required size -// for the buffer, allocate buffer, then call the function again to retrieve -// sensor information. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnGetDataFieldProperties( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _In_ const PROPERTYKEY *DataField, // pointer to the propertykey of requested property - _Inout_opt_ PSENSOR_COLLECTION_LIST /*pProperties*/, // pointer to a list of sensor properties - _Out_ PULONG pSize // number of bytes for the list of sensor properties -) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_NOT_SUPPORTED; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice || nullptr == pSize || nullptr == DataField) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Invalid parameters! %!STATUS!", Status); - } - - *pSize = 0; - - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to get sampling rate of the sensor. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnGetDataInterval( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _Out_ PULONG DataRateMs // sampling rate in milliseconds - ) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Sensor(0x%p) parameter is invalid. Failed %!STATUS!", SensorInstance, Status); - goto Exit; - } - - if (nullptr == DataRateMs) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! DataRateMs(0x%p) parameter is invalid. Failed %!STATUS!", DataRateMs, Status); - goto Exit; - } - - *DataRateMs = pDevice->m_Interval; - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to set sampling rate of the sensor. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnSetDataInterval( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _In_ ULONG DataRateMs // sampling rate in milliseconds - ) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Sensor(0x%p) parameter is invalid. Failed %!STATUS!", SensorInstance, Status); - goto Exit; - } - - if (Sdo_Mininum_DataInterval > DataRateMs) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! DataRateMs(%d) parameter is smaller than the minimum data interval. Failed %!STATUS!", DataRateMs, Status); - goto Exit; - } - - pDevice->m_Interval = DataRateMs; - - // Restart the timer at minimum report interval to return a sample as soon as possible. - if (FALSE != pDevice->m_Started) - { - pDevice->m_Started = FALSE; - WdfTimerStop(pDevice->m_Timer, TRUE); - - pDevice->m_Started = TRUE; - pDevice->m_FirstSample = TRUE; - WdfTimerStart(pDevice->m_Timer, WDF_REL_TIMEOUT_IN_MS(Sdo_Mininum_DataInterval)); - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to get data thresholds. The typical usage is to call -// this function once with buffer pointer as NULL to acquire the required size -// for the buffer, allocate buffer, then call the function again to retrieve -// sensor information. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnGetDataThresholds( - _In_ SENSOROBJECT SensorInstance, // sensor device object - _Inout_opt_ PSENSOR_COLLECTION_LIST pThresholds, // pointer to a list of sensor thresholds - _Out_ PULONG pSize // number of bytes for the list of sensor thresholds - ) -{ - PSdoDevice pDevice = GetSdoContextFromSensorInstance(SensorInstance); - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (nullptr == pDevice || nullptr == pSize) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! Invalid parameters! %!STATUS!", Status); - goto Exit; - } - - if (nullptr == pThresholds) - { - // Just return size - *pSize = CollectionsListGetMarshalledSize(pDevice->m_pEmptyThreshold); - } - else - { - if (pThresholds->AllocatedSizeInBytes < - CollectionsListGetMarshalledSize(pDevice->m_pEmptyThreshold)) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! Buffer is too small. Failed %!STATUS!", Status); - goto Exit; - } - - // Fill out all data - Status = CollectionsListCopyAndMarshall(pThresholds, pDevice->m_pEmptyThreshold); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! CollectionsListCopyAndMarshall failed %!STATUS!", Status); - goto Exit; - } - - *pSize = CollectionsListGetMarshalledSize(pDevice->m_pEmptyThreshold); - } - -Exit: - if (!NT_SUCCESS(Status)) - { - *pSize = 0; - } - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to set data thresholds. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnSetDataThresholds( - _In_ SENSOROBJECT /*SensorInstance*/, // sensor device object - _In_ PSENSOR_COLLECTION_LIST /*pThresholds*/ // pointer to a list of sensor thresholds - ) -{ - NTSTATUS Status = STATUS_NOT_SUPPORTED; - - SENSOR_FunctionEnter(); - - // Unsupported at this point in time. - - SENSOR_FunctionExit(Status); - return Status; -} - -// Called by Sensor CLX to handle IOCTLs that clx does not support -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnIoControl( - _In_ SENSOROBJECT /*SensorInstance*/, // Sensor object - _In_ WDFREQUEST /*Request*/, // WDF request object - _In_ size_t /*OutputBufferLength*/, // number of bytes to retrieve from output buffer - _In_ size_t /*InputBufferLength*/, // number of bytes to retrieve from input buffer - _In_ ULONG /*IoControlCode*/ // IOCTL control code - ) -{ - NTSTATUS Status = STATUS_NOT_SUPPORTED; - - SENSOR_FunctionEnter(); - - SENSOR_FunctionExit(Status); - return Status; -} diff --git a/SimpleDeviceOrientationSensor/device.cpp b/SimpleDeviceOrientationSensor/device.cpp deleted file mode 100644 index e962430..0000000 --- a/SimpleDeviceOrientationSensor/device.cpp +++ /dev/null @@ -1,572 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved. -// -//Abstract: -// -// This module contains the implementation of WDF callback functions -// for sample simple device orientation sensor driver. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#include "Device.h" - -#include "Device.tmh" - -// Simple Device Orientation Sample Sensors Unique ID -// DO NOT REUSE THIS GUID, CREATE A NEW GUID -// {57AB5189-3D73-4E4D-AFEB-019A5CFB8F05} -DEFINE_GUID(GUID_SdoDevice_UniqueID, - 0x57ab5189, 0x3d73, 0x4e4d, 0xaf, 0xeb, 0x1, 0x9a, 0x5c, 0xfb, 0x8f, 0x5); - -// This routine initializes the sensor to its default properties -// Returns an NTSTATUS code -NTSTATUS SdoDevice::Initialize( - _In_ WDFDEVICE Device, // WDFDEVICE object - _In_ SENSOROBJECT SensorInstance // SENSOROBJECT for each sensor instance - ) -{ - ULONG Size = 0; - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - FILETIME Time = {}; - WDF_OBJECT_ATTRIBUTES TimerAttributes; - WDF_TIMER_CONFIG TimerConfig; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // Store device and instance - m_FxDevice = Device; - m_SensorInstance = SensorInstance; - m_Started = FALSE; - - m_PoweredOn = FALSE; - m_FirstSample = TRUE; - - // Initialize the simple device orientation simulator - HardwareSimulator::Initialize(Device, &m_SimulatorInstance); - - // - // Create Locks - // - { - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - TraceError("SDO %!FUNC! WdfWaitLockCreate m_Lock failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Create timer object for polling sensor samples - // - { - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SensorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - WDF_TIMER_CONFIG_INIT(&TimerConfig, OnTimerExpire); - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - TraceError("SDO %!FUNC! WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - } - - // - // Sensor Enumeration Properties - // - { - Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_ENUMERATION_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_SDO, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEnumerationProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pEnumerationProperties) - { - TraceError("SDO %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEnumerationProperties, Size); - m_pEnumerationProperties->Count = SENSOR_ENUMERATION_PROPERTIES_COUNT; - - m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Key = DEVPKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_SimpleDeviceOrientation, - &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); - - m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Microsoft", - &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); - - m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; - InitPropVariantFromString(L"Simple Device Orientation", - &(m_pEnumerationProperties->List[SENSOR_MODEL].Value)); - - m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Key = DEVPKEY_Sensor_PersistentUniqueId; - InitPropVariantFromCLSID(GUID_SdoDevice_UniqueID, - &(m_pEnumerationProperties->List[SENSOR_PERSISTENT_UNIQUEID].Value)); - - m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Key = DEVPKEY_Sensor_IsPrimary; - InitPropVariantFromBoolean(FALSE, - &(m_pEnumerationProperties->List[SENSOR_ISPRIMARY].Value)); // This value should be set to TRUE if multiple simple device orientation sensors - // exist on the system and this sensor is the primary sensor - } - - // - // Supported Data-Fields - // - { - Size = SENSOR_PROPERTY_LIST_SIZE(SDO_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_SDO, - Size, - &MemoryHandle, - reinterpret_cast(&m_pSupportedDataFields)); - if (!NT_SUCCESS(Status) || nullptr == m_pSupportedDataFields) - { - TraceError("SDO %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = SDO_DATA_COUNT; - - m_pSupportedDataFields->List[SDO_DATA_TIMESTAMP] = PKEY_SensorData_Timestamp; - m_pSupportedDataFields->List[SDO_DATA_SIMPLEDEVICEORIENTATION] = PKEY_SensorData_SimpleDeviceOrientation; - } - - // - // Data - // - { - Size = SENSOR_COLLECTION_LIST_SIZE(SDO_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_SDO, - Size, - &MemoryHandle, - reinterpret_cast(&m_pData)); - if (!NT_SUCCESS(Status) || nullptr == m_pData) - { - TraceError("SDO %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = SDO_DATA_COUNT; - - m_pData->List[SDO_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[SDO_DATA_TIMESTAMP].Value)); - - m_pData->List[SDO_DATA_SIMPLEDEVICEORIENTATION].Key = PKEY_SensorData_SimpleDeviceOrientation; - InitPropVariantFromUInt32(ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Faceup, &(m_pData->List[SDO_DATA_SIMPLEDEVICEORIENTATION].Value)); - } - - // - // Sensor Properties - // - { - m_Interval = Sdo_Default_DataInterval; - - Size = SENSOR_COLLECTION_LIST_SIZE(SENSOR_PROPERTIES_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_SDO, - Size, - &MemoryHandle, - reinterpret_cast(&m_pProperties)); - if (!NT_SUCCESS(Status) || nullptr == m_pProperties) - { - TraceError("SDO %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pProperties, Size); - m_pProperties->Count = SENSOR_PROPERTIES_COUNT; - - m_pProperties->List[SENSOR_PROPERTY_STATE].Key = PKEY_Sensor_State; - InitPropVariantFromUInt32(SensorState_Initializing, - &(m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); - - m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Key = PKEY_Sensor_MinimumDataInterval_Ms; - InitPropVariantFromUInt32(Sdo_Mininum_DataInterval, - &(m_pProperties->List[SENSOR_PROPERTY_MIN_INTERVAL].Value)); - - m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Key = PKEY_Sensor_MaximumDataFieldSize_Bytes; - InitPropVariantFromUInt32(CollectionsListGetMarshalledSize(m_pData), - &(m_pProperties->List[SENSOR_PROPERTY_MAX_DATAFIELDSIZE].Value)); - - m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Key = PKEY_Sensor_Type; - InitPropVariantFromCLSID(GUID_SensorType_SimpleDeviceOrientation, - &(m_pProperties->List[SENSOR_PROPERTY_SENSOR_TYPE].Value)); - } - - // - // Empty Threshold List - // - { - Size = SENSOR_COLLECTION_LIST_SIZE(0); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_SDO, - Size, - &MemoryHandle, - reinterpret_cast(&m_pEmptyThreshold)); - if (!NT_SUCCESS(Status) || nullptr == m_pEmptyThreshold) - { - TraceError("SDO %!FUNC! WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pEmptyThreshold, Size); - m_pEmptyThreshold->Count = 0; - } - - // Reset the FirstSample flag - m_FirstSample = TRUE; - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// This routine is the AddDevice entry point for the SDO client -// driver. This routine is called by the framework in response to AddDevice -// call from the PnP manager. It will create and initialize the device object -// to represent a new instance of the sensor client. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnDeviceAdd( - _In_ WDFDRIVER /*Driver*/, // Supplies a handle to the driver object created in DriverEntry - _Inout_ PWDFDEVICE_INIT pDeviceInit // Supplies a pointer to a framework-allocated WDFDEVICE_INIT structure - ) -{ - WDF_PNPPOWER_EVENT_CALLBACKS Callbacks; - WDFDEVICE Device = nullptr; - WDF_OBJECT_ATTRIBUTES FdoAttributes; - ULONG Flag = 0; - SENSOR_CONTROLLER_CONFIG SensorConfig; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - WDF_OBJECT_ATTRIBUTES_INIT(&FdoAttributes); - - // Initialize FDO attributes and set up file object with sensor extension - Status = SensorsCxDeviceInitConfig(pDeviceInit, &FdoAttributes, Flag); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! SensorsCxDeviceInitConfig failed %!STATUS!", Status); - goto Exit; - } - - // Register the PnP callbacks with the framework. - WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&Callbacks); - Callbacks.EvtDevicePrepareHardware = SdoDevice::OnPrepareHardware; - Callbacks.EvtDeviceReleaseHardware = SdoDevice::OnReleaseHardware; - Callbacks.EvtDeviceD0Entry = SdoDevice::OnD0Entry; - Callbacks.EvtDeviceD0Exit = SdoDevice::OnD0Exit; - - WdfDeviceInitSetPnpPowerEventCallbacks(pDeviceInit, &Callbacks); - - // Call the framework to create the device - Status = WdfDeviceCreate(&pDeviceInit, &FdoAttributes, &Device); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! WdfDeviceCreate failed %!STATUS!", Status); - goto Exit; - } - - // Register CLX callback function pointers - SENSOR_CONTROLLER_CONFIG_INIT(&SensorConfig); - SensorConfig.DriverIsPowerPolicyOwner = WdfUseDefault; - - SensorConfig.EvtSensorStart = SdoDevice::OnStart; - SensorConfig.EvtSensorStop = SdoDevice::OnStop; - SensorConfig.EvtSensorGetSupportedDataFields = SdoDevice::OnGetSupportedDataFields; - SensorConfig.EvtSensorGetDataInterval = SdoDevice::OnGetDataInterval; - SensorConfig.EvtSensorSetDataInterval = SdoDevice::OnSetDataInterval; - SensorConfig.EvtSensorGetDataFieldProperties = SdoDevice::OnGetDataFieldProperties; - SensorConfig.EvtSensorGetDataThresholds = SdoDevice::OnGetDataThresholds; - SensorConfig.EvtSensorSetDataThresholds = SdoDevice::OnSetDataThresholds; - SensorConfig.EvtSensorGetProperties = SdoDevice::OnGetProperties; - SensorConfig.EvtSensorDeviceIoControl = SdoDevice::OnIoControl; - - // Set up power capabilities and IO queues - Status = SensorsCxDeviceInitialize(Device, &SensorConfig); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! SensorsCxDeviceInitialize failed %!STATUS!", Status); - goto Exit; - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// This routine is called by the framework when the PnP manager sends an -// IRP_MN_START_DEVICE request to the driver stack. This routine is -// responsible for performing operations that are necessary to make the -// driver's device operational (for e.g. mapping the hardware resources -// into memory). -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnPrepareHardware( - _In_ WDFDEVICE Device, // Supplies a handle to the framework device object - _In_ WDFCMRESLIST /*ResourcesRaw*/, // Supplies a handle to a collection of framework resource - // objects. This collection identifies the raw (bus-relative) hardware - // resources that have been assigned to the device. - _In_ WDFCMRESLIST /*ResourcesTranslated*/) // Supplies a handle to a collection of framework - // resource objects. This collection identifies the translated - // (system-physical) hardware resources that have been assigned to the - // device. The resources appear from the CPU's point of view. - -{ - PSdoDevice pDevice = nullptr; - WDF_OBJECT_ATTRIBUTES SensorAttr = {}; - SENSOR_CONFIG SensorConfig = {}; - SENSOROBJECT SensorInstance = nullptr; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // Construct sensor instance - - // Create WDFOBJECT for the sensor - WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&SensorAttr, SdoDevice); - - // Register sensor instance with clx - Status = SensorsCxSensorCreate(Device, &SensorAttr, &SensorInstance); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! SensorsCxSensorCreate failed %!STATUS!", Status); - goto Exit; - } - - pDevice = GetSdoContextFromSensorInstance(SensorInstance); - if (nullptr == pDevice) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetSdoContextFromSensorInstance failed %!STATUS!", Status); - goto Exit; - } - - Status = pDevice->Initialize(Device, SensorInstance); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! Initialize device object failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_CONFIG_INIT(&SensorConfig); - SensorConfig.pEnumerationList = pDevice->m_pEnumerationProperties; - Status = SensorsCxSensorInitialize(SensorInstance, &SensorConfig); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! SensorsCxSensorInitialize failed %!STATUS!", Status); - goto Exit; - } - - -Exit: - SENSOR_FunctionExit(Status); - - return Status; -} - -// This routine is called by the framework when the PnP manager is revoking -// ownership of our resources. This may be in response to either -// IRP_MN_STOP_DEVICE or IRP_MN_REMOVE_DEVICE. This routine is responsible for -// performing cleanup of resources allocated in PrepareHardware callback. -// This callback is invoked before passing the request down to the lower driver. -// This routine will also be invoked by the framework if the prepare hardware -// callback returns a failure. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnReleaseHardware( - _In_ WDFDEVICE Device, // Supplies a handle to the framework device object - _In_ WDFCMRESLIST /*ResourcesTranslated*/) // Supplies a handle to a collection of framework - // resource objects. This collection identifies the translated - // (system-physical) hardware resources that have been assigned to the - // device. The resources appear from the CPU's point of view. -{ - PHardwareSimulator pSimulator = nullptr; - PSdoDevice pDevice = nullptr; - SENSOROBJECT SensorInstance = nullptr; - ULONG SensorInstanceCount = 1; // only expect 1 sensor instance - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // Get sensor instance - Status = SensorsCxDeviceGetSensorList(Device, &SensorInstance, &SensorInstanceCount); - if (!NT_SUCCESS(Status) || - 0 == SensorInstanceCount || - NULL == SensorInstance) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! SensorsCxDeviceGetSensorList failed %!STATUS!", Status); - goto Exit; - } - - pDevice = GetSdoContextFromSensorInstance(SensorInstance); - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! GetSdoContextFromSensorInstance failed %!STATUS!", Status); - goto Exit; - } - - // Delete lock - if (pDevice->m_Lock) - { - WdfObjectDelete(pDevice->m_Lock); - pDevice->m_Lock = NULL; - } - - // Cleanup the simple device orientation simulator - pSimulator = GetHardwareSimulatorContextFromInstance(pDevice->m_SimulatorInstance); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - goto Exit; - } - - pSimulator->Cleanup(); - - // Delete hardware simulator instance - if (NULL != pDevice->m_SimulatorInstance) - { - WdfObjectDelete(pDevice->m_SimulatorInstance); - pDevice->m_SimulatorInstance = NULL; - } - - // Delete sensor instance - if (NULL != pDevice->m_SensorInstance) - { - WdfObjectDelete(pDevice->m_SensorInstance); - } - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// This routine is invoked by the framework to program the device to goto -// D0, which is the working state. The framework invokes callback every -// time the hardware needs to be (re-)initialized. This includes after -// IRP_MN_START_DEVICE, IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE, -// and IRP_MN_SET_POWER-D0. -// Returns an NTSTATUS code -NTSTATUS SdoDevice::OnD0Entry( - _In_ WDFDEVICE Device, // Supplies a handle to the framework device object - _In_ WDF_POWER_DEVICE_STATE /*PreviousState*/) // WDF_POWER_DEVICE_STATE-typed enumerator that identifies - // the device power state that the device was in before this transition to D0 -{ - PSdoDevice pDevice; - SENSOROBJECT SensorInstance = nullptr; - ULONG SensorInstanceCount = 1; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // Get sensor instance - Status = SensorsCxDeviceGetSensorList(Device, &SensorInstance, &SensorInstanceCount); - if (!NT_SUCCESS(Status) || - 0 == SensorInstanceCount || - NULL == SensorInstance) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! SensorsCxDeviceGetSensorList failed %!STATUS!", Status); - goto Exit; - } - - pDevice = GetSdoContextFromSensorInstance(SensorInstance); - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! GetSdoContextFromSensorInstance failed %!STATUS!", Status); - goto Exit; - } - - // Power on sensor - pDevice->m_PoweredOn = TRUE; - InitPropVariantFromUInt32(SensorState_Idle, - &(pDevice->m_pProperties->List[SENSOR_PROPERTY_STATE].Value)); - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} - -// This routine is invoked by the framework to program the device to go into -// a certain Dx state. The framework invokes callback every the the device is -// leaving the D0 state, which happens when the device is stopped, when it is -// removed, and when it is powered off. -// Returns an NTSTATUS code -NTSTATUS -SdoDevice::OnD0Exit( - _In_ WDFDEVICE Device, // Supplies a handle to the framework device object - _In_ WDF_POWER_DEVICE_STATE /*TargetState*/) // Supplies the device power state which the device will be put - // in once the callback is complete -{ - PSdoDevice pDevice; - SENSOROBJECT SensorInstance = nullptr; - ULONG SensorInstanceCount = 1; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - // Get sensor instance - Status = SensorsCxDeviceGetSensorList(Device, &SensorInstance, &SensorInstanceCount); - if (!NT_SUCCESS(Status) || - 0 == SensorInstanceCount || - NULL == SensorInstance) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! SensorsCxDeviceGetSensorList failed %!STATUS!", Status); - goto Exit; - } - - pDevice = GetSdoContextFromSensorInstance(SensorInstance); - if (nullptr == pDevice) - { - Status = STATUS_INVALID_PARAMETER; - TraceError("SDOS %!FUNC! GetSdoContextFromSensorInstance failed %!STATUS!", Status); - goto Exit; - } - - // Power off sensor - pDevice->m_PoweredOn = FALSE; - -Exit: - SENSOR_FunctionExit(Status); - return Status; -} diff --git a/SimpleDeviceOrientationSensor/driver.cpp b/SimpleDeviceOrientationSensor/driver.cpp deleted file mode 100644 index f3ed004..0000000 --- a/SimpleDeviceOrientationSensor/driver.cpp +++ /dev/null @@ -1,75 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved. -// -//Abstract: -// -// This module contains the implementation of entry and exit point of sample simple device orientation sensor driver. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#include "Device.h" -#include "Driver.h" - -#include "Driver.tmh" - -// This routine is the driver initialization entry point. -// Returns an NTSTATUS code -NTSTATUS DriverEntry( - _In_ PDRIVER_OBJECT DriverObject, // Pointer to the driver object created by the I/O manager - _In_ PUNICODE_STRING RegistryPath) // Pointer to the driver specific registry key -{ - WDF_DRIVER_CONFIG DriverConfig; - NTSTATUS Status = STATUS_SUCCESS; - - // - // Initialize WPP Tracing - // - WPP_INIT_TRACING(DriverObject, NULL); - - SENSOR_FunctionEnter(); - - DriverConfig.DriverPoolTag = SENSORV2_POOL_TAG_SDO; - - // - // Initialize the driver configuration structure. - // - WDF_DRIVER_CONFIG_INIT(&DriverConfig, SdoDevice::OnDeviceAdd); - DriverConfig.EvtDriverUnload = OnDriverUnload; - - // - // Create a framework driver object to represent our driver. - // - Status = WdfDriverCreate(DriverObject, - RegistryPath, - WDF_NO_OBJECT_ATTRIBUTES, - &DriverConfig, - WDF_NO_HANDLE); - - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! WdfDriverCreate failed: %!STATUS!", Status); - goto Exit; - } - -Exit: - SENSOR_FunctionExit(Status); - - return Status; -} - -// This routine is called when the driver unloads. -VOID OnDriverUnload( - _In_ WDFDRIVER Driver) // driver object -{ - SENSOR_FunctionEnter(); - - SENSOR_FunctionExit(STATUS_SUCCESS); - - // WPP_CLEANUP doesn't actually use the Driver parameter - // So we need to set it as unreferenced. - UNREFERENCED_PARAMETER(Driver); - WPP_CLEANUP(Driver); - - return; -} \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/hardwaresimulator.cpp b/SimpleDeviceOrientationSensor/hardwaresimulator.cpp deleted file mode 100644 index 759338c..0000000 --- a/SimpleDeviceOrientationSensor/hardwaresimulator.cpp +++ /dev/null @@ -1,248 +0,0 @@ -//Copyright (C) Microsoft Corporation, All Rights Reserved. -// -//Abstract: -// -// This module contains the implementation of the simple device orientation sensor sample -// hardware simulator. -// -//Environment: -// -// Windows User-Mode Driver Framework (UMDF) - -#include "HardwareSimulator.h" - -#include "HardwareSimulator.tmh" - -// Simulated device orientations -const ABI::Windows::Devices::Sensors::SimpleOrientation OrientationData[] = { - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Facedown, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_NotRotated, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Faceup, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Rotated90DegreesCounterclockwise, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Facedown, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Rotated180DegreesCounterclockwise, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Faceup, - ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Rotated270DegreesCounterclockwise -}; - -HardwareSimulator::_HardwareSimulator() : - m_Index(0), - m_Lock(NULL), - m_State(SimulatorState_NotInitialized), - m_SimulatorInstance(NULL), - m_Timer(NULL) -{ -} - -HardwareSimulator::~_HardwareSimulator() -{ -} - -// This static routine performs simulator initialization. The routine creates a -// timer object that periodically updates the m_Index location -// Returns an NTSTATUS code -NTSTATUS HardwareSimulator::Initialize( - _In_ WDFDEVICE Device, // WDF device representing the sensor - _Out_ WDFOBJECT *SimulatorInstance) // Instance of the WDF object for the simulator -{ - PHardwareSimulator pSimulator = nullptr; - NTSTATUS Status = STATUS_SUCCESS; - WDF_OBJECT_ATTRIBUTES HardwareSimulatorAttributes = {}; - - SENSOR_FunctionEnter(); - - // Create WDFOBJECT for the hardware simulator - WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&HardwareSimulatorAttributes, HardwareSimulator); - HardwareSimulatorAttributes.ParentObject = Device; - - Status = WdfObjectCreate(&HardwareSimulatorAttributes, SimulatorInstance); - if (!NT_SUCCESS(Status)) - { - TraceError("SDOS %!FUNC! WdfObjectCreate failed %!STATUS!", Status); - goto Exit; - } - - pSimulator = GetHardwareSimulatorContextFromInstance(*SimulatorInstance); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - goto Exit; - } - - pSimulator->InitializeInternal(*SimulatorInstance); - -Exit: - - SENSOR_FunctionExit(Status); - - return Status; -} - -// Internal routine to perform simulator initialization -// Returns an NTSTATUS code -NTSTATUS HardwareSimulator::InitializeInternal( - _In_ WDFOBJECT SimulatorInstance) // Instance of the WDF object for the simulator -{ - NTSTATUS Status = STATUS_SUCCESS; - WDF_OBJECT_ATTRIBUTES TimerAttributes = {}; - WDF_TIMER_CONFIG TimerConfig = {}; - - SENSOR_FunctionEnter(); - - // Only initialize the simulator if it is in the "not initialized" state - if (SimulatorState_NotInitialized == m_State) - { - // Create Lock - Status = WdfWaitLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &m_Lock); - if (!NT_SUCCESS(Status)) - { - m_Lock = NULL; - - TraceError("SDOS %!FUNC! WdfWaitLockCreate failed %!STATUS!", Status); - goto Exit; - } - - // Create a timer object for simulation updates - WDF_TIMER_CONFIG_INIT(&TimerConfig, HardwareSimulator::OnTimerExpire); - WDF_OBJECT_ATTRIBUTES_INIT(&TimerAttributes); - TimerAttributes.ParentObject = SimulatorInstance; - TimerAttributes.ExecutionLevel = WdfExecutionLevelPassive; - - Status = WdfTimerCreate(&TimerConfig, &TimerAttributes, &m_Timer); - if (!NT_SUCCESS(Status)) - { - m_Timer = NULL; - - TraceError("SDOS %!FUNC! WdfTimerCreate failed %!STATUS!", Status); - goto Exit; - } - - // Set the simulator state to "initialized" - m_State = SimulatorState_Initialized; - m_SimulatorInstance = SimulatorInstance; - } - -Exit: - if (!NT_SUCCESS(Status) && NULL != m_Lock) - { - WdfObjectDelete(m_Lock); - m_Lock = NULL; - } - - SENSOR_FunctionExit(Status); - - return Status; -} - -// This routine perform a simulator cleanup -// Returns an NTSTATUS code -NTSTATUS HardwareSimulator::Cleanup() -{ - NTSTATUS status = STATUS_SUCCESS; - - if (SimulatorState_Started == m_State) - { - Stop(); - } - - // Delete lock - if (NULL != m_Lock) - { - WdfObjectDelete(m_Lock); - m_Lock = NULL; - } - - // Set the simulator state to "not initialized" - m_State = SimulatorState_NotInitialized; - - return status; -} - -// This routine starts the simulator -// Returns an NTSTATUS code -NTSTATUS HardwareSimulator::Start() -{ - NTSTATUS status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (SimulatorState_Initialized == m_State) - { - WdfTimerStart(m_Timer, WDF_REL_TIMEOUT_IN_MS(HardwareSimulator_HardwareInterval)); - m_State = SimulatorState_Started; - } - - SENSOR_FunctionExit(status); - - return status; -} - -// This routine stops the simulator -// Returns an NTSTATUS code -NTSTATUS HardwareSimulator::Stop() -{ - NTSTATUS status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - if (SimulatorState_Started == m_State) - { - WdfTimerStop(m_Timer, TRUE); - m_State = SimulatorState_Initialized; - } - - SENSOR_FunctionExit(status); - - return status; -} - -// This callback is called when the simulator wait time has expired and the simulator -// is ready to switch to the next sample. The callback updates the sample index and -// schedules the next wake up time. -VOID HardwareSimulator::OnTimerExpire( - _In_ WDFTIMER Timer) // WDF timer object -{ - HardwareSimulator *pSimulator = nullptr; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - pSimulator = GetHardwareSimulatorContextFromInstance(WdfTimerGetParentObject(Timer)); - if (nullptr == pSimulator) - { - Status = STATUS_INSUFFICIENT_RESOURCES; - TraceError("SDOS %!FUNC! GetHardwareSimulatorContextFromInstance failed %!STATUS!", Status); - } - - if (NT_SUCCESS(Status)) - { - // Increment the sample index, roll over if the index reach the end of the array - WdfWaitLockAcquire(pSimulator->m_Lock, NULL); - pSimulator->m_Index++; - pSimulator->m_Index %= ARRAYSIZE(OrientationData); - WdfWaitLockRelease(pSimulator->m_Lock); - - WdfTimerStart(pSimulator->m_Timer, WDF_REL_TIMEOUT_IN_MS(HardwareSimulator_HardwareInterval)); - } - - SENSOR_FunctionExit(Status); -} - -// This routine returns the current sample from the driver at the current m_Index location. -// Returns one of the ABI::Windows::Devices::Sensors::SimpleOrientation enum values. -ABI::Windows::Devices::Sensors::SimpleOrientation HardwareSimulator::GetOrientation() -{ - ABI::Windows::Devices::Sensors::SimpleOrientation Sample = ABI::Windows::Devices::Sensors::SimpleOrientation::SimpleOrientation_Faceup; - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - WdfWaitLockAcquire(m_Lock, NULL); - Sample = OrientationData[m_Index]; - WdfWaitLockRelease(m_Lock); - - SENSOR_FunctionExit(Status); - - return Sample; -} \ No newline at end of file diff --git a/SimpleDeviceOrientationSensor/readme.md b/SimpleDeviceOrientationSensor/readme.md deleted file mode 100644 index c33739c..0000000 --- a/SimpleDeviceOrientationSensor/readme.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -topic: sample -description: "Demonstrates how to write a UMDF v2 sensor driver to output simple device orientation values." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# SimpleDeviceOrientationSensor - -This sample shows you how to write a UMDF v2 sensor driver to output simple device orientation values.