Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "Sliders" (IHSlider) (pedals) with xoutput #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions XOutput/ControllerDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class ControllerDevice
public bool enabled = true;

public OutputState cOutput;
public byte[] mapping = new byte[42];
public byte[] mapping = new byte[44];
bool[] buttons;
int[] dPads;
int[] analogs;
public int[] analogs;


delegate byte input(byte subType, byte num);
Expand All @@ -33,7 +33,14 @@ public ControllerDevice(Joystick joy, int num)
deviceNumber = num;
name = joystick.Information.InstanceName;
cOutput = new OutputState();
for (int i = 0; i < 42; i++)

joystick.Poll();
JoystickState jState = joystick.GetCurrentState();
buttons = jState.GetButtons();
dPads = jState.GetPointOfViewControllers();
analogs = GetAxes(jState);

for (int i = 0; i < mapping.Length; i++)
{
mapping[i] = 255; //Changed default mapping to blank
}
Expand Down Expand Up @@ -141,10 +148,10 @@ private void updateInput()
input funcDPad = DPad;
input[] funcArray = new input[] { funcButton, funcAnalog, funcDPad };

byte[] output = new byte[21];
for (int i = 0; i < 21; i++)
byte[] output = new byte[22];
for (int i = 0; i < 22; i++)
{
if (mapping[i * 2] == 255)
if (mapping[i * 2] == 255 || mapping[i * 2] == 253)
{
continue;
}
Expand Down Expand Up @@ -214,7 +221,6 @@ public byte[] getoutput()
//Guide
Report[12] = (byte)(cOutput.Home ? 0xFF : 0x00);


Report[14] = cOutput.LX; //Left Stick X


Expand All @@ -231,7 +237,5 @@ public byte[] getoutput()

return Report;
}


}
}
42 changes: 39 additions & 3 deletions XOutput/ControllerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private class ContData
private Control handle;
public bool isExclusive = false;

protected int compensationValue = 0;

private object[] ds4locks = new object[4];

Expand Down Expand Up @@ -68,7 +69,6 @@ public void changeExclusive(bool e)
public ControllerDevice getController(int n)
{
return devices[n];

}

public void Swap(int i, int p)
Expand All @@ -94,6 +94,11 @@ public void setControllerEnable(int i, bool b)

private Int32 Scale(Int32 Value, Boolean Flip)
{
if (Value == 0)
{
return Value;
}

Value -= 0x80;

if (Value == -128) Value = -127;
Expand Down Expand Up @@ -133,6 +138,9 @@ public override bool Start()
{
if (devices[i] != null && devices[i].enabled)
{
//Need to figure this out for multiple controllers...
compensationValue = devices[i].mapping[devices[i].mapping.Length - 1];

running = true;
processingData[i] = new ContData();
Console.WriteLine("Plug " + i);
Expand Down Expand Up @@ -299,7 +307,6 @@ private void ProcessData(int n)
byte[] data = devices[n].getoutput();
if (data != null && devices[n].enabled)
{

data[0] = (byte)n;
Parse(data, processingData[n].parsedData);
Report(processingData[n].parsedData, processingData[n].output);
Expand Down Expand Up @@ -362,7 +369,7 @@ public void Parse(Byte[] Input, Byte[] Output)
Output[12] = Input[26]; // Left Trigger
Output[13] = Input[27]; // Right Trigger

Int32 ThumbLX = Scale(Input[14], false);
Int32 ThumbLX = Scale(CorrectDeadZone(Input[14], 127, compensationValue), false);
Int32 ThumbLY = -Scale(Input[15], false);
Int32 ThumbRX = Scale(Input[16], false);
Int32 ThumbRY = -Scale(Input[17], false);
Expand All @@ -380,6 +387,35 @@ public void Parse(Byte[] Input, Byte[] Output)
Output[21] = (Byte)((ThumbRY >> 8) & 0xFF);
}
}
private int CorrectDeadZone(int input, int centerPoint, int deadZoneCompensation)
{
int returnVal = input;

if (deadZoneCompensation > 0)
{
if (input > centerPoint)
{
//Steering Right
returnVal += deadZoneCompensation;
}
else if (input < centerPoint)
{
//Steering Left
returnVal -= deadZoneCompensation;
}

//Full Lock
if (returnVal > 255)
{
returnVal = 255;
}
else if (returnVal < 1)
{
returnVal = 1;
}
}

return returnVal;
}
}
}
Loading