Skip to content

Commit

Permalink
Merge branch 'release/test' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
micro-artwork committed Oct 29, 2021
2 parents 69b1b52 + 786b931 commit 662c02d
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 735 deletions.
1 change: 0 additions & 1 deletion XI2DS/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
137 changes: 125 additions & 12 deletions XI2DS/DualShock/DS4Controller.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
using System;
using System.Collections.Generic;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
using Nefarius.ViGEm.Client.Targets.DualShock4;
using Vortice.XInput;

namespace XI2DS.DualShock4
{
public class DS4Controller
{
{

public DualShock4Controller Controller { get; }
readonly Dictionary<GamepadButtons, DualShock4Button> ButtonFlags =
new Dictionary<GamepadButtons, DualShock4Button>()
{
{ GamepadButtons.Start, DualShock4Button.Options },

public int UserIndex { get; }

public bool IsConnected = false;
// back button is not used independently
//{ GamepadButtonFlags.Back, DualShock4Buttons.Share },
{ GamepadButtons.LeftThumb, DualShock4Button.ThumbLeft },
{ GamepadButtons.RightThumb, DualShock4Button.ThumbRight},

{ GamepadButtons.LeftShoulder, DualShock4Button.ShoulderLeft },
{ GamepadButtons.RightShoulder, DualShock4Button.ShoulderRight },

{ GamepadButtons.A, DualShock4Button.Cross },
{ GamepadButtons.B, DualShock4Button.Circle },
{ GamepadButtons.X, DualShock4Button.Square },
{ GamepadButtons.Y, DualShock4Button.Triangle }
};

FeedBackReceiver feedBackReceiver;
readonly Dictionary<GamepadButtons, DualShock4DPadDirection> DPadFlags =
new Dictionary<GamepadButtons, DualShock4DPadDirection>()
{
{ GamepadButtons.DPadUp, DualShock4DPadDirection.North },
{ GamepadButtons.DPadDown, DualShock4DPadDirection.South },
{ GamepadButtons.DPadLeft, DualShock4DPadDirection.West },
{ GamepadButtons.DPadRight, DualShock4DPadDirection.East }
};


public IDualShock4Controller Controller { get; }


public int UserIndex { get; }

public bool IsConnected = false;

public DS4Controller(ViGEmClient client, int userIndex, FeedBackReceiver feedBackReceiver)
IFeedBackReceiver feedBackReceiver;

public DS4Controller(ViGEmClient client, int userIndex, IFeedBackReceiver feedBackReceiver)
{
if (userIndex >= 4 && userIndex < 0)
{
throw new Exception("Not allowed user index type");
}

this.UserIndex = UserIndex;
this.Controller = new DualShock4Controller(client);
SetFeedBackReceiver(feedBackReceiver);
this.Controller = client.CreateDualShock4Controller();
SetFeedBackReceiver(feedBackReceiver);
}

private void SetFeedBackReceiver(FeedBackReceiver feedBackReceiver)
private void SetFeedBackReceiver(IFeedBackReceiver feedBackReceiver)
{
this.feedBackReceiver = feedBackReceiver;
this.Controller.FeedbackReceived += (sender, e)
Expand Down Expand Up @@ -62,11 +93,93 @@ public bool Disconnect()
return false;
}

public void SendReport(DualShock4Report report)
public void SubmitReport(State state)
{
if (this.IsConnected)
{
this.Controller.SendReport(report);
Gamepad gamepad = state.Gamepad;
GamepadButtons buttons = gamepad.Buttons;

foreach (KeyValuePair<GamepadButtons, DualShock4Button> item in ButtonFlags)
{
Controller.SetButtonState(item.Value, buttons.HasFlag(item.Key));
}

// combination for special button implementation
if (buttons.HasFlag(GamepadButtons.Back)) {

if (buttons.HasFlag(GamepadButtons.Start))
{
Controller.SetButtonState(DualShock4SpecialButton.Ps, true);
Controller.SetButtonState(DualShock4SpecialButton.Options, false);
}
else if (buttons.HasFlag(GamepadButtons.LeftShoulder))
{
Controller.SetButtonState(DualShock4SpecialButton.Share, true);
Controller.SetButtonState(DualShock4Button.ShoulderLeft, false);
}
else if (buttons.HasFlag(GamepadButtons.RightShoulder))
{
Controller.SetButtonState(DualShock4SpecialButton.Touchpad, true);
Controller.SetButtonState(DualShock4Button.ShoulderRight, false);
} else
{
Controller.SetButtonState(DualShock4SpecialButton.Ps, false);
Controller.SetButtonState(DualShock4SpecialButton.Share, false);
Controller.SetButtonState(DualShock4SpecialButton.Touchpad, false);
}

} else
{
Controller.SetButtonState(DualShock4SpecialButton.Ps, false);
Controller.SetButtonState(DualShock4SpecialButton.Share, false);
Controller.SetButtonState(DualShock4SpecialButton.Touchpad, false);
}

Controller.SetDPadDirection(DualShock4DPadDirection.None);

foreach (KeyValuePair<GamepadButtons, DualShock4DPadDirection> item in DPadFlags)
{
if (buttons.HasFlag(item.Key))
{
Controller.SetDPadDirection(item.Value);
}
}

if (buttons.HasFlag(GamepadButtons.DPadUp) && buttons.HasFlag(GamepadButtons.DPadLeft))
{
Controller.SetDPadDirection(DualShock4DPadDirection.Northwest);
}
else if (buttons.HasFlag(GamepadButtons.DPadUp) && buttons.HasFlag(GamepadButtons.DPadRight))
{
Controller.SetDPadDirection(DualShock4DPadDirection.Northeast);
}
else if (buttons.HasFlag(GamepadButtons.DPadDown) && buttons.HasFlag(GamepadButtons.DPadLeft))
{
Controller.SetDPadDirection(DualShock4DPadDirection.Southwest);
}
else if (buttons.HasFlag(GamepadButtons.DPadDown) && buttons.HasFlag(GamepadButtons.DPadRight))
{
Controller.SetDPadDirection(DualShock4DPadDirection.Southeast);
}

Int16 ltx = (Int16)((Math.Abs((float)gamepad.LeftThumbX) < Gamepad.LeftThumbDeadZone) ? 0 : (float)gamepad.LeftThumbX / short.MaxValue * 127);
Int16 lty = (Int16)((Math.Abs((float)gamepad.LeftThumbY) < Gamepad.LeftThumbDeadZone) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * -127);
Int16 rtx = (Int16)((Math.Abs((float)gamepad.RightThumbX) < Gamepad.RightThumbDeadZone) ? 0 : (float)gamepad.RightThumbX / short.MaxValue * 127);
Int16 rty = (Int16)((Math.Abs((float)gamepad.RightThumbY) < Gamepad.RightThumbDeadZone) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * -127);

Controller.SetAxisValue(DualShock4Axis.LeftThumbX, (byte)(ltx + 0x7f));
Controller.SetAxisValue(DualShock4Axis.LeftThumbY, (byte)(lty + 0x7f));
Controller.SetAxisValue(DualShock4Axis.RightThumbX, (byte)(rtx + 0x7f));
Controller.SetAxisValue(DualShock4Axis.RightThumbY, (byte)(rty + 0x7f));

Controller.SetButtonState(DualShock4Button.TriggerLeft, gamepad.LeftTrigger > Gamepad.TriggerThreshold);
Controller.SetSliderValue(DualShock4Slider.LeftTrigger, gamepad.LeftTrigger);
Controller.SetButtonState(DualShock4Button.TriggerRight, gamepad.RightTrigger > Gamepad.TriggerThreshold);
Controller.SetSliderValue(DualShock4Slider.RightTrigger, gamepad.RightTrigger);

this.Controller.SubmitReport();

}
}
}
Expand Down
13 changes: 0 additions & 13 deletions XI2DS/DualShock/FeedBackReceiver.cs

This file was deleted.

7 changes: 7 additions & 0 deletions XI2DS/DualShock/IFeedBackReceiver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace XI2DS.DualShock4
{
public interface IFeedBackReceiver
{
void OnFeedBackReceived(int userIndex, byte smallMotor, byte largeMotor);
}
}
4 changes: 0 additions & 4 deletions XI2DS/FodyWeavers.xml

This file was deleted.

12 changes: 7 additions & 5 deletions XI2DS/FormAbout.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion XI2DS/FormAbout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public string AssemblyTitle {
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
return "";
}
}

Expand Down
62 changes: 1 addition & 61 deletions XI2DS/FormAbout.resx
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
13 changes: 7 additions & 6 deletions XI2DS/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 662c02d

Please sign in to comment.