Skip to content

Commit

Permalink
Improved efficiency
Browse files Browse the repository at this point in the history
For each device: Added a per-device PositionReady (BOOL) to indicate that position data is unread.

Restrict reading IOCTL_HID_READ_REPORT requests to position data of devices that:
1. Exist (pDevContext->DeviceImplemented[id - 1])
2. Comtain fresh position data (pDevContext->PositionReady[id - 1])
  • Loading branch information
shauleiz committed Mar 14, 2017
1 parent 6052a9d commit 58bd4d5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
25 changes: 12 additions & 13 deletions apps/common/vJoyInterfaceCS/WrapperTest/WrapperTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -53,7 +53,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -62,7 +62,7 @@
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
Expand All @@ -72,7 +72,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>MixedRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
Expand All @@ -82,7 +82,7 @@
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
Expand All @@ -92,7 +92,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>MixedRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_STAT|AnyCPU' ">
Expand All @@ -102,7 +102,7 @@
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_STAT|x86' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -111,7 +111,7 @@
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_STAT|x64' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -120,7 +120,7 @@
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_STAT|AnyCPU' ">
<OutputPath>bin\Release_CPP\</OutputPath>
Expand All @@ -129,7 +129,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_STAT|x86' ">
<OutputPath>bin\x86\Release_CPP\</OutputPath>
Expand All @@ -138,7 +138,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_STAT|x64' ">
<OutputPath>bin\x64\Release_CPP\</OutputPath>
Expand All @@ -147,7 +147,7 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>WrapperTest.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>wrappertest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -187,7 +187,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="WrapperTest.ruleset" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
17 changes: 16 additions & 1 deletion driver/sys/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,17 @@ Return Value:
if (!pDevContext->positions[id-1])
return STATUS_INVALID_PARAMETER;

// Test if device exists if not, return STATUS_NO_SUCH_DEVICE
if (!pDevContext->DeviceImplemented[id - 1])
return STATUS_NO_SUCH_DEVICE;

// Test if device "Dirty bit" is set - if not, return STATUS_INVALID_DEVICE_REQUEST
// Dirty Bit is set when new data is loaded to the position structure of a vJoy device
// and reset after data was read.
if (!pDevContext->PositionReady[id - 1])
return STATUS_INVALID_DEVICE_REQUEST;


//
// Check if there are any pending requests in the Read Report Interrupt Message Queue.
// If a request is found then complete the pending request.
Expand Down Expand Up @@ -840,7 +851,11 @@ vJoyGetPositionData(
HidReport->InputReport.bButtonsEx2 = (ULONG)pDevContext->positions[i]->ValButtonsEx2;
HidReport->InputReport.bButtonsEx3 = (ULONG)pDevContext->positions[i]->ValButtonsEx3;
};
// DEBUGGING HidReport->InputReport.FFBVal = 0xFF; // FFB Value

// Clear 'dearty bit'
// This means that the data above has already been read and should not be read again
pDevContext->PositionReady[i] = FALSE;

WdfWaitLockRelease(pDevContext->positionLock);

return STATUS_SUCCESS;
Expand Down
13 changes: 13 additions & 0 deletions driver/sys/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,12 @@ LoadPositions(PJOYSTICK_POSITION_V2 pPosition, PDEVICE_EXTENSION pDevContext, si
i = pPosition->bDevice-1; // Index is zero-based

WdfWaitLockAcquire(pDevContext->positionLock, NULL);

// Clear 'dearty bit'
// This means that the position data should not be read (It is not ready)
pDevContext->PositionReady[i] = FALSE;

// Copy position to context area
pDevContext->positions[i]->ValX = pPosition->wAxisX;
pDevContext->positions[i]->ValY = pPosition->wAxisY;
pDevContext->positions[i]->ValZ = pPosition->wAxisZ;
Expand All @@ -1306,6 +1312,10 @@ LoadPositions(PJOYSTICK_POSITION_V2 pPosition, PDEVICE_EXTENSION pDevContext, si
pDevContext->positions[i]->ValButtonsEx3 = pPosition->lButtonsEx3;
};

// Set 'dearty bit'
// This means that the position data is ready to be read
pDevContext->PositionReady[i] = TRUE;

WdfWaitLockRelease(pDevContext->positionLock);
}

Expand Down Expand Up @@ -2005,6 +2015,9 @@ void InitializeDev(PDEVICE_EXTENSION devContext, USHORT Mask, BOOLEAN ResetOnl
devContext->positions[index]->ValDial = data_buf.InitValAxis[7] * 0x7FFF / 100 + 1;
devContext->positions[index]->ValWheel = 0;

// Mark position data as ready to be read
devContext->PositionReady[index] = TRUE;

// Test if the initialization values refer to Discrete POVs
// The sign of Discrete POV initialization is value in the range 0x80-0x8F
// If one or more values are in the range it is adssumed the POVs are Discrete
Expand Down
8 changes: 7 additions & 1 deletion driver/sys/vjoy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1230,10 +1230,16 @@ typedef struct _DEVICE_EXTENSION{ // Needs to be changed
WDFIOTARGET IoTargetToSelf;

//
// Array of Joystick Values - One for each joystick (Index = ID-1)
// Array of Joystick Position Values - One for each joystick (Index = ID-1)
PDEVICE_POSITION_V2 positions[MAX_N_DEVICES];
int nDevices;

// Array of booleans that indicates that the data in position structure is ready to be read
// Or already read.
// Once data is loaded the corresponding variable is set
// After the data was read this variable is reset
BOOLEAN PositionReady[MAX_N_DEVICES];

// Array that tells the driver which of the 16 vJoy devices is actually implemented
BOOLEAN DeviceImplemented[MAX_N_DEVICES];

Expand Down

0 comments on commit 58bd4d5

Please sign in to comment.