From 4c131fd627b55f677b7aab30666279b1dca1d1d2 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 25 Jan 2025 19:44:32 +0800 Subject: [PATCH 01/19] Add .gitattributes to properly track files Copied from Microsoft/windows-driver-samples Signed-off-by: Daniel Schaefer --- .gitattributes | 38 ++++++++++++++++++ SensorsComboDriver/SensorsComboDriver.inx | Bin 4746 -> 0 bytes .../SimpleDeviceOrientationSensor.inx | Bin 5444 -> 0 bytes 3 files changed, 38 insertions(+) create mode 100644 .gitattributes delete mode 100644 SensorsComboDriver/SensorsComboDriver.inx delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx 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/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx deleted file mode 100644 index 699be4deea0fc567282806aca7f21cff9dc74f77..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4746 zcmb`LYfl?T6o${|O8pO(g{3sb4v^5KLHPi7NRYxsp}>cGzVn1-- zW-j5Q5P@J;KdP-r}6X2{dnI;?Kkx_#to6nLfKtq*;l*-wn8tS!plhW^wpq3g4D z2c9FIo@Z;sRo6aq;(u(&$2#^f<}#!PDM+%N*r_SWc38jLaD0X0drAyj}@P=LU=z% zhhOm8dC;Z_g88?q?p1B)p(i;5_+EnTDNif*YsJpll+A$4gi#!XwqsVby=`q`?@{p0 zJ3B;M`O#zNw=lcU+Zpu2<&v*LS=S4GO^0d#~4)!nbMN+zW=oo&Aw&Eq) zqNmDhUm<6RrMaBHY}Jz2v!-*&+ml-~>E2q4mtD+A=>2l7OLX zEoO&fp4<8iZ>*rP#wF}~Vv9U=cwQ=uk25>QMA{oPO6&u+OzbnBa^Eb66_WN2tS7;D z3D)+|JY{uylhdiWrnEDy_o0yq?moB-TI>*R34yZ~U!zyz4Fyqq43iV{Ew>-9MU3@XTeXmoKRF2l#7~oam7O+Fb?#iyi!< z%8_DQd5yA2nkc5#)#O#7J`R!gZWcu%qcd$U!=WcRxFFA4@s>M-OlfDgp&N0`@ zV@X->yR&D%@<@Al%&cYVlQ34a9fh^NPo$xXxMrm~oDut^`ikPtq!kD31@g3{N}g)2 zdcuqFCR&&0UX-lG5{>BAW@KKTNnX9wgL>9hyOq2j6R)p};!eoXTt-CaTlqy%RpcIh zberWz0ow*XP`{Xffco78Po?3#Skdoe{Sgs8$Rgq(>mtiK&#HEDu5O)Db*htJd8Xw3 z=xnWaLG?6X8+FO=b+r<1k-NvL?;)>=WO4r-?tQw(giGCyx>a#s4^==tRb9HGtXSc8 zIqCe7d2^5Ir!z}J1uR>V%i0O~^%3b~v^!w@z|T9oSv=E_o6*8ev{%I&hpfJ0)JdgJ zPg|8N3%l4p4&39qFX^5C*F>Lt*XvN!?+w) z4HkmUPaWcmgH(~T+uVC zms~0BG&&Q@k~91kYq)p#!gFYUV&e%Uoc899I^ZQXh>s3!p zWeM}%T=Kk*KL6jrWmFNI^>0J$MPsMsk<_f9Ki`@LyOnZZ|6>e;Z}rcM;@1C#QI*>W zaVF{g;QwhjDZC=`{6Cq5Y*R(oTG^)avsP9q{2Y1(?-9QX=tZHN)amyvH0p-63+SJe h2K(?OQQ?tRTseZXPUfA$d2Ee5Q5|S!=fgVD^B?P7;Wz*Q diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx deleted file mode 100644 index b2ccfaba9d2db47582c2ce274c95f324a473ff20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5444 zcmb_gZEqS!5T4JG`X3N7Qkn#8lelSv`oV@cu@t{3*x^G`MfP#HvcTdfVrj zxykLGaiJVqamVfL&OGzX%kJJke{aeId5HFd+>=&zZOd4$S&+lE{y^ zAEGb8o3Tvs8|XWZpI`>B=ja*Y-$)u5U6Eb+fK~})P4y|o{1m;PaP4DksQ(c2`*MwW zDaIZ_=12T{mW`oQwl4I1gjSB~;P*+9rE;vgQXrTGXu23NQp^)*JAl;vNawCx;O$H; zNN_J|vl$gwJj`$n)ZPl7DVMrvDW5KZZU)|nKGaLgo6x>hKwpXQSMIPNmc=>r5BZx! zmK;QQa(|G?F>sOjqIGBJbL7TlqCR{Eq^F34E48HxuaIYZSG2sGN2q-OZP)N=AOD*2 z4%~IXMOXcAeh%5JV)P6si#Wnas!JX5y{Y`L|E;`HzGy9D^f!IONV>!mxw;0M^c&l+ z_*G>?dKxdp(gPauc#7Vt&TYfz=U|V%4IAf%XsJCP`vQ7~urt^5O?G5kp5oe($7oN0 zyp8))^w#n8Got1v{M$p{9(uC1eas^j2`ovjWCZho|&JFusj<&c%Go&BA^ACO`S^{dpg!6PBjj1R6>f_ ze2j7LBK#b2hPv3vDhl-tpo#TshF;Td`W#&o7KL*RX%{vy{u0dL_$lm~ey@Lybvv`M z2A!;(L+COstjj}i;uW|CEo{{+R{u+jd)c*=sjhuk&YI6gKDQMGwHty%ARfU|vcy_z zIXB6CLA&O^&!g1ju8#4&GUhABBVe?g-j&zLrI*NVMj2y`Kei^?mNvJeh00QD zW!25C_ulXx;yyqIxhJ?<+-~8_O5uI{&Yp@AD7_YWIn=*AZ=U0|EUU_R!Xt)}zx;|z zOUg%q>$V6m-?A@(SFhoX6g8uV>d1Qf8rKGV&bm8{meucOCfNW7lIlTk}){b+MP#==J!^Bs$hsA-Cc@vZ}`O0?!}Z zp)o4*eRsaHyS%rha;|7Qt4gljSIKqpP?YXAEaIf6SyIuO$f`F)o{%5*gjLYxt(TJ? zqHT~x#96j)k1d&3AHA>KZjzO2^*qUA+fHrdXTAlj&#X!L4%+dTtt+8U+Z~$6USe&d z&d+*JvDZ&D;_Zw<*6d8p{qC~!LS0@Nk8$GtBa4y~>^ymPO|YuQ_T{>cP@P#@c9C~| zurG7=gFLE6>?Vh5s|E(Je8;N1y`OqQ|#i4nrUGhwvSZ0kGnnJxk_bi)UF!L_D;@zoXEjU$7_UPPrMaIsA@7`!3;Q z-@VyMjVur4D=fdjKl?%wj;22soogJ=vUlRH7EX0>^;m7+J%tti1uFg?W8VhuI%O}5 zyExA5I7LkHTSQ%bF~hy6$FwgxMHQtldcI5hU3v_~>aptQ1>g4?K0^^oE$=%+%E)UW OTUn#(*>{CyqV-=ov0v-} From cfde0fe0fb5117d138b8deb1ddbfc7b101d6be3a Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Thu, 6 Feb 2025 09:29:51 +0800 Subject: [PATCH 02/19] Add back inx file With new .gitattributes Signed-off-by: Daniel Schaefer --- SensorsComboDriver/SensorsComboDriver.inx | 83 ++++++++++++++++++ .../SimpleDeviceOrientationSensor.inx | 86 +++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 SensorsComboDriver/SensorsComboDriver.inx create mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx new file mode 100644 index 0000000..00c1eeb --- /dev/null +++ b/SensorsComboDriver/SensorsComboDriver.inx @@ -0,0 +1,83 @@ +/*++ +; +;Copyright (c) Microsoft Corporation. All rights reserved. +; +;Module Name: +; SensorsComboDriver.INF +; +;Abstract: +; INF file for installing the Sensors Combo Driver +; +;Installation Notes: +; Using Devcon: Type "devcon install SensorsComboDriver.inf umdf2\SensorsComboDriver" to install +; +;--*/ +[Version] +Signature = "$WINDOWS NT$" +Class = Sensor +ClassGuid = {5175D334-C371-4806-B3BA-71FD53C9258D} +Provider = %PROVIDER% +CatalogFile = SensorsComboDriver.cat +DriverVer = 8/29/2014,2.00.00.03 +PnpLockdown = 1 + +[SourceDisksNames] +1 = %MediaDescription%,,,"" + +[SourceDisksFiles] +SensorsComboDriver.dll = 1,, + +[Manufacturer] +%PROVIDER% = SensorsComboDriver_Device, NT$ARCH$.10.0...22000 + +;******************************* +; Combo Driver Install Section +;******************************* + +[SensorsComboDriver_Device.NT$ARCH$.10.0...22000] +; DisplayName Section DeviceId +; ----------- ------- -------- +%SensorsComboDriver_DevDesc% = SensorsComboDriver_Inst, umdf2\SensorsComboDriver + +[SensorsComboDriver_Inst.NT] +Include=WUDFRD.inf +Needs=WUDFRD.NT +CopyFiles = SensorsComboDriverCopy + +[SensorsComboDriverCopy] +SensorsComboDriver.dll + +[SensorsComboDriver_Inst.NT.HW] +Include=WUDFRD.inf +Needs=WUDFRD.NT.HW + +[DestinationDirs] +;12 == Windows\System32\Drivers\UMDF +DefaultDestDir = 12,UMDF + +;-------------- Service installation +[SensorsComboDriver_Inst.NT.Services] +Include=WUDFRD.inf +Needs=WUDFRD.NT.Services + +;-------------- WDF specific section + +[SensorsComboDriver_Inst.NT.Wdf] +UmdfService = SensorsComboDriver, SensorsComboDriver_Install +UmdfServiceOrder = SensorsComboDriver +UmdfDirectHardwareAccess = AllowDirectHardwareAccess +UmdfFileObjectPolicy = AllowNullAndUnknownFileObjects +UmdfFsContextUsePolicy = CannotUseFsContexts + +[SensorsComboDriver_Install] +UmdfLibraryVersion = $UMDFVERSION$ +ServiceBinary = %12%\UMDF\SensorsComboDriver.dll +UmdfExtensions = SensorsCx0102 + +[Strings] +;Localizable Strings +MediaDescription = "Windows Sensors Combo Driver" +PROVIDER = "Manufacturer Name" +SensorsComboDriver_DevDesc = "Sensors Combo Driver - Ambient Light, Barometer, Gyroscope, Magnetometer, Proximity, and Relative Fusion, and more." + +;Non-Localizable Strings diff --git a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx new file mode 100644 index 0000000..9ea7328 --- /dev/null +++ b/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx @@ -0,0 +1,86 @@ +/*++ +; +;Copyright (c) Microsoft Corporation. All rights reserved. +; +;Module Name: +; SimpleDeviceOrientationSensor.INF +; +;Abstract: +; INF file for installing the Sensors 2.0 Simple Device Orientation Sensor Driver +; +;Installation Notes: +; Using Devcon: Type "devcon install SimpleDeviceOrientationSensor.inf umdf2\SDOSampleSensor" to install +; +;--*/ + +[Version] +Signature = "$WINDOWS NT$" +Class = Sensor +ClassGuid = {5175D334-C371-4806-B3BA-71FD53C9258D} +Provider = %ProviderName% +CatalogFile = SimpleDeviceOrientationSensor.cat +DriverVer = 08/14/2014,2.0.0.1 +PnpLockdown = 1 + +[DestinationDirs] +;12 == Windows\System32\Drivers\UMDF +DefaultDestDir = 12,UMDF + +[SourceDisksNames] +1 = %MediaDescription%,,,"" + +[SourceDisksFiles] +SimpleDeviceOrientationSensor.dll = 1,, + +[Manufacturer] +%ManufacturerName% = SimpleDeviceOrientationSensor_Device, NT$ARCH$.10.0...22000 + +;******************************* +; Simple Device Orientation Sensor Install Section +;******************************* + +[SimpleDeviceOrientationSensor_Device.NT$ARCH$.10.0...22000] +; DisplayName Section DeviceId +; ----------- ------- -------- +%SimpleDeviceOrientationSensor_DevDesc% = SimpleDeviceOrientationSensor_Inst, umdf2\SDOSampleSensor + +[SimpleDeviceOrientationSensor_Inst.NT] +Include=WUDFRD.inf +Needs=WUDFRD.NT +CopyFiles = SimpleDeviceOrientationSensorDriverCopy + +[SimpleDeviceOrientationSensorDriverCopy] +SimpleDeviceOrientationSensor.dll + +[SimpleDeviceOrientationSensor_Inst.NT.HW] +Include=WUDFRD.inf +Needs=WUDFRD.NT.HW + +;-------------- Service installation + +[SimpleDeviceOrientationSensor_Inst.NT.Services] +Include=WUDFRD.inf +Needs=WUDFRD.NT.Services + +;-------------- WDF specific section + +[SimpleDeviceOrientationSensor_Inst.NT.Wdf] +UmdfService = SimpleDeviceOrientationSensor, SimpleDeviceOrientationSensor_Install +UmdfServiceOrder = SimpleDeviceOrientationSensor +UmdfDirectHardwareAccess = AllowDirectHardwareAccess +UmdfFileObjectPolicy = AllowNullAndUnknownFileObjects +UmdfFsContextUsePolicy = CannotUseFsContexts + +[SimpleDeviceOrientationSensor_Install] +UmdfLibraryVersion = $UMDFVERSION$ +ServiceBinary = %12%\UMDF\SimpleDeviceOrientationSensor.dll +UmdfExtensions = SensorsCx0102 + +[Strings] +;Localizable Strings +MediaDescription = "Windows Simple Device Orientation Sensor sample Driver" +ProviderName = "TODO-Set-Provider" +ManufacturerName = "TODO-Set-Manufacturer" +SimpleDeviceOrientationSensor_DevDesc = "Simple Device Orientation Sensor sample" + +;Non-Localizable Strings From 386fd242fb661a3d0ce5ca1966ddba8049b1a070 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 21 Jan 2025 20:54:49 +0800 Subject: [PATCH 03/19] SensorsComboDriver: Remove barometer Signed-off-by: Daniel Schaefer --- SensorsComboDriver/BarClient.cpp | 464 ------------------ SensorsComboDriver/Clients.h | 21 - SensorsComboDriver/Device.cpp | 3 - SensorsComboDriver/SensorsComboDriver.vcxproj | 2 +- .../SensorsComboDriver.vcxproj.Filters | 3 - 5 files changed, 1 insertion(+), 492 deletions(-) delete mode 100644 SensorsComboDriver/BarClient.cpp 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/Clients.h b/SensorsComboDriver/Clients.h index a8992fa..0850847 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/Clients.h @@ -204,27 +204,6 @@ typedef class _AlsDevice : public _ComboDevice -// -// 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 ------------------------------------------------------------------ // diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index b93bbbd..4f19393 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -22,7 +22,6 @@ enum Device { Device_Als = 0, - Device_Bar, Device_GeomagneticOrientation, Device_GravityVector, Device_Gyr, @@ -44,7 +43,6 @@ inline size_t GetDeviceSizeAtIndex( switch (static_cast(Index)) { 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; @@ -65,7 +63,6 @@ void AllocateDeviceAtIndex( switch (static_cast(Index)) { 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; diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj b/SensorsComboDriver/SensorsComboDriver.vcxproj index 6c7fcd2..4a1199c 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj @@ -76,7 +76,7 @@ - + true true SensorsComboDriver diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters index 7e7513b..cc264b7 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters @@ -22,9 +22,6 @@ Source Files - - Source Files - Source Files From 1e52459b65bb8b0b248a5e06f449d5451c8d9184 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 21 Jan 2025 21:04:00 +0800 Subject: [PATCH 04/19] SensorsComboDriver: Remove all except ALS and accel Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Clients.h | 138 ----- SensorsComboDriver/Device.cpp | 18 - .../GeomagneticOrientationClient.cpp | 485 ---------------- SensorsComboDriver/GravityVectorClient.cpp | 499 ---------------- SensorsComboDriver/GyrClient.cpp | 510 ----------------- SensorsComboDriver/MagClient.cpp | 537 ------------------ SensorsComboDriver/PrxClient.cpp | 458 --------------- SensorsComboDriver/SensorsComboDriver.vcxproj | 2 +- .../SensorsComboDriver.vcxproj.Filters | 18 - SensorsComboDriver/relativefusionclient.cpp | 515 ----------------- 10 files changed, 1 insertion(+), 3179 deletions(-) delete mode 100644 SensorsComboDriver/GeomagneticOrientationClient.cpp delete mode 100644 SensorsComboDriver/GravityVectorClient.cpp delete mode 100644 SensorsComboDriver/GyrClient.cpp delete mode 100644 SensorsComboDriver/MagClient.cpp delete mode 100644 SensorsComboDriver/PrxClient.cpp delete mode 100644 SensorsComboDriver/relativefusionclient.cpp diff --git a/SensorsComboDriver/Clients.h b/SensorsComboDriver/Clients.h index 0850847..3471d39 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/Clients.h @@ -204,99 +204,6 @@ typedef class _AlsDevice : public _ComboDevice -// -// 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 -------------------------------------------------------------- // @@ -321,48 +228,3 @@ typedef class _LinearAccelerometerDevice : public _ComboDevice 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 ------------------------------------------------------------------ -// -typedef class _GeomagneticOrientationDevice : public _ComboDevice -{ -private: - - typedef struct _GeomagneticOrientationSample - { - QUATERNION Quaternion; - FLOAT RotationAngle_Degrees; - FLOAT DeclinationAngle_Degrees; - } GeomagneticOrientationSample, *PGeomagneticOrientationSample; - - GeomagneticOrientationSample m_CachedThresholds; - GeomagneticOrientationSample m_CachedData; - GeomagneticOrientationSample m_LastSample; - -public: - - NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); - NTSTATUS UpdateCachedThreshold(); - -} GeomagneticOrientationDevice, *PGeomagneticOrientationDevice; diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 4f19393..0cec6cc 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -22,13 +22,7 @@ enum Device { Device_Als = 0, - Device_GeomagneticOrientation, - Device_GravityVector, - Device_Gyr, Device_LinearAccelerometer, - Device_Mag, - Device_Prx, - Device_RelativeFusion, // Keep this last Device_Count }; @@ -43,13 +37,7 @@ inline size_t GetDeviceSizeAtIndex( switch (static_cast(Index)) { case Device_Als: result = sizeof(AlsDevice); break; - case Device_GeomagneticOrientation: result = sizeof(GeomagneticOrientationDevice); break; - case Device_GravityVector: result = sizeof(GravityVectorDevice); break; - case Device_Gyr: result = sizeof(GyrDevice); break; 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; default: break; // invalid } return result; @@ -63,13 +51,7 @@ void AllocateDeviceAtIndex( switch (static_cast(Index)) { case Device_Als: *ppDevice = new(*ppDevice) AlsDevice; 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; 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; default: break; // invalid (let driver fail) } 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/GravityVectorClient.cpp b/SensorsComboDriver/GravityVectorClient.cpp deleted file mode 100644 index 4dc53d7..0000000 --- a/SensorsComboDriver/GravityVectorClient.cpp +++ /dev/null @@ -1,499 +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 "GravityVectorClient.tmh" - - - -#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); - -// 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; - -//------------------------------------------------------------------------------ -// 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 -GravityVectorDevice::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! GRA 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! GRA 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_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pEnumerationProperties); - if (!NT_SUCCESS(Status) || m_pEnumerationProperties == nullptr) - { - TraceError("COMBO %!FUNC! GRA 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_GravityVector, - &(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"Gravity Vector 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_GravityVectorDevice_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(GRAVITY_VECTOR_DATA_COUNT); - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pSupportedDataFields); - if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) - { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); - m_pSupportedDataFields->Count = GRAVITY_VECTOR_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; - } - - // - // Data - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GRAVITY_VECTOR_DATA_COUNT); - FILETIME Time = {0}; - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pData); - if (!NT_SUCCESS(Status) || m_pData == nullptr) - { - TraceError("COMBO %!FUNC! GRA WdfMemoryCreate failed %!STATUS!", Status); - goto Exit; - } - - SENSOR_COLLECTION_LIST_INIT(m_pData, Size); - m_pData->Count = GRAVITY_VECTOR_DATA_COUNT; - - m_pData->List[GRAVITY_VECTOR_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; - GetSystemTimePreciseAsFileTime(&Time); - InitPropVariantFromFileTime(&Time, &(m_pData->List[GRAVITY_VECTOR_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[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_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 - // - { - m_IntervalMs = GravityVectorDevice_Default_MinDataInterval; - - 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_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pProperties); - if (!NT_SUCCESS(Status) || m_pProperties == nullptr) - { - TraceError("GRA %!FUNC! 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(GravityVectorDevice_Default_MinDataInterval, - &(m_pProperties->List[SENSOR_COMMON_PROPERTY_MIN_INTERVAL].Value)); - - 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_GravityVector, - &(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_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pDataFieldProperties); - if (!NT_SUCCESS(Status) || m_pDataFieldProperties == nullptr) - { - TraceError("COMBO %!FUNC! GRA 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(GravityVectorDevice_Axis_Resolution, - &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); - - m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; - InitPropVariantFromFloat(GravityVectorDevice_Axis_Minimum, - &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); - - m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; - InitPropVariantFromFloat(GravityVectorDevice_Axis_Maximum, - &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); - } - - // - // Set default threshold - // - { - WDF_OBJECT_ATTRIBUTES MemoryAttributes; - WDFMEMORY MemoryHandle = NULL; - - ULONG Size = SENSOR_COLLECTION_LIST_SIZE(GRAVITY_VECTOR_DATA_COUNT - 1); // Timestamp does not have thresholds - - MemoryHandle = NULL; - WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); - MemoryAttributes.ParentObject = SensorInstance; - Status = WdfMemoryCreate(&MemoryAttributes, - PagedPool, - SENSORV2_POOL_TAG_GRAVITY_VECTOR, - Size, - &MemoryHandle, - (PVOID*)&m_pThresholds); - if (!NT_SUCCESS(Status) || m_pThresholds == nullptr) - { - TraceError("COMBO %!FUNC! GRA 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->List[GRAVITY_VECTOR_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; - InitPropVariantFromFloat(GravityVectorDevice_Default_Axis_Threshold, - &(m_pThresholds->List[GRAVITY_VECTOR_DATA_Z].Value)); - - m_CachedThresholds.X = GravityVectorDevice_Default_Axis_Threshold; - m_CachedThresholds.Y = GravityVectorDevice_Default_Axis_Threshold; - m_CachedThresholds.Z = GravityVectorDevice_Default_Axis_Threshold; - - 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 -GravityVectorDevice::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! GRA 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[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)); - - GetSystemTimePreciseAsFileTime(&TimeStamp); - InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[GRAVITY_VECTOR_DATA_TIMESTAMP].Value)); - - SensorsCxSensorDataReady(m_SensorInstance, m_pData); - m_FirstSample = FALSE; - } - else - { - Status = STATUS_DATA_NOT_ACCEPTED; - TraceInformation("COMBO %!FUNC! GRA 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 -GravityVectorDevice::UpdateCachedThreshold( - ) -{ - NTSTATUS Status = STATUS_SUCCESS; - - SENSOR_FunctionEnter(); - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AccelerationX_Gs, - &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); - 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.vcxproj b/SensorsComboDriver/SensorsComboDriver.vcxproj index 4a1199c..d02c2da 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj @@ -76,7 +76,7 @@ - + true true SensorsComboDriver diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters index cc264b7..ed6c62e 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters @@ -31,27 +31,9 @@ Source Files - - Source Files - - - Source Files - - - Source Files - Source Files - - Source Files - - - Source Files - - - Source Files - Source Files 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 From 25e602f68e717f18e887eff6cccef050081740f8 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 21 Jan 2025 21:32:19 +0800 Subject: [PATCH 05/19] SensorsComboDriver: Add orientation sensor Just copied from accel and renamed. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Clients.h | 27 + SensorsComboDriver/Device.cpp | 3 + SensorsComboDriver/SensorsComboDriver.vcxproj | 2 +- .../SensorsComboDriver.vcxproj.Filters | 3 + .../SimpleDeviceOrientationClient.cpp | 508 ++++++++++++++++++ 5 files changed, 542 insertions(+), 1 deletion(-) create mode 100644 SensorsComboDriver/SimpleDeviceOrientationClient.cpp diff --git a/SensorsComboDriver/Clients.h b/SensorsComboDriver/Clients.h index 3471d39..c716cd8 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/Clients.h @@ -228,3 +228,30 @@ typedef class _LinearAccelerometerDevice : public _ComboDevice NTSTATUS UpdateCachedThreshold(); } LinearAccelerometerDevice, *PLinearAccelerometerDevice; + + + +// +// Simple Device Orientation -------------------------------------------------- +// +typedef class _SimpleDeviceOrientationDevice : public _ComboDevice +{ +private: + + typedef struct _SimpleDeviceOrientationSample + { + VEC3D Axis; + BOOL Shake; + } SimpleDeviceOrientationSample, *PSimpleDeviceOrientationSample; + + SimpleDeviceOrientationSample m_CachedThresholds; + SimpleDeviceOrientationSample m_CachedData; + SimpleDeviceOrientationSample m_LastSample; + +public: + + NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); + NTSTATUS GetData(); + NTSTATUS UpdateCachedThreshold(); + +} SimpleDeviceOrientationDevice, *PSimpleDeviceOrientationDevice; diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 0cec6cc..3d8c9d5 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -22,6 +22,7 @@ enum Device { Device_Als = 0, + Device_SimpleDeviceOrientation, Device_LinearAccelerometer, // Keep this last Device_Count @@ -37,6 +38,7 @@ inline size_t GetDeviceSizeAtIndex( switch (static_cast(Index)) { case Device_Als: result = sizeof(AlsDevice); break; + case Device_SimpleDeviceOrientation:result = sizeof(SimpleDeviceOrientationDevice); break; case Device_LinearAccelerometer: result = sizeof(LinearAccelerometerDevice); break; default: break; // invalid } @@ -51,6 +53,7 @@ void AllocateDeviceAtIndex( switch (static_cast(Index)) { case Device_Als: *ppDevice = new(*ppDevice) AlsDevice; break; + case Device_SimpleDeviceOrientation:*ppDevice = new(*ppDevice) SimpleDeviceOrientationDevice; break; case Device_LinearAccelerometer: *ppDevice = new(*ppDevice) LinearAccelerometerDevice; break; default: break; // invalid (let driver fail) diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj b/SensorsComboDriver/SensorsComboDriver.vcxproj index d02c2da..0cb3dc0 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj @@ -76,7 +76,7 @@ - + true true SensorsComboDriver diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters index ed6c62e..1e5b51b 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters @@ -31,6 +31,9 @@ Source Files + + Source Files + Source Files diff --git a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp new file mode 100644 index 0000000..9f6efc7 --- /dev/null +++ b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp @@ -0,0 +1,508 @@ +// 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 "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 + +// 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 +{ + LINEAR_ACCELEROMETER_DATA_X = 0, + LINEAR_ACCELEROMETER_DATA_Y, + LINEAR_ACCELEROMETER_DATA_Z, + LINEAR_ACCELEROMETER_DATA_TIMESTAMP, + LINEAR_ACCELEROMETER_DATA_SHAKE, + LINEAR_ACCELEROMETER_DATA_COUNT +} LINEAR_ACCELEROMETER_DATA_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 +SimpleDeviceOrientationDevice::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! LAC 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! LAC 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_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pEnumerationProperties); + if (!NT_SUCCESS(Status) || m_pEnumerationProperties == nullptr) + { + TraceError("COMBO %!FUNC! LAC 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"Manufacturer name", + &(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_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_SimpleDeviceOrientationDevice_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(LINEAR_ACCELEROMETER_DATA_COUNT); + + MemoryHandle = NULL; + WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); + MemoryAttributes.ParentObject = SensorInstance; + Status = WdfMemoryCreate(&MemoryAttributes, + PagedPool, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pSupportedDataFields); + if (!NT_SUCCESS(Status) || m_pSupportedDataFields == nullptr) + { + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); + goto Exit; + } + + SENSOR_PROPERTY_LIST_INIT(m_pSupportedDataFields, Size); + m_pSupportedDataFields->Count = LINEAR_ACCELEROMETER_DATA_COUNT; + + 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_Y] = PKEY_SensorData_AccelerationY_Gs; + m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_Z] = PKEY_SensorData_AccelerationZ_Gs; + m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_SHAKE] = PKEY_SensorData_Shake; + } + + // + // Data + // + { + WDF_OBJECT_ATTRIBUTES MemoryAttributes; + WDFMEMORY MemoryHandle = NULL; + ULONG Size = SENSOR_COLLECTION_LIST_SIZE(LINEAR_ACCELEROMETER_DATA_COUNT); + FILETIME Time = {0}; + + MemoryHandle = NULL; + WDF_OBJECT_ATTRIBUTES_INIT(&MemoryAttributes); + MemoryAttributes.ParentObject = SensorInstance; + Status = WdfMemoryCreate(&MemoryAttributes, + PagedPool, + SENSORV2_POOL_TAG_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pData); + if (!NT_SUCCESS(Status) || m_pData == nullptr) + { + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); + goto Exit; + } + + SENSOR_COLLECTION_LIST_INIT(m_pData, Size); + m_pData->Count = LINEAR_ACCELEROMETER_DATA_COUNT; + + m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].Key = PKEY_SensorData_Timestamp; + GetSystemTimePreciseAsFileTime(&Time); + InitPropVariantFromFileTime(&Time, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].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[LINEAR_ACCELEROMETER_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; + InitPropVariantFromFloat(0.0, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); + + m_pData->List[LINEAR_ACCELEROMETER_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; + InitPropVariantFromFloat(0.0, &(m_pData->List[LINEAR_ACCELEROMETER_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.Axis.X = 0.0f; + m_CachedData.Axis.Y = 0.0f; + m_CachedData.Axis.Z = -1.0f; + m_CachedData.Shake = FALSE; + + m_LastSample.Axis.X = 0.0f; + m_LastSample.Axis.Y = 0.0f; + m_LastSample.Axis.Z = 0.0f; + m_LastSample.Shake = FALSE; + } + + // + // Sensor Properties + // + { + m_IntervalMs = SimpleDeviceOrientationDevice_Default_MinDataInterval; + + 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_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pProperties); + if (!NT_SUCCESS(Status) || m_pProperties == nullptr) + { + TraceError("LAC %!FUNC! 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(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; + 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_SimpleDeviceOrientation, + &(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_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pDataFieldProperties); + if (!NT_SUCCESS(Status) || m_pDataFieldProperties == nullptr) + { + TraceError("COMBO %!FUNC! LAC 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(SimpleDeviceOrientationDevice_Axis_Resolution, + &(m_pDataFieldProperties->List[SENSOR_RESOLUTION].Value)); + + m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Key = PKEY_SensorDataField_RangeMinimum; + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Axis_Minimum, + &(m_pDataFieldProperties->List[SENSOR_MIN_RANGE].Value)); + + m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Key = PKEY_SensorDataField_RangeMaximum; + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Axis_Maximum, + &(m_pDataFieldProperties->List[SENSOR_MAX_RANGE].Value)); + } + + // + // Set default threshold + // + { + WDF_OBJECT_ATTRIBUTES MemoryAttributes; + WDFMEMORY MemoryHandle = NULL; + + 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_LINEAR_ACCELEROMETER, + Size, + &MemoryHandle, + (PVOID*)&m_pThresholds); + if (!NT_SUCCESS(Status) || m_pThresholds == nullptr) + { + TraceError("COMBO %!FUNC! LAC WdfMemoryCreate failed %!STATUS!", Status); + goto Exit; + } + + SENSOR_COLLECTION_LIST_INIT(m_pThresholds, Size); + m_pThresholds->Count = LINEAR_ACCELEROMETER_DATA_COUNT - 2; + + 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_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, + &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); + + m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; + InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, + &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Z].Value)); + + m_CachedThresholds.Axis.X = SimpleDeviceOrientationDevice_Default_Axis_Threshold; + m_CachedThresholds.Axis.Y = SimpleDeviceOrientationDevice_Default_Axis_Threshold; + m_CachedThresholds.Axis.Z = SimpleDeviceOrientationDevice_Default_Axis_Threshold; + + 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 +SimpleDeviceOrientationDevice::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! LAC 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.Axis.X) || + (abs(m_CachedData.Axis.Y - m_LastSample.Axis.Y) >= m_CachedThresholds.Axis.Y) || + (abs(m_CachedData.Axis.Z - m_LastSample.Axis.Z) >= m_CachedThresholds.Axis.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.Shake = m_CachedData.Shake; + + // push to clx + InitPropVariantFromFloat(m_LastSample.Axis.X, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_X].Value)); + InitPropVariantFromFloat(m_LastSample.Axis.Y, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); + InitPropVariantFromFloat(m_LastSample.Axis.Z, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_Z].Value)); + + InitPropVariantFromBoolean(m_LastSample.Shake, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_SHAKE].Value)); + + GetSystemTimePreciseAsFileTime(&TimeStamp); + InitPropVariantFromFileTime(&TimeStamp, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_TIMESTAMP].Value)); + + SensorsCxSensorDataReady(m_SensorInstance, m_pData); + m_FirstSample = FALSE; + } + else + { + Status = STATUS_DATA_NOT_ACCEPTED; + TraceInformation("COMBO %!FUNC! LAC 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 +SimpleDeviceOrientationDevice::UpdateCachedThreshold( + ) +{ + NTSTATUS Status = STATUS_SUCCESS; + + SENSOR_FunctionEnter(); + + Status = PropKeyFindKeyGetFloat(m_pThresholds, + &PKEY_SensorData_AccelerationX_Gs, + &m_CachedThresholds.Axis.X); + if (!NT_SUCCESS(Status)) + { + TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); + goto Exit; + } + + Status = PropKeyFindKeyGetFloat(m_pThresholds, + &PKEY_SensorData_AccelerationY_Gs, + &m_CachedThresholds.Axis.Y); + if (!NT_SUCCESS(Status)) + { + TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); + goto Exit; + } + + Status = PropKeyFindKeyGetFloat(m_pThresholds, + &PKEY_SensorData_AccelerationZ_Gs, + &m_CachedThresholds.Axis.Z); + if (!NT_SUCCESS(Status)) + { + TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); + goto Exit; + } + +Exit: + SENSOR_FunctionExit(Status); + return Status; +} From 90ad3eb9af6ed4217456967f30ae8067c2f87e0b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 21 Jan 2025 21:36:31 +0800 Subject: [PATCH 06/19] SensorsComboDriver: Remove X and Y measurements Reduce it to a single value, like it's supposed to be. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Clients.h | 2 +- .../SimpleDeviceOrientationClient.cpp | 62 +++---------------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/SensorsComboDriver/Clients.h b/SensorsComboDriver/Clients.h index c716cd8..44e0725 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/Clients.h @@ -240,7 +240,7 @@ typedef class _SimpleDeviceOrientationDevice : public _ComboDevice typedef struct _SimpleDeviceOrientationSample { - VEC3D Axis; + FLOAT X; BOOL Shake; } SimpleDeviceOrientationSample, *PSimpleDeviceOrientationSample; diff --git a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp index 9f6efc7..ec38487 100644 --- a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp +++ b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp @@ -30,8 +30,6 @@ DEFINE_GUID(GUID_SimpleDeviceOrientationDevice_UniqueID, typedef enum { LINEAR_ACCELEROMETER_DATA_X = 0, - LINEAR_ACCELEROMETER_DATA_Y, - LINEAR_ACCELEROMETER_DATA_Z, LINEAR_ACCELEROMETER_DATA_TIMESTAMP, LINEAR_ACCELEROMETER_DATA_SHAKE, LINEAR_ACCELEROMETER_DATA_COUNT @@ -177,8 +175,6 @@ SimpleDeviceOrientationDevice::Initialize( 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_Y] = PKEY_SensorData_AccelerationY_Gs; - m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_Z] = PKEY_SensorData_AccelerationZ_Gs; m_pSupportedDataFields->List[LINEAR_ACCELEROMETER_DATA_SHAKE] = PKEY_SensorData_Shake; } @@ -216,23 +212,13 @@ SimpleDeviceOrientationDevice::Initialize( 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[LINEAR_ACCELEROMETER_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; - InitPropVariantFromFloat(0.0, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); - - m_pData->List[LINEAR_ACCELEROMETER_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; - InitPropVariantFromFloat(0.0, &(m_pData->List[LINEAR_ACCELEROMETER_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.Axis.X = 0.0f; - m_CachedData.Axis.Y = 0.0f; - m_CachedData.Axis.Z = -1.0f; + m_CachedData.X = 0.0f; m_CachedData.Shake = FALSE; - m_LastSample.Axis.X = 0.0f; - m_LastSample.Axis.Y = 0.0f; - m_LastSample.Axis.Z = 0.0f; + m_LastSample.X = 0.0f; m_LastSample.Shake = FALSE; } @@ -351,17 +337,7 @@ SimpleDeviceOrientationDevice::Initialize( InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_X].Value)); - m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Y].Key = PKEY_SensorData_AccelerationY_Gs; - InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, - &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); - - m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Z].Key = PKEY_SensorData_AccelerationZ_Gs; - InitPropVariantFromFloat(SimpleDeviceOrientationDevice_Default_Axis_Threshold, - &(m_pThresholds->List[LINEAR_ACCELEROMETER_DATA_Z].Value)); - - m_CachedThresholds.Axis.X = SimpleDeviceOrientationDevice_Default_Axis_Threshold; - m_CachedThresholds.Axis.Y = SimpleDeviceOrientationDevice_Default_Axis_Threshold; - m_CachedThresholds.Axis.Z = SimpleDeviceOrientationDevice_Default_Axis_Threshold; + m_CachedThresholds.X = SimpleDeviceOrientationDevice_Default_Axis_Threshold; m_FirstSample = TRUE; } @@ -414,9 +390,7 @@ SimpleDeviceOrientationDevice::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.Axis.X - m_LastSample.Axis.X) >= m_CachedThresholds.Axis.X) || - (abs(m_CachedData.Axis.Y - m_LastSample.Axis.Y) >= m_CachedThresholds.Axis.Y) || - (abs(m_CachedData.Axis.Z - m_LastSample.Axis.Z) >= m_CachedThresholds.Axis.Z)) + if ( (abs(m_CachedData.X - m_LastSample.X) >= m_CachedThresholds.X)) { DataReady = TRUE; } @@ -425,16 +399,12 @@ SimpleDeviceOrientationDevice::GetData( 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.X = m_CachedData.X; m_LastSample.Shake = m_CachedData.Shake; // push to clx - InitPropVariantFromFloat(m_LastSample.Axis.X, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_X].Value)); - InitPropVariantFromFloat(m_LastSample.Axis.Y, &(m_pData->List[LINEAR_ACCELEROMETER_DATA_Y].Value)); - InitPropVariantFromFloat(m_LastSample.Axis.Z, &(m_pData->List[LINEAR_ACCELEROMETER_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)); @@ -477,31 +447,13 @@ SimpleDeviceOrientationDevice::UpdateCachedThreshold( Status = PropKeyFindKeyGetFloat(m_pThresholds, &PKEY_SensorData_AccelerationX_Gs, - &m_CachedThresholds.Axis.X); + &m_CachedThresholds.X); if (!NT_SUCCESS(Status)) { TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for X failed! %!STATUS!", Status); goto Exit; } - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AccelerationY_Gs, - &m_CachedThresholds.Axis.Y); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for Y failed! %!STATUS!", Status); - goto Exit; - } - - Status = PropKeyFindKeyGetFloat(m_pThresholds, - &PKEY_SensorData_AccelerationZ_Gs, - &m_CachedThresholds.Axis.Z); - if (!NT_SUCCESS(Status)) - { - TraceError("COMBO %!FUNC! LAC PropKeyFindKeyGetFloat for Z failed! %!STATUS!", Status); - goto Exit; - } - Exit: SENSOR_FunctionExit(Status); return Status; From e02d0ec1de0a00e2ecd12e926f2396c890680067 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 25 Jan 2025 19:45:42 +0800 Subject: [PATCH 07/19] SensorsComboDriver: Rename INF to remove sensors All the sensors previously removed. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/SensorsComboDriver.inx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx index 00c1eeb..3719d93 100644 --- a/SensorsComboDriver/SensorsComboDriver.inx +++ b/SensorsComboDriver/SensorsComboDriver.inx @@ -78,6 +78,6 @@ UmdfExtensions = SensorsCx0102 ;Localizable Strings MediaDescription = "Windows Sensors Combo Driver" PROVIDER = "Manufacturer Name" -SensorsComboDriver_DevDesc = "Sensors Combo Driver - Ambient Light, Barometer, Gyroscope, Magnetometer, Proximity, and Relative Fusion, and more." +SensorsComboDriver_DevDesc = "Sensors Combo Driver - ALS, Accelerometer, Orientation" ;Non-Localizable Strings From be4068bdccc67d0ff3ed31097605e39595975b9c Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 4 Feb 2025 15:58:20 +0800 Subject: [PATCH 08/19] Proof of concept UMDF=>crosecbus interaction Can see the the full EC memory map dump in TraceView. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Device.cpp | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 3d8c9d5..dfb1c26 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -13,9 +13,13 @@ #include "Driver.h" #include +#include #include "Device.tmh" +#define EC_LPC_ADDR_MEMMAP 0xE00 +#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ + //--------------------------------------- // Declare and map devices below //--------------------------------------- @@ -327,6 +331,78 @@ OnReleaseHardware( return Status; } +#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; + + +NTSTATUS ConnectToEc( + _In_ WDFDEVICE FxDevice +) { + SENSOR_FunctionEnter(); + NTSTATUS Status = STATUS_SUCCESS; + HANDLE h; + CROSEC_READMEM rm{}; + DWORD retb{}; + + UNREFERENCED_PARAMETER(FxDevice); + + h = CreateFileW( + LR"(\\.\GLOBALROOT\Device\CrosEC)", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + + if (h == INVALID_HANDLE_VALUE) { + Status = STATUS_INVALID_HANDLE; + TraceError("COMBO %!FUNC! CreateFileW failed %!STATUS!", Status); + goto Exit; + } + + rm.bytes = 0xfe; + rm.offset = 0; + Status = DeviceIoControl(h, + (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 (int 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] + ); + } + +Exit: + SENSOR_FunctionExit(Status); + + return Status; +} //------------------------------------------------------------------------------ @@ -359,6 +435,12 @@ OnD0Entry( SENSOR_FunctionEnter(); + Status = ConnectToEc(Device); + if (!NT_SUCCESS(Status)) { + TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status); + goto Exit; + } + // // Get sensor instances // From b1e8de92afd7cc376cb4ca9df445e104f2f6c866 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Tue, 4 Feb 2025 16:54:56 +0800 Subject: [PATCH 09/19] Hook up to ALS sensor Works on 13in to report ALS reading. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/AlsClient.cpp | 45 ++++++ SensorsComboDriver/Clients.cpp | 2 +- SensorsComboDriver/Clients.h | 25 ++- SensorsComboDriver/Device.cpp | 147 ++++++++---------- .../SimpleDeviceOrientationClient.cpp | 3 + .../linearaccelerometerclient.cpp | 3 + 6 files changed, 141 insertions(+), 84 deletions(-) diff --git a/SensorsComboDriver/AlsClient.cpp b/SensorsComboDriver/AlsClient.cpp index eb7080a..7331ba9 100644 --- a/SensorsComboDriver/AlsClient.cpp +++ b/SensorsComboDriver/AlsClient.cpp @@ -9,6 +9,7 @@ // Windows User-Mode Driver Framework (WUDF) #include "Clients.h" +#include #include "AlsClient.tmh" @@ -462,6 +463,40 @@ AlsDevice::Initialize( } +static 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; +} + + //------------------------------------------------------------------------------ // Function: GetData @@ -478,6 +513,7 @@ AlsDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS AlsDevice::GetData( + _In_ HANDLE Handle ) { BOOLEAN DataReady = FALSE; @@ -486,6 +522,15 @@ AlsDevice::GetData( SENSOR_FunctionEnter(); + UINT8 als[4] = {0}; + CrosEcReadMemU8(Handle, 0x80 + 0, &als[0]); + CrosEcReadMemU8(Handle, 0x80 + 1, &als[1]); + CrosEcReadMemU8(Handle, 0x80 + 2, &als[2]); + CrosEcReadMemU8(Handle, 0x80 + 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/SensorsComboDriver/Clients.cpp index 4524b6b..4673356 100644 --- a/SensorsComboDriver/Clients.cpp +++ b/SensorsComboDriver/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/SensorsComboDriver/Clients.h index 44e0725..6d951c3 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/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,7 +198,7 @@ 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; @@ -224,7 +225,7 @@ 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; @@ -251,7 +252,23 @@ typedef class _SimpleDeviceOrientationDevice : public _ComboDevice public: NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj); - NTSTATUS GetData(); + NTSTATUS GetData(_In_ HANDLE Device); NTSTATUS UpdateCachedThreshold(); } SimpleDeviceOrientationDevice, *PSimpleDeviceOrientationDevice; + +#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; diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index dfb1c26..089073a 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -64,6 +64,38 @@ void AllocateDeviceAtIndex( } } +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 @@ -199,9 +231,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; @@ -231,6 +297,8 @@ OnPrepareHardware( AllocateDeviceAtIndex(Count, &pDevice); + pDevice->m_CrosEcHandle = Handle; + // Fill out properties Status = pDevice->Initialize(Device, SensorInstance); if (!NT_SUCCESS(Status)) @@ -331,80 +399,6 @@ OnReleaseHardware( return Status; } -#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; - - -NTSTATUS ConnectToEc( - _In_ WDFDEVICE FxDevice -) { - SENSOR_FunctionEnter(); - NTSTATUS Status = STATUS_SUCCESS; - HANDLE h; - CROSEC_READMEM rm{}; - DWORD retb{}; - - UNREFERENCED_PARAMETER(FxDevice); - - h = CreateFileW( - LR"(\\.\GLOBALROOT\Device\CrosEC)", - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - - if (h == INVALID_HANDLE_VALUE) { - Status = STATUS_INVALID_HANDLE; - TraceError("COMBO %!FUNC! CreateFileW failed %!STATUS!", Status); - goto Exit; - } - - rm.bytes = 0xfe; - rm.offset = 0; - Status = DeviceIoControl(h, - (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 (int 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] - ); - } - -Exit: - SENSOR_FunctionExit(Status); - - return Status; -} - - //------------------------------------------------------------------------------ // // Function: OnD0Entry @@ -435,11 +429,6 @@ OnD0Entry( SENSOR_FunctionEnter(); - Status = ConnectToEc(Device); - if (!NT_SUCCESS(Status)) { - TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status); - goto Exit; - } // // Get sensor instances diff --git a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp index ec38487..667e8c2 100644 --- a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp +++ b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp @@ -364,12 +364,15 @@ SimpleDeviceOrientationDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS SimpleDeviceOrientationDevice::GetData( + _In_ HANDLE Device ) { BOOLEAN DataReady = FALSE; FILETIME TimeStamp = {0}; NTSTATUS Status = STATUS_SUCCESS; + UNREFERENCED_PARAMETER(Device); + SENSOR_FunctionEnter(); // new sample? diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/SensorsComboDriver/linearaccelerometerclient.cpp index 036c294..c948a57 100644 --- a/SensorsComboDriver/linearaccelerometerclient.cpp +++ b/SensorsComboDriver/linearaccelerometerclient.cpp @@ -387,12 +387,15 @@ LinearAccelerometerDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS LinearAccelerometerDevice::GetData( + _In_ HANDLE Device ) { BOOLEAN DataReady = FALSE; FILETIME TimeStamp = {0}; NTSTATUS Status = STATUS_SUCCESS; + UNREFERENCED_PARAMETER(Device); + SENSOR_FunctionEnter(); // new sample? From fd7d057d5890dbfaf367b282824462039526ff04 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 14:40:56 +0800 Subject: [PATCH 10/19] Inf2Cat: Use localtime Fix error that occurs sometimes: DriverVer set to a date in the future (postdated DriverVer not allowed) Signed-off-by: Daniel Schaefer --- SensorsComboDriver/SensorsComboDriver.vcxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj b/SensorsComboDriver/SensorsComboDriver.vcxproj index 0cb3dc0..7b465eb 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/SensorsComboDriver/SensorsComboDriver.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 From 44166c5b20a09c027ff0ca82149f8de10e10cbc0 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 15:14:13 +0800 Subject: [PATCH 11/19] README: Add build and installation instructions Signed-off-by: Daniel Schaefer --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 99d5e6e..7ad96f7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ # framework-win-sensor-driver Sensor Driver for Windows on Framework systems + +``` +# Build +msbuild .\SensorsComboDriver\SensorsComboDriver.sln /property:Platform=x64 /property:Configuration=Debug + +# First install +# TODO: Should move to ACPI\FRMWC006 +> sudo .\devcon.exe install .\SensorsComboDriver\x64\Debug\SensorsComboDriver\SensorsComboDriver.inf umdf2\SensorsComboDriver + +# Subsequent installs +> sudo pnputil /add-driver .\SensorsComboDriver\x64\Debug\SensorsComboDriver\SensorsComboDriver.inf /install + +# 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 +``` From 61536fb7eff49018479b4fc40a929b25fe56cf2d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 15:15:07 +0800 Subject: [PATCH 12/19] Use FRMWC006 Then we don't have to use devcon to create a software device. Signed-off-by: Daniel Schaefer --- README.md | 39 +++++++++++++++++++---- SensorsComboDriver/SensorsComboDriver.inx | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7ad96f7..d753ba3 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,6 @@ Sensor Driver for Windows on Framework systems # Build msbuild .\SensorsComboDriver\SensorsComboDriver.sln /property:Platform=x64 /property:Configuration=Debug -# First install -# TODO: Should move to ACPI\FRMWC006 -> sudo .\devcon.exe install .\SensorsComboDriver\x64\Debug\SensorsComboDriver\SensorsComboDriver.inf umdf2\SensorsComboDriver - -# Subsequent installs -> sudo pnputil /add-driver .\SensorsComboDriver\x64\Debug\SensorsComboDriver\SensorsComboDriver.inf /install - # Distributing .\SensorsComboDriver\x64\Debug\ SensorsComboDriver.pdb @@ -19,4 +12,36 @@ msbuild .\SensorsComboDriver\SensorsComboDriver.sln /property:Platform=x64 /prop 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: Sensors Combo Driver - ALS, Accelerometer, Orientation +Class Name: Sensor +Class GUID: {5175d334-c371-4806-b3ba-71fd53c9258d} +Manufacturer Name: Manufacturer Name +Status: Started +Driver Name: oem194.inf ``` diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx index 3719d93..1c03118 100644 --- a/SensorsComboDriver/SensorsComboDriver.inx +++ b/SensorsComboDriver/SensorsComboDriver.inx @@ -37,7 +37,7 @@ SensorsComboDriver.dll = 1,, [SensorsComboDriver_Device.NT$ARCH$.10.0...22000] ; DisplayName Section DeviceId ; ----------- ------- -------- -%SensorsComboDriver_DevDesc% = SensorsComboDriver_Inst, umdf2\SensorsComboDriver +%SensorsComboDriver_DevDesc% = SensorsComboDriver_Inst, ACPI\FRMWC006 [SensorsComboDriver_Inst.NT] Include=WUDFRD.inf From 98599e8c451a7724e5350c00889d90ee8acd2375 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 16:14:02 +0800 Subject: [PATCH 13/19] Allow disabling sensors at compile-time Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Device.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 089073a..88e96a2 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -19,15 +19,24 @@ #define EC_LPC_ADDR_MEMMAP 0xE00 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ +#define ENABLE_ALS_SENSOR 1 +#define ENABLE_ORIENTATION_SENSOR 0 +#define ENABLE_ACCEL_SENSOR 0 //--------------------------------------- // Declare and map devices below //--------------------------------------- enum Device { - Device_Als = 0, +#if ENABLE_ALS_SENSOR + Device_Als, +#endif +#if ENABLE_ORIENTATION_SENSOR Device_SimpleDeviceOrientation, +#endif +#if ENABLE_ACCEL_SENSOR Device_LinearAccelerometer, +#endif // Keep this last Device_Count }; @@ -41,9 +50,15 @@ inline size_t GetDeviceSizeAtIndex( size_t result = 0; switch (static_cast(Index)) { +#if ENABLE_ALS_SENSOR case Device_Als: result = sizeof(AlsDevice); 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; +#endif default: break; // invalid } return result; @@ -56,9 +71,15 @@ void AllocateDeviceAtIndex( { switch (static_cast(Index)) { +#if ENABLE_ALS_SENSOR case Device_Als: *ppDevice = new(*ppDevice) AlsDevice; 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; +#endif default: break; // invalid (let driver fail) } From d42ad9f5d43a16405979738d803cd436bb6b444d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 16:14:46 +0800 Subject: [PATCH 14/19] Split EC Communication into separate file Signed-off-by: Daniel Schaefer --- SensorsComboDriver/AlsClient.cpp | 45 ++-------------- SensorsComboDriver/Clients.h | 16 ------ SensorsComboDriver/Device.cpp | 3 +- SensorsComboDriver/EcCommunication.cpp | 43 +++++++++++++++ SensorsComboDriver/EcCommunication.h | 53 +++++++++++++++++++ SensorsComboDriver/SensorsComboDriver.vcxproj | 2 +- .../SensorsComboDriver.vcxproj.Filters | 3 ++ 7 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 SensorsComboDriver/EcCommunication.cpp create mode 100644 SensorsComboDriver/EcCommunication.h diff --git a/SensorsComboDriver/AlsClient.cpp b/SensorsComboDriver/AlsClient.cpp index 7331ba9..f274199 100644 --- a/SensorsComboDriver/AlsClient.cpp +++ b/SensorsComboDriver/AlsClient.cpp @@ -9,7 +9,7 @@ // Windows User-Mode Driver Framework (WUDF) #include "Clients.h" -#include +#include "EcCommunication.h" #include "AlsClient.tmh" @@ -463,41 +463,6 @@ AlsDevice::Initialize( } -static 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; -} - - - //------------------------------------------------------------------------------ // Function: GetData // @@ -523,10 +488,10 @@ AlsDevice::GetData( SENSOR_FunctionEnter(); UINT8 als[4] = {0}; - CrosEcReadMemU8(Handle, 0x80 + 0, &als[0]); - CrosEcReadMemU8(Handle, 0x80 + 1, &als[1]); - CrosEcReadMemU8(Handle, 0x80 + 2, &als[2]); - CrosEcReadMemU8(Handle, 0x80 + 3, &als[3]); + 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); diff --git a/SensorsComboDriver/Clients.h b/SensorsComboDriver/Clients.h index 6d951c3..3dee88a 100644 --- a/SensorsComboDriver/Clients.h +++ b/SensorsComboDriver/Clients.h @@ -256,19 +256,3 @@ typedef class _SimpleDeviceOrientationDevice : public _ComboDevice NTSTATUS UpdateCachedThreshold(); } SimpleDeviceOrientationDevice, *PSimpleDeviceOrientationDevice; - -#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; diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 88e96a2..6ebe1fc 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -11,14 +11,13 @@ #include "Clients.h" #include "Driver.h" +#include "EcCommunication.h" #include #include #include "Device.tmh" -#define EC_LPC_ADDR_MEMMAP 0xE00 -#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ #define ENABLE_ALS_SENSOR 1 #define ENABLE_ORIENTATION_SENSOR 0 #define ENABLE_ACCEL_SENSOR 0 diff --git a/SensorsComboDriver/EcCommunication.cpp b/SensorsComboDriver/EcCommunication.cpp new file mode 100644 index 0000000..9adac8d --- /dev/null +++ b/SensorsComboDriver/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/SensorsComboDriver/EcCommunication.h b/SensorsComboDriver/EcCommunication.h new file mode 100644 index 0000000..c1ec5b7 --- /dev/null +++ b/SensorsComboDriver/EcCommunication.h @@ -0,0 +1,53 @@ +//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 +#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) +#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(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/SensorsComboDriver/SensorsComboDriver.vcxproj b/SensorsComboDriver/SensorsComboDriver.vcxproj index 7b465eb..17c18cc 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj @@ -80,7 +80,7 @@ - + true true SensorsComboDriver diff --git a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters index 1e5b51b..8bb9450 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters @@ -31,6 +31,9 @@ Source Files + + Source Files + Source Files From 90b67cf89b9becd1aea4bd0c3bebc40b0c860d18 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 16:57:20 +0800 Subject: [PATCH 15/19] Change SensorType LinearAccelerometer to Accelerometer3D Windows automatically create SimpleOrientationSensor and calculate the orientation. Signed-off-by: Daniel Schaefer --- SensorsComboDriver/linearaccelerometerclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/SensorsComboDriver/linearaccelerometerclient.cpp index c948a57..2c9eb3d 100644 --- a/SensorsComboDriver/linearaccelerometerclient.cpp +++ b/SensorsComboDriver/linearaccelerometerclient.cpp @@ -123,7 +123,7 @@ 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; From e26fcad1e2362b0fb4be2b751a416a671c5a9a1b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 18:33:36 +0800 Subject: [PATCH 16/19] Get Accelerometer data from EC Signed-off-by: Daniel Schaefer --- SensorsComboDriver/Device.cpp | 4 +- SensorsComboDriver/EcCommunication.h | 6 ++- .../linearaccelerometerclient.cpp | 44 ++++++++++++++++--- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/SensorsComboDriver/Device.cpp b/SensorsComboDriver/Device.cpp index 6ebe1fc..df8ea02 100644 --- a/SensorsComboDriver/Device.cpp +++ b/SensorsComboDriver/Device.cpp @@ -18,9 +18,9 @@ #include "Device.tmh" -#define ENABLE_ALS_SENSOR 1 +#define ENABLE_ALS_SENSOR 0 #define ENABLE_ORIENTATION_SENSOR 0 -#define ENABLE_ACCEL_SENSOR 0 +#define ENABLE_ACCEL_SENSOR 1 //--------------------------------------- // Declare and map devices below diff --git a/SensorsComboDriver/EcCommunication.h b/SensorsComboDriver/EcCommunication.h index c1ec5b7..df830e0 100644 --- a/SensorsComboDriver/EcCommunication.h +++ b/SensorsComboDriver/EcCommunication.h @@ -27,8 +27,10 @@ extern "C" { /* Define the format of the accelerometer mapped memory status byte. */ #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f -#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) -#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) +// 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 diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/SensorsComboDriver/linearaccelerometerclient.cpp index 2c9eb3d..ea969f0 100644 --- a/SensorsComboDriver/linearaccelerometerclient.cpp +++ b/SensorsComboDriver/linearaccelerometerclient.cpp @@ -9,6 +9,7 @@ // Windows User-Mode Driver Framework (UMDF) #include "Clients.h" +#include "EcCommunication.h" #include "LinearAccelerometerClient.tmh" @@ -127,11 +128,11 @@ LinearAccelerometerDevice::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", &(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,17 +388,50 @@ LinearAccelerometerDevice::Initialize( //------------------------------------------------------------------------------ NTSTATUS LinearAccelerometerDevice::GetData( - _In_ HANDLE Device + _In_ HANDLE Handle ) { BOOLEAN DataReady = FALSE; FILETIME TimeStamp = {0}; NTSTATUS Status = STATUS_SUCCESS; - UNREFERENCED_PARAMETER(Device); - 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) { From 3d10d954d7e23568b5d26dc5c79b9d6ce4386c5b Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 18:35:17 +0800 Subject: [PATCH 17/19] Remove SimpleDeviceOrientationSensor sample Used it as a sample, don't need it anymore. Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 1 - SimpleDeviceOrientationSensor/Device.h | 137 ---- SimpleDeviceOrientationSensor/Driver.h | 19 - .../HardwareSimulator.h | 58 -- SimpleDeviceOrientationSensor/SensorsTrace.h | 100 --- .../SimpleDeviceOrientationSensor.def | 6 - .../SimpleDeviceOrientationSensor.inx | 86 --- .../SimpleDeviceOrientationSensor.sln | 28 - .../SimpleDeviceOrientationSensor.vcxproj | 216 ------- ...pleDeviceOrientationSensor.vcxproj.Filters | 43 -- SimpleDeviceOrientationSensor/client.cpp | 595 ------------------ SimpleDeviceOrientationSensor/device.cpp | 572 ----------------- SimpleDeviceOrientationSensor/driver.cpp | 75 --- .../hardwaresimulator.cpp | 248 -------- SimpleDeviceOrientationSensor/readme.md | 13 - 15 files changed, 2197 deletions(-) delete mode 100644 SimpleDeviceOrientationSensor/Device.h delete mode 100644 SimpleDeviceOrientationSensor/Driver.h delete mode 100644 SimpleDeviceOrientationSensor/HardwareSimulator.h delete mode 100644 SimpleDeviceOrientationSensor/SensorsTrace.h delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.def delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.sln delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj delete mode 100644 SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.vcxproj.Filters delete mode 100644 SimpleDeviceOrientationSensor/client.cpp delete mode 100644 SimpleDeviceOrientationSensor/device.cpp delete mode 100644 SimpleDeviceOrientationSensor/driver.cpp delete mode 100644 SimpleDeviceOrientationSensor/hardwaresimulator.cpp delete mode 100644 SimpleDeviceOrientationSensor/readme.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21d9208..b6d7d8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,6 @@ jobs: - 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 }} env: Configuration: ${{ matrix.configuration }} Platform: ${{ matrix.platform }} 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 9ea7328..0000000 --- a/SimpleDeviceOrientationSensor/SimpleDeviceOrientationSensor.inx +++ /dev/null @@ -1,86 +0,0 @@ -/*++ -; -;Copyright (c) Microsoft Corporation. All rights reserved. -; -;Module Name: -; SimpleDeviceOrientationSensor.INF -; -;Abstract: -; INF file for installing the Sensors 2.0 Simple Device Orientation Sensor Driver -; -;Installation Notes: -; Using Devcon: Type "devcon install SimpleDeviceOrientationSensor.inf umdf2\SDOSampleSensor" to install -; -;--*/ - -[Version] -Signature = "$WINDOWS NT$" -Class = Sensor -ClassGuid = {5175D334-C371-4806-B3BA-71FD53C9258D} -Provider = %ProviderName% -CatalogFile = SimpleDeviceOrientationSensor.cat -DriverVer = 08/14/2014,2.0.0.1 -PnpLockdown = 1 - -[DestinationDirs] -;12 == Windows\System32\Drivers\UMDF -DefaultDestDir = 12,UMDF - -[SourceDisksNames] -1 = %MediaDescription%,,,"" - -[SourceDisksFiles] -SimpleDeviceOrientationSensor.dll = 1,, - -[Manufacturer] -%ManufacturerName% = SimpleDeviceOrientationSensor_Device, NT$ARCH$.10.0...22000 - -;******************************* -; Simple Device Orientation Sensor Install Section -;******************************* - -[SimpleDeviceOrientationSensor_Device.NT$ARCH$.10.0...22000] -; DisplayName Section DeviceId -; ----------- ------- -------- -%SimpleDeviceOrientationSensor_DevDesc% = SimpleDeviceOrientationSensor_Inst, umdf2\SDOSampleSensor - -[SimpleDeviceOrientationSensor_Inst.NT] -Include=WUDFRD.inf -Needs=WUDFRD.NT -CopyFiles = SimpleDeviceOrientationSensorDriverCopy - -[SimpleDeviceOrientationSensorDriverCopy] -SimpleDeviceOrientationSensor.dll - -[SimpleDeviceOrientationSensor_Inst.NT.HW] -Include=WUDFRD.inf -Needs=WUDFRD.NT.HW - -;-------------- Service installation - -[SimpleDeviceOrientationSensor_Inst.NT.Services] -Include=WUDFRD.inf -Needs=WUDFRD.NT.Services - -;-------------- WDF specific section - -[SimpleDeviceOrientationSensor_Inst.NT.Wdf] -UmdfService = SimpleDeviceOrientationSensor, SimpleDeviceOrientationSensor_Install -UmdfServiceOrder = SimpleDeviceOrientationSensor -UmdfDirectHardwareAccess = AllowDirectHardwareAccess -UmdfFileObjectPolicy = AllowNullAndUnknownFileObjects -UmdfFsContextUsePolicy = CannotUseFsContexts - -[SimpleDeviceOrientationSensor_Install] -UmdfLibraryVersion = $UMDFVERSION$ -ServiceBinary = %12%\UMDF\SimpleDeviceOrientationSensor.dll -UmdfExtensions = SensorsCx0102 - -[Strings] -;Localizable Strings -MediaDescription = "Windows Simple Device Orientation Sensor sample Driver" -ProviderName = "TODO-Set-Provider" -ManufacturerName = "TODO-Set-Manufacturer" -SimpleDeviceOrientationSensor_DevDesc = "Simple Device Orientation Sensor sample" - -;Non-Localizable Strings 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. From 58e17d70d0ba21ab0e2acbfde0e6bade61958588 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 5 Feb 2025 18:37:30 +0800 Subject: [PATCH 18/19] Change to Framework branding Signed-off-by: Daniel Schaefer --- README.md | 4 ++-- SensorsComboDriver/AlsClient.cpp | 2 +- SensorsComboDriver/SensorsComboDriver.inx | 12 +++++------- SensorsComboDriver/SimpleDeviceOrientationClient.cpp | 2 +- SensorsComboDriver/linearaccelerometerclient.cpp | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d753ba3..63c6378 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,10 @@ Driver Name: oem2.inf Microsoft PnP Utility Instance ID: ACPI\FRMWC006\1 -Device Description: Sensors Combo Driver - ALS, Accelerometer, Orientation +Device Description: Sensor Driver - ALS, Accelerometer, Orientation Class Name: Sensor Class GUID: {5175d334-c371-4806-b3ba-71fd53c9258d} -Manufacturer Name: Manufacturer Name +Manufacturer Name: Framework Computer Inc Status: Started Driver Name: oem194.inf ``` diff --git a/SensorsComboDriver/AlsClient.cpp b/SensorsComboDriver/AlsClient.cpp index f274199..753e873 100644 --- a/SensorsComboDriver/AlsClient.cpp +++ b/SensorsComboDriver/AlsClient.cpp @@ -166,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; diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/SensorsComboDriver/SensorsComboDriver.inx index 1c03118..c448898 100644 --- a/SensorsComboDriver/SensorsComboDriver.inx +++ b/SensorsComboDriver/SensorsComboDriver.inx @@ -1,15 +1,13 @@ /*++ ; ;Copyright (c) Microsoft Corporation. All rights reserved. +;Copyright (c) Framework Computer Inc. All rights reserved. ; ;Module Name: ; SensorsComboDriver.INF ; ;Abstract: -; INF file for installing the Sensors Combo Driver -; -;Installation Notes: -; Using Devcon: Type "devcon install SensorsComboDriver.inf umdf2\SensorsComboDriver" to install +; INF file for installing the Framework Sensor Driver ; ;--*/ [Version] @@ -76,8 +74,8 @@ UmdfExtensions = SensorsCx0102 [Strings] ;Localizable Strings -MediaDescription = "Windows Sensors Combo Driver" -PROVIDER = "Manufacturer Name" -SensorsComboDriver_DevDesc = "Sensors Combo Driver - ALS, Accelerometer, Orientation" +MediaDescription = "Framework Computer Sensor Driver" +PROVIDER = "Framework Computer Inc" +SensorsComboDriver_DevDesc = "Sensor Driver - ALS, Accelerometer, Orientation" ;Non-Localizable Strings diff --git a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp index 667e8c2..a92fd22 100644 --- a/SensorsComboDriver/SimpleDeviceOrientationClient.cpp +++ b/SensorsComboDriver/SimpleDeviceOrientationClient.cpp @@ -126,7 +126,7 @@ SimpleDeviceOrientationDevice::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; diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/SensorsComboDriver/linearaccelerometerclient.cpp index ea969f0..6f9db5f 100644 --- a/SensorsComboDriver/linearaccelerometerclient.cpp +++ b/SensorsComboDriver/linearaccelerometerclient.cpp @@ -128,7 +128,7 @@ LinearAccelerometerDevice::Initialize( &(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value)); m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer; - InitPropVariantFromString(L"Framework Computer", + InitPropVariantFromString(L"Framework Computer Inc", &(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value)); m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model; From 07e1f89cdc5e12d8b0acceb063a2df78364f77d1 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Thu, 6 Feb 2025 13:22:52 +0800 Subject: [PATCH 19/19] SensorsComboDriver rename to FrameworkSensors Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 4 +- .../AlsClient.cpp | 0 .../Clients.cpp | 0 .../Clients.h | 0 .../Device.cpp | 4 +- .../Driver.cpp | 2 +- .../Driver.h | 2 +- .../EcCommunication.cpp | 0 .../EcCommunication.h | 0 .../FrameworkSensors.inx | 38 +++++++++---------- .../FrameworkSensors.sln | 2 +- .../FrameworkSensors.vcxproj | 14 +++---- .../FrameworkSensors.vcxproj.Filters | 4 +- .../SensorsTrace.h | 0 .../SimpleDeviceOrientationClient.cpp | 0 .../linearaccelerometerclient.cpp | 0 SensorsComboDriver/readme.md | 13 ------- 17 files changed, 35 insertions(+), 48 deletions(-) rename {SensorsComboDriver => FrameworkSensors}/AlsClient.cpp (100%) rename {SensorsComboDriver => FrameworkSensors}/Clients.cpp (100%) rename {SensorsComboDriver => FrameworkSensors}/Clients.h (100%) rename {SensorsComboDriver => FrameworkSensors}/Device.cpp (99%) rename {SensorsComboDriver => FrameworkSensors}/Driver.cpp (98%) rename {SensorsComboDriver => FrameworkSensors}/Driver.h (90%) rename {SensorsComboDriver => FrameworkSensors}/EcCommunication.cpp (100%) rename {SensorsComboDriver => FrameworkSensors}/EcCommunication.h (100%) rename SensorsComboDriver/SensorsComboDriver.inx => FrameworkSensors/FrameworkSensors.inx (62%) rename SensorsComboDriver/SensorsComboDriver.sln => FrameworkSensors/FrameworkSensors.sln (89%) rename SensorsComboDriver/SensorsComboDriver.vcxproj => FrameworkSensors/FrameworkSensors.vcxproj (97%) rename SensorsComboDriver/SensorsComboDriver.vcxproj.Filters => FrameworkSensors/FrameworkSensors.vcxproj.Filters (95%) rename {SensorsComboDriver => FrameworkSensors}/SensorsTrace.h (100%) rename {SensorsComboDriver => FrameworkSensors}/SimpleDeviceOrientationClient.cpp (100%) rename {SensorsComboDriver => FrameworkSensors}/linearaccelerometerclient.cpp (100%) delete mode 100644 SensorsComboDriver/readme.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6d7d8c..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,7 +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 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 100% rename from SensorsComboDriver/AlsClient.cpp rename to FrameworkSensors/AlsClient.cpp diff --git a/SensorsComboDriver/Clients.cpp b/FrameworkSensors/Clients.cpp similarity index 100% rename from SensorsComboDriver/Clients.cpp rename to FrameworkSensors/Clients.cpp diff --git a/SensorsComboDriver/Clients.h b/FrameworkSensors/Clients.h similarity index 100% rename from SensorsComboDriver/Clients.h rename to FrameworkSensors/Clients.h diff --git a/SensorsComboDriver/Device.cpp b/FrameworkSensors/Device.cpp similarity index 99% rename from SensorsComboDriver/Device.cpp rename to FrameworkSensors/Device.cpp index df8ea02..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: // @@ -120,7 +120,7 @@ NTSTATUS ConnectToEc( // // 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. 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/SensorsComboDriver/EcCommunication.cpp b/FrameworkSensors/EcCommunication.cpp similarity index 100% rename from SensorsComboDriver/EcCommunication.cpp rename to FrameworkSensors/EcCommunication.cpp diff --git a/SensorsComboDriver/EcCommunication.h b/FrameworkSensors/EcCommunication.h similarity index 100% rename from SensorsComboDriver/EcCommunication.h rename to FrameworkSensors/EcCommunication.h diff --git a/SensorsComboDriver/SensorsComboDriver.inx b/FrameworkSensors/FrameworkSensors.inx similarity index 62% rename from SensorsComboDriver/SensorsComboDriver.inx rename to FrameworkSensors/FrameworkSensors.inx index c448898..d833c79 100644 --- a/SensorsComboDriver/SensorsComboDriver.inx +++ b/FrameworkSensors/FrameworkSensors.inx @@ -4,7 +4,7 @@ ;Copyright (c) Framework Computer Inc. All rights reserved. ; ;Module Name: -; SensorsComboDriver.INF +; FrameworkSensors.INF ; ;Abstract: ; INF file for installing the Framework Sensor Driver @@ -15,7 +15,7 @@ Signature = "$WINDOWS NT$" Class = Sensor ClassGuid = {5175D334-C371-4806-B3BA-71FD53C9258D} Provider = %PROVIDER% -CatalogFile = SensorsComboDriver.cat +CatalogFile = FrameworkSensors.cat DriverVer = 8/29/2014,2.00.00.03 PnpLockdown = 1 @@ -23,29 +23,29 @@ PnpLockdown = 1 1 = %MediaDescription%,,,"" [SourceDisksFiles] -SensorsComboDriver.dll = 1,, +FrameworkSensors.dll = 1,, [Manufacturer] -%PROVIDER% = SensorsComboDriver_Device, NT$ARCH$.10.0...22000 +%PROVIDER% = FrameworkSensors_Device, NT$ARCH$.10.0...22000 ;******************************* -; Combo Driver Install Section +; Framework Sensors Driver Install Section ;******************************* -[SensorsComboDriver_Device.NT$ARCH$.10.0...22000] +[FrameworkSensors_Device.NT$ARCH$.10.0...22000] ; DisplayName Section DeviceId ; ----------- ------- -------- -%SensorsComboDriver_DevDesc% = SensorsComboDriver_Inst, ACPI\FRMWC006 +%FrameworkSensors_DevDesc% = FrameworkSensors_Inst, ACPI\FRMWC006 -[SensorsComboDriver_Inst.NT] +[FrameworkSensors_Inst.NT] Include=WUDFRD.inf Needs=WUDFRD.NT -CopyFiles = SensorsComboDriverCopy +CopyFiles = FrameworkSensorsCopy -[SensorsComboDriverCopy] -SensorsComboDriver.dll +[FrameworkSensorsCopy] +FrameworkSensors.dll -[SensorsComboDriver_Inst.NT.HW] +[FrameworkSensors_Inst.NT.HW] Include=WUDFRD.inf Needs=WUDFRD.NT.HW @@ -54,28 +54,28 @@ Needs=WUDFRD.NT.HW DefaultDestDir = 12,UMDF ;-------------- Service installation -[SensorsComboDriver_Inst.NT.Services] +[FrameworkSensors_Inst.NT.Services] Include=WUDFRD.inf Needs=WUDFRD.NT.Services ;-------------- WDF specific section -[SensorsComboDriver_Inst.NT.Wdf] -UmdfService = SensorsComboDriver, SensorsComboDriver_Install -UmdfServiceOrder = SensorsComboDriver +[FrameworkSensors_Inst.NT.Wdf] +UmdfService = FrameworkSensors, FrameworkSensors_Install +UmdfServiceOrder = FrameworkSensors UmdfDirectHardwareAccess = AllowDirectHardwareAccess UmdfFileObjectPolicy = AllowNullAndUnknownFileObjects UmdfFsContextUsePolicy = CannotUseFsContexts -[SensorsComboDriver_Install] +[FrameworkSensors_Install] UmdfLibraryVersion = $UMDFVERSION$ -ServiceBinary = %12%\UMDF\SensorsComboDriver.dll +ServiceBinary = %12%\UMDF\FrameworkSensors.dll UmdfExtensions = SensorsCx0102 [Strings] ;Localizable Strings MediaDescription = "Framework Computer Sensor Driver" PROVIDER = "Framework Computer Inc" -SensorsComboDriver_DevDesc = "Sensor Driver - ALS, Accelerometer, Orientation" +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 97% rename from SensorsComboDriver/SensorsComboDriver.vcxproj rename to FrameworkSensors/FrameworkSensors.vcxproj index 17c18cc..7cc55ee 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj +++ b/FrameworkSensors/FrameworkSensors.vcxproj @@ -83,26 +83,26 @@ 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 95% rename from SensorsComboDriver/SensorsComboDriver.vcxproj.Filters rename to FrameworkSensors/FrameworkSensors.vcxproj.Filters index 8bb9450..6bb862f 100644 --- a/SensorsComboDriver/SensorsComboDriver.vcxproj.Filters +++ b/FrameworkSensors/FrameworkSensors.vcxproj.Filters @@ -40,12 +40,12 @@ 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/SimpleDeviceOrientationClient.cpp b/FrameworkSensors/SimpleDeviceOrientationClient.cpp similarity index 100% rename from SensorsComboDriver/SimpleDeviceOrientationClient.cpp rename to FrameworkSensors/SimpleDeviceOrientationClient.cpp diff --git a/SensorsComboDriver/linearaccelerometerclient.cpp b/FrameworkSensors/linearaccelerometerclient.cpp similarity index 100% rename from SensorsComboDriver/linearaccelerometerclient.cpp rename to FrameworkSensors/linearaccelerometerclient.cpp 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.