diff --git a/apps/common/vJoyInterfaceCS/WrapperTest/WrapperTest.csproj b/apps/common/vJoyInterfaceCS/WrapperTest/WrapperTest.csproj index 39e7149..3285eb4 100644 --- a/apps/common/vJoyInterfaceCS/WrapperTest/WrapperTest.csproj +++ b/apps/common/vJoyInterfaceCS/WrapperTest/WrapperTest.csproj @@ -43,7 +43,7 @@ prompt 4 false - WrapperTest.ruleset + wrappertest.ruleset pdbonly @@ -53,7 +53,7 @@ prompt 4 false - WrapperTest.ruleset + wrappertest.ruleset true @@ -62,7 +62,7 @@ full x86 prompt - WrapperTest.ruleset + wrappertest.ruleset false @@ -72,7 +72,7 @@ pdbonly x86 prompt - WrapperTest.ruleset + MixedRecommendedRules.ruleset false @@ -82,7 +82,7 @@ full x64 prompt - WrapperTest.ruleset + wrappertest.ruleset false @@ -92,7 +92,7 @@ pdbonly x64 prompt - WrapperTest.ruleset + MixedRecommendedRules.ruleset false @@ -102,7 +102,7 @@ full AnyCPU prompt - WrapperTest.ruleset + wrappertest.ruleset true @@ -111,7 +111,7 @@ full x86 prompt - WrapperTest.ruleset + wrappertest.ruleset true @@ -120,7 +120,7 @@ full x64 prompt - WrapperTest.ruleset + wrappertest.ruleset bin\Release_CPP\ @@ -129,7 +129,7 @@ pdbonly AnyCPU prompt - WrapperTest.ruleset + wrappertest.ruleset bin\x86\Release_CPP\ @@ -138,7 +138,7 @@ pdbonly x86 prompt - WrapperTest.ruleset + wrappertest.ruleset bin\x64\Release_CPP\ @@ -147,7 +147,7 @@ pdbonly x64 prompt - WrapperTest.ruleset + wrappertest.ruleset @@ -187,7 +187,6 @@ Settings.settings True - diff --git a/driver/sys/driver.c b/driver/sys/driver.c index 35678e9..b956f05 100644 --- a/driver/sys/driver.c +++ b/driver/sys/driver.c @@ -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. @@ -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; diff --git a/driver/sys/hid.c b/driver/sys/hid.c index 1c3ee6b..33e438c 100644 --- a/driver/sys/hid.c +++ b/driver/sys/hid.c @@ -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; @@ -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); } @@ -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 diff --git a/driver/sys/vjoy.h b/driver/sys/vjoy.h index 994b5c7..d5ca500 100644 --- a/driver/sys/vjoy.h +++ b/driver/sys/vjoy.h @@ -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];