Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Source/Core Providers/Core_ViGEm/Core_ViGEm.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\Costura.Fody.5.1.0\build\Costura.Fody.props" Condition="Exists('..\..\..\packages\Costura.Fody.5.1.0\build\Costura.Fody.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -35,18 +36,22 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=2.0.1.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Costura.Fody.2.0.1\lib\net452\Costura.dll</HintPath>
<Reference Include="Costura, Version=5.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Costura.Fody.5.1.0\lib\netstandard1.0\Costura.dll</HintPath>
</Reference>
<Reference Include="Nefarius.ViGEmClient, Version=1.15.16.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Nefarius.ViGEmClient.1.15.16\lib\net452\Nefarius.ViGEmClient.dll</HintPath>
<Reference Include="Nefarius.ViGEm.Client, Version=1.17.178.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Nefarius.ViGEm.Client.1.17.178\lib\net452\Nefarius.ViGEm.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
Expand Down Expand Up @@ -110,8 +115,11 @@ xcopy /Y /i "$(TargetDir)*.dll" "$(SolutionDir)Artifacts\Providers\$(ProjectName
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Fody.3.0.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Fody.3.0.3\build\Fody.targets'))" />
<Error Condition="!Exists('..\..\..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\..\..\packages\Fody.6.4.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Fody.6.4.0\build\Fody.targets'))" />
<Error Condition="!Exists('..\..\..\packages\Costura.Fody.5.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Costura.Fody.5.1.0\build\Costura.Fody.props'))" />
</Target>
<Import Project="..\..\..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets" Condition="Exists('..\..\..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets')" />
<Import Project="..\..\..\packages\Fody.6.4.0\build\Fody.targets" Condition="Exists('..\..\..\packages\Fody.6.4.0\build\Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
96 changes: 58 additions & 38 deletions Source/Core Providers/Core_ViGEm/DS4Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,44 @@ public partial class Core_ViGEm
/// </summary>
private class DS4Handler : DeviceHandler
{
private readonly DualShock4Report _report = new DualShock4Report();
// private readonly DualShock4Report target = new DualShock4Report();

private static readonly List<DualShock4Axes> AxisIndexes = new List<DualShock4Axes>
private static readonly List<DualShock4Axis> AxisIndexes = new List<DualShock4Axis>
{
DualShock4Axes.LeftThumbX, DualShock4Axes.LeftThumbY, DualShock4Axes.RightThumbX, DualShock4Axes.RightThumbY,
DualShock4Axes.LeftTrigger, DualShock4Axes.RightTrigger
DualShock4Axis.LeftThumbX, DualShock4Axis.LeftThumbY, DualShock4Axis.RightThumbX, DualShock4Axis.RightThumbY
};

private static readonly List<DualShock4Slider> SliderIndexes = new List<DualShock4Slider>
{
DualShock4Slider.LeftTrigger, DualShock4Slider.RightTrigger
};

protected override List<string> axisNames { get; set; } = new List<string>
{
"LX", "LY", "RX", "RY", "L2 (LT)", "R2 (RT)"
};

private static readonly List<DualShock4Buttons> ButtonIndexes = new List<DualShock4Buttons>
private static readonly List<DualShock4Button> ButtonIndexes = new List<DualShock4Button>
{
DualShock4Buttons.Cross, DualShock4Buttons.Circle, DualShock4Buttons.Square, DualShock4Buttons.Triangle,
DualShock4Buttons.ShoulderLeft, DualShock4Buttons.ShoulderRight, DualShock4Buttons.ThumbLeft, DualShock4Buttons.ThumbRight,
DualShock4Buttons.Share, DualShock4Buttons.Options,
DualShock4Buttons.TriggerLeft, DualShock4Buttons.TriggerRight
DualShock4Button.Cross, DualShock4Button.Circle, DualShock4Button.Square, DualShock4Button.Triangle,
DualShock4Button.ShoulderLeft, DualShock4Button.ShoulderRight, DualShock4Button.ThumbLeft, DualShock4Button.ThumbRight,
DualShock4Button.Share, DualShock4Button.Options,
DualShock4Button.TriggerLeft, DualShock4Button.TriggerRight
};

private static readonly List<DualShock4SpecialButtons> SpecialButtonIndexes = new List<DualShock4SpecialButtons>
private static readonly List<DualShock4SpecialButton> SpecialButtonIndexes = new List<DualShock4SpecialButton>
{
DualShock4SpecialButtons.Ps, DualShock4SpecialButtons.Touchpad
DualShock4SpecialButton.Ps, DualShock4SpecialButton.Touchpad
};

protected override List<string> buttonNames { get; set; } = new List<string>
{
"Cross", "Circle", "Square", "Triangle", "L1", "R1", "LS", "RS", "Share", "Options", "L2", "R2", "PS", "TouchPad Click"
};

private static readonly List<DualShock4DPadValues> PovIndexes = new List<DualShock4DPadValues>
private static readonly List<DualShock4DPadDirection> PovIndexes = new List<DualShock4DPadDirection>
{
DualShock4DPadValues.North, DualShock4DPadValues.East, DualShock4DPadValues.South, DualShock4DPadValues.West
DualShock4DPadDirection.North, DualShock4DPadDirection.East, DualShock4DPadDirection.South, DualShock4DPadDirection.West
};

private readonly Dictionary<string, int> _povAxisStates = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)
Expand All @@ -64,17 +68,17 @@ private class DS4Handler : DeviceHandler
{3, ("x", -1)}
};

