Updated code to use newer ViGEm.NET client

This commit is contained in:
Travis Nickles 2019-04-03 16:47:03 -05:00
parent 839f03d538
commit aff365b28f
5 changed files with 39 additions and 41 deletions

View File

@ -34,10 +34,7 @@ namespace DS4Windows
bool[] buttonsdown = new bool[4] { false, false, false, false }; bool[] buttonsdown = new bool[4] { false, false, false, false };
bool[] held = new bool[DS4_CONTROLLER_COUNT]; bool[] held = new bool[DS4_CONTROLLER_COUNT];
int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 }; int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 };
public Xbox360Controller[] x360controls = new Xbox360Controller[4] { null, null, null, null }; public IXbox360Controller[] x360controls = new IXbox360Controller[4] { null, null, null, null };
private Xbox360Report[] x360reports = new Xbox360Report[4] { new Xbox360Report(), new Xbox360Report(),
new Xbox360Report(), new Xbox360Report()
};
Thread tempThread; Thread tempThread;
public List<string> affectedDevs = new List<string>() public List<string> affectedDevs = new List<string>()
{ {
@ -424,7 +421,7 @@ namespace DS4Windows
{ {
LogDebug("Plugging in X360 Controller #" + (i + 1)); LogDebug("Plugging in X360 Controller #" + (i + 1));
useDInputOnly[i] = false; useDInputOnly[i] = false;
x360controls[i] = new Xbox360Controller(vigemTestClient); x360controls[i] = vigemTestClient.CreateXbox360Controller();
int devIndex = i; int devIndex = i;
x360controls[i].FeedbackReceived += (sender, args) => x360controls[i].FeedbackReceived += (sender, args) =>
{ {
@ -680,7 +677,7 @@ namespace DS4Windows
{ {
LogDebug("Plugging in X360 Controller #" + (Index + 1)); LogDebug("Plugging in X360 Controller #" + (Index + 1));
useDInputOnly[Index] = false; useDInputOnly[Index] = false;
x360controls[Index] = new Xbox360Controller(vigemTestClient); x360controls[Index] = vigemTestClient.CreateXbox360Controller();
int devIndex = Index; int devIndex = Index;
x360controls[Index].FeedbackReceived += (sender, args) => x360controls[Index].FeedbackReceived += (sender, args) =>
{ {
@ -721,7 +718,7 @@ namespace DS4Windows
return true; return true;
} }
private void testNewReport(ref Xbox360Report xboxreport, DS4State state, private void testNewReport(ref IXbox360Controller cont, DS4State state,
int device) int device)
{ {
Xbox360Buttons tempButtons = 0; Xbox360Buttons tempButtons = 0;
@ -746,54 +743,54 @@ namespace DS4Windows
if (state.Cross) tempButtons |= Xbox360Buttons.A; if (state.Cross) tempButtons |= Xbox360Buttons.A;
if (state.Square) tempButtons |= Xbox360Buttons.X; if (state.Square) tempButtons |= Xbox360Buttons.X;
if (state.PS) tempButtons |= Xbox360Buttons.Guide; if (state.PS) tempButtons |= Xbox360Buttons.Guide;
xboxreport.SetButtonsFull(tempButtons); cont.SetButtonsFull((ushort)tempButtons);
} }
xboxreport.LeftTrigger = state.L2; cont.LeftTrigger = state.L2;
xboxreport.RightTrigger = state.R2; cont.RightTrigger = state.R2;
SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device); SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device);
switch (steeringWheelMappedAxis) switch (steeringWheelMappedAxis)
{ {
case SASteeringWheelEmulationAxisType.None: case SASteeringWheelEmulationAxisType.None:
xboxreport.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbX = AxisScale(state.LX, false);
xboxreport.LeftThumbY = AxisScale(state.LY, true); cont.LeftThumbY = AxisScale(state.LY, true);
xboxreport.RightThumbX = AxisScale(state.RX, false); cont.RightThumbX = AxisScale(state.RX, false);
xboxreport.RightThumbY = AxisScale(state.RY, true); cont.RightThumbY = AxisScale(state.RY, true);
break; break;
case SASteeringWheelEmulationAxisType.LX: case SASteeringWheelEmulationAxisType.LX:
xboxreport.LeftThumbX = (short)state.SASteeringWheelEmulationUnit; cont.LeftThumbX = (short)state.SASteeringWheelEmulationUnit;
xboxreport.LeftThumbY = AxisScale(state.LY, true); cont.LeftThumbY = AxisScale(state.LY, true);
xboxreport.RightThumbX = AxisScale(state.RX, false); cont.RightThumbX = AxisScale(state.RX, false);
xboxreport.RightThumbY = AxisScale(state.RY, true); cont.RightThumbY = AxisScale(state.RY, true);
break; break;
case SASteeringWheelEmulationAxisType.LY: case SASteeringWheelEmulationAxisType.LY:
xboxreport.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbX = AxisScale(state.LX, false);
xboxreport.LeftThumbY = (short)state.SASteeringWheelEmulationUnit; cont.LeftThumbY = (short)state.SASteeringWheelEmulationUnit;
xboxreport.RightThumbX = AxisScale(state.RX, false); cont.RightThumbX = AxisScale(state.RX, false);
xboxreport.RightThumbY = AxisScale(state.RY, true); cont.RightThumbY = AxisScale(state.RY, true);
break; break;
case SASteeringWheelEmulationAxisType.RX: case SASteeringWheelEmulationAxisType.RX:
xboxreport.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbX = AxisScale(state.LX, false);
xboxreport.LeftThumbY = AxisScale(state.LY, true); cont.LeftThumbY = AxisScale(state.LY, true);
xboxreport.RightThumbX = (short)state.SASteeringWheelEmulationUnit; cont.RightThumbX = (short)state.SASteeringWheelEmulationUnit;
xboxreport.RightThumbY = AxisScale(state.RY, true); cont.RightThumbY = AxisScale(state.RY, true);
break; break;
case SASteeringWheelEmulationAxisType.RY: case SASteeringWheelEmulationAxisType.RY:
xboxreport.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbX = AxisScale(state.LX, false);
xboxreport.LeftThumbY = AxisScale(state.LY, true); cont.LeftThumbY = AxisScale(state.LY, true);
xboxreport.RightThumbX = AxisScale(state.RX, false); cont.RightThumbX = AxisScale(state.RX, false);
xboxreport.RightThumbY = (short)state.SASteeringWheelEmulationUnit; cont.RightThumbY = (short)state.SASteeringWheelEmulationUnit;
break; break;
case SASteeringWheelEmulationAxisType.L2R2: case SASteeringWheelEmulationAxisType.L2R2:
xboxreport.LeftTrigger = xboxreport.RightTrigger = 0; cont.LeftTrigger = cont.RightTrigger = 0;
if (state.SASteeringWheelEmulationUnit >= 0) xboxreport.LeftTrigger = (Byte)state.SASteeringWheelEmulationUnit; if (state.SASteeringWheelEmulationUnit >= 0) cont.LeftTrigger = (Byte)state.SASteeringWheelEmulationUnit;
else xboxreport.RightTrigger = (Byte)state.SASteeringWheelEmulationUnit; else cont.RightTrigger = (Byte)state.SASteeringWheelEmulationUnit;
goto case SASteeringWheelEmulationAxisType.None; goto case SASteeringWheelEmulationAxisType.None;
case SASteeringWheelEmulationAxisType.VJoy1X: case SASteeringWheelEmulationAxisType.VJoy1X:
@ -1057,7 +1054,7 @@ namespace DS4Windows
if (!getDInputOnly(ind)) if (!getDInputOnly(ind))
{ {
LogDebug("Plugging in X360 Controller #" + (ind + 1)); LogDebug("Plugging in X360 Controller #" + (ind + 1));
x360controls[ind] = new Xbox360Controller(vigemTestClient); x360controls[ind] = vigemTestClient.CreateXbox360Controller();
x360controls[ind].FeedbackReceived += (eventsender, args) => x360controls[ind].FeedbackReceived += (eventsender, args) =>
{ {
SetDevRumble(device, args.LargeMotor, args.SmallMotor, ind); SetDevRumble(device, args.LargeMotor, args.SmallMotor, ind);
@ -1238,8 +1235,8 @@ namespace DS4Windows
if (!useDInputOnly[ind]) if (!useDInputOnly[ind])
{ {
testNewReport(ref x360reports[ind], cState, ind); testNewReport(ref x360controls[ind], cState, ind);
x360controls[ind]?.SendReport(x360reports[ind]); x360controls[ind]?.SubmitReport();
//x360Bus.Parse(cState, processingData[ind].Report, ind); //x360Bus.Parse(cState, processingData[ind].Report, ind);
// We push the translated Xinput state, and simultaneously we // We push the translated Xinput state, and simultaneously we
// pull back any possible rumble data coming from Xinput consumers. // pull back any possible rumble data coming from Xinput consumers.

View File

@ -3063,7 +3063,7 @@ namespace DS4Windows
tempDev.setBTPollRate(btPollRate[device]); tempDev.setBTPollRate(btPollRate[device]);
if (xinputStatus && xinputPlug) if (xinputStatus && xinputPlug)
{ {
control.x360controls[device] = new Nefarius.ViGEm.Client.Targets.Xbox360Controller(control.vigemTestClient); control.x360controls[device] = control.vigemTestClient.CreateXbox360Controller();
control.x360controls[device].Connect(); control.x360controls[device].Connect();
Global.useDInputOnly[device] = false; Global.useDInputOnly[device] = false;
AppLogger.LogToGui("X360 Controller # " + (device + 1) + " connected", false); AppLogger.LogToGui("X360 Controller # " + (device + 1) + " connected", false);

View File

@ -116,11 +116,11 @@
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.8.0.0, Culture=neutral, PublicKeyToken=c416bc1b32d97233, processorArchitecture=MSIL"> <Reference Include="Microsoft.Win32.TaskScheduler, Version=2.8.0.0, Culture=neutral, PublicKeyToken=c416bc1b32d97233, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.8.0\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath> <HintPath>..\packages\TaskScheduler.2.8.0\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference> </Reference>
<Reference Include="Nefarius.ViGEmClient" Condition="'$(Platform)' == 'x64'"> <Reference Include="Nefarius.ViGEm.Client" Condition="'$(Platform)' == 'x64'">
<HintPath>.\libs\x64\Nefarius.ViGEmClient\Nefarius.ViGEmClient.dll</HintPath> <HintPath>.\libs\x64\Nefarius.ViGEmClient\Nefarius.ViGEm.Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="Nefarius.ViGEmClient" Condition="'$(Platform)' == 'x86'"> <Reference Include="Nefarius.ViGEm.Client" Condition="'$(Platform)' == 'x86'">
<HintPath>.\libs\x86\Nefarius.ViGEmClient\Nefarius.ViGEmClient.dll</HintPath> <HintPath>.\libs\x86\Nefarius.ViGEmClient\Nefarius.ViGEm.Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -147,6 +147,7 @@
<Compile Include="DS4Control\ScpUtil.cs" /> <Compile Include="DS4Control\ScpUtil.cs" />
<Compile Include="DS4Control\UdpServer.cs" /> <Compile Include="DS4Control\UdpServer.cs" />
<Compile Include="DS4Control\Util.cs" /> <Compile Include="DS4Control\Util.cs" />
<Compile Include="DS4Control\VigemXbox360Report.cs" />
<Compile Include="DS4Forms\LanguagePackComboBox.cs"> <Compile Include="DS4Forms\LanguagePackComboBox.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>