Skip to content

Commit

Permalink
List only axes that are actually used
Browse files Browse the repository at this point in the history
Changed ControllerOptions to read raw axis data instead
of capabilities information to determine axis list.
Most devices have axes 1,2,3,6.
This makes that apparent.
  • Loading branch information
Pxtl committed Mar 5, 2017
1 parent d60fedf commit 708dadc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 12 additions & 2 deletions XOutput/ControllerDevice.cs
Expand Up @@ -22,7 +22,7 @@ public class ControllerDevice
public byte[] mapping = new byte[42];
bool[] buttons;
int[] dPads;
int[] analogs;
public int[] analogs;


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

//initialize values
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
}
byte[] saveData = SaveManager.Load(joy.Information.ProductName.ToString());
if (saveData != null)
{
mapping = saveData;
}
}

#region Utility Functions
Expand Down
22 changes: 13 additions & 9 deletions XOutput/ControllerOptions.cs
Expand Up @@ -44,16 +44,20 @@ public ControllerOptions(ControllerDevice device)
m.addOption("D-Pad " + i.ToString() + " Right", dpads,
new byte[] { 35, (byte)(i - 1), (byte)ind });
}
for (int i = 1; i <= dev.joystick.Capabilities.AxesCount; i++)
for (int i = 0; i <= dev.analogs.Length - 1; i++)
{
m.addOption("Axis " + i.ToString(), axes,
new byte[] { 16, (byte)(i - 1), (byte)ind });
m.addOption("IAxis " + i.ToString(), iaxes,
new byte[] { 17, (byte)(i - 1), (byte)ind });
m.addOption("HAxis" + i.ToString(), haxes,
new byte[] { 18, (byte)(i - 1), (byte)ind });
m.addOption("IHAxis" + i.ToString(), ihaxes,
new byte[] { 19, (byte)(i - 1), (byte)ind });
if (dev.analogs[i] != 0)
{
int labelNum = i + 1;
m.addOption("Axis " + labelNum.ToString(), axes,
new byte[] { 16, (byte)(i), (byte)ind });
m.addOption("IAxis " + labelNum.ToString(), iaxes,
new byte[] { 17, (byte)(i), (byte)ind });
m.addOption("HAxis" + labelNum.ToString(), haxes,
new byte[] { 18, (byte)(i), (byte)ind });
m.addOption("IHAxis" + labelNum.ToString(), ihaxes,
new byte[] { 19, (byte)(i), (byte)ind });
}
}
m.SelectionChangeCommitted += new System.EventHandler(SelectionChanged);
ind++;
Expand Down

0 comments on commit 708dadc

Please sign in to comment.