private static readonly Dictionary<(int x, int y), DualShock4DPadValues> AxisStatesToDpadValue = new Dictionary<(int x, int y), DualShock4DPadValues>()
{
{(0, 0), DualShock4DPadValues.None},
{(0, -1), DualShock4DPadValues.North},
{(1, -1), DualShock4DPadValues.Northeast},
{(1, 0), DualShock4DPadValues.East},
{(1, 1), DualShock4DPadValues.Southeast},
{(0, 1), DualShock4DPadValues.South},
{(-1, 1), DualShock4DPadValues.Southwest},
{(-1, 0), DualShock4DPadValues.West},
{(-1, -1), DualShock4DPadValues.Northwest}
private static readonly Dictionary<(int x, int y), DualShock4DPadDirection> AxisStatesToDpadValue = new Dictionary<(int x, int y), DualShock4DPadDirection>()
{
{(0, 0), DualShock4DPadDirection.None},
{(0, -1), DualShock4DPadDirection.North},
{(1, -1), DualShock4DPadDirection.Northeast},
{(1, 0), DualShock4DPadDirection.East},
{(1, 1), DualShock4DPadDirection.Southeast},
{(0, 1), DualShock4DPadDirection.South},
{(-1, 1), DualShock4DPadDirection.Southwest},
{(-1, 0), DualShock4DPadDirection.West},
{(-1, -1), DualShock4DPadDirection.Northwest}
};

public DS4Handler(DeviceClassDescriptor descriptor, int index) : base(descriptor, index)
Expand All @@ -83,7 +87,8 @@ public DS4Handler(DeviceClassDescriptor descriptor, int index) : base(descriptor

protected override void AcquireTarget()
{
target = new DualShock4Controller(_client);
target = _client.CreateDualShock4Controller();
((IDualShock4Controller)target).FeedbackReceived += new DualShock4FeedbackReceivedEventHandler(FeedbackEventHandler);
target.Connect();
}

Expand All @@ -96,22 +101,35 @@ protected override void RelinquishTarget()
protected override void SetAxisState(BindingDescriptor bindingDescriptor, int state)
{
var inputId = bindingDescriptor.Index;
_report.SetAxis(AxisIndexes[inputId], (byte)((state + 32768) / 256));
SendReport();
if (inputId > 3)
{
SetSliderState(bindingDescriptor, state);
} else
{
((IDualShock4Controller)target).SetAxisValue(AxisIndexes[inputId], (byte)((state + 32768) / 256));
/*SendReport();*/
}
}

protected void SetSliderState(BindingDescriptor bindingDescriptor, int state)
{
var inputId = bindingDescriptor.Index;
((IDualShock4Controller)target).SetSliderValue(SliderIndexes[inputId], (byte)((state + 32768) / 256));
/*SendReport();*/
}

protected override void SetButtonState(BindingDescriptor bindingDescriptor, int state)
{
var inputId = bindingDescriptor.Index;
if (inputId >= ButtonIndexes.Count)
{
_report.SetSpecialButtonState(SpecialButtonIndexes[inputId - ButtonIndexes.Count], state != 0);
((IDualShock4Controller)target).SetButtonState(SpecialButtonIndexes[inputId - ButtonIndexes.Count], state != 0);
}
else
{
_report.SetButtonState(ButtonIndexes[inputId], state != 0);
((IDualShock4Controller)target).SetButtonState(ButtonIndexes[inputId], state != 0);
}
SendReport();
/*SendReport();*/
}

protected override void SetPovState(BindingDescriptor bindingDescriptor, int state)
Expand All @@ -122,19 +140,21 @@ protected override void SetPovState(BindingDescriptor bindingDescriptor, int sta
var newState = state == 1 ? mapping.Direction : 0;
if (axisState == newState) return;
_povAxisStates[mapping.Axis] = newState;

var buttons = (int)_report.Buttons;
buttons &= ~15; // Clear all the Dpad bits

buttons |= (int)AxisStatesToDpadValue[(_povAxisStates["x"], _povAxisStates["y"])];
_report.Buttons = (ushort) buttons;
SendReport();
var buttons = AxisStatesToDpadValue[(_povAxisStates["x"], _povAxisStates["y"])];
((IDualShock4Controller)target).SetDPadDirection(buttons);
/*SendReport();*/
}

private void SendReport()
protected void FeedbackEventHandler(object sender, DualShock4FeedbackReceivedEventArgs e)
{
((DualShock4Controller)target).SendReport(_report);
SubscribeFeedback(e);
}

/*private void SendReport()
{
((IDualShock4Controller)target).SendReport(target);
}*/
}
}
}
15 changes: 14 additions & 1 deletion Source/Core Providers/Core_ViGEm/DeviceHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client;
using System;
using System.Collections.Generic;
using Hidwizards.IOWrapper.Libraries.ProviderLogger;
Expand All @@ -23,7 +24,7 @@ private abstract class DeviceHandler : IDisposable
protected DeviceClassDescriptor deviceClassDescriptor;
protected int deviceId;
protected bool isAcquired;
protected ViGEmTarget target;
protected IVirtualGamepad target;

protected abstract List<string> axisNames { get; set; }
protected static readonly List<BindingCategory> axisCategories = new List<BindingCategory>
Expand All @@ -43,6 +44,12 @@ public DeviceHandler(DeviceClassDescriptor descriptor,int index)
deviceClassDescriptor = descriptor;
}

protected bool SubscribeFeedback(EventArgs e)
{
// TODO: send feedback to main IOWrapper
return false;
}

protected bool SubscribeOutput(OutputSubscriptionRequest subReq)
{
return false;
Expand Down Expand Up @@ -95,6 +102,9 @@ public bool SetOutputState(OutputSubscriptionRequest subReq, BindingDescriptor b
case BindingType.Axis:
SetAxisState(bindingDescriptor, state);
break;
/*case BindingType.Slider:
SetSliderState(bindingDescriptor, state);
break;*/
case BindingType.Button:
SetButtonState(bindingDescriptor, state);
break;
Expand Down Expand Up @@ -189,9 +199,12 @@ protected DeviceReportNode GetPovReport()
return report;
}

protected abstract void FeedbackEventHandler(object sender, EventArgs e);

protected abstract void AcquireTarget();
protected abstract void RelinquishTarget();
protected abstract void SetAxisState(BindingDescriptor bindingDescriptor, int state);
// protected abstract void SetSliderState(BindingDescriptor bindingDescriptor, int state);
protected abstract void SetButtonState(BindingDescriptor bindingDescriptor, int state);
protected abstract void SetPovState(BindingDescriptor bindingDescriptor, int state);

Expand Down
Loading