[Win] Improved joystick debugging information

This commit is contained in:
thefiddler 2014-08-02 22:57:42 +02:00
parent 1e5b2e57cd
commit a2d6f1801c

View file

@ -169,6 +169,10 @@ namespace OpenTK.Platform.Windows
#endregion
}
#if DEBUG
static readonly string TypeName = typeof(WinRawJoystick).Name;
#endif
XInputJoystick XInput = new XInputJoystick();
// Defines which types of HID devices we are interested in
@ -464,21 +468,27 @@ namespace OpenTK.Platform.Windows
void QueryDeviceCaps(Device stick)
{
HidProtocolCaps caps;
Debug.Print("[{0}] Querying joystick {1}",
TypeName, stick.GetGuid());
// Discovered elements
int axes = 0;
int dpads = 0;
int buttons = 0;
try
{
Debug.Indent();
HidProtocolCaps caps;
if (GetPreparsedData(stick.Handle, ref PreparsedData) &&
GetDeviceCaps(stick, PreparsedData, out caps))
{
for (int i = 0; i < stick.AxisCaps.Count; i++)
{
if (stick.AxisCaps[i].IsRange)
Debug.Print("Analyzing value collection {0} {1} {2}",
i,
stick.AxisCaps[i].IsRange ? "range" : "",
stick.AxisCaps[i].IsAlias ? "alias" : "");
if (stick.AxisCaps[i].IsRange || stick.AxisCaps[i].IsAlias)
{
Debug.Print("[WinRawJoystick] Range axis elements not implemented.");
Debug.Print("Skipping value collection {0}", i);
continue;
}
@ -497,10 +507,16 @@ namespace OpenTK.Platform.Windows
case HIDUsageGD.Slider:
case HIDUsageGD.Dial:
case HIDUsageGD.Wheel:
Debug.Print("Found axis {0} ({1} / {2})",
JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
stick.SetAxis(page, stick.AxisCaps[i].NotRange.Usage, 0);
break;
case HIDUsageGD.Hatswitch:
Debug.Print("Found hat {0} ({1} / {2})",
JoystickHat.Hat0 + stick.GetCapabilities().HatCount,
page, (HIDUsageGD)stick.AxisCaps[i].NotRange.Usage);
stick.SetHat(page, stick.AxisCaps[i].NotRange.Usage, HatPosition.Centered);
break;
}
@ -511,6 +527,9 @@ namespace OpenTK.Platform.Windows
{
case HIDUsageSim.Rudder:
case HIDUsageSim.Throttle:
Debug.Print("Found simulation axis {0} ({1} / {2})",
JoystickAxis.Axis0 + stick.GetCapabilities().AxisCount,
page, (HIDUsageSim)stick.AxisCaps[i].NotRange.Usage);
stick.SetAxis(page, stick.AxisCaps[i].NotRange.Usage, 0);
break;
}
@ -520,6 +539,17 @@ namespace OpenTK.Platform.Windows
for (int i = 0; i < stick.ButtonCaps.Count; i++)
{
Debug.Print("Analyzing button collection {0} {1} {2}",
i,
stick.ButtonCaps[i].IsRange ? "range" : "",
stick.ButtonCaps[i].IsAlias ? "alias" : "");
if (stick.ButtonCaps[i].IsAlias)
{
Debug.Print("Skipping button collection {0}", i);
continue;
}
bool is_range = stick.ButtonCaps[i].IsRange;
HIDPage page = stick.ButtonCaps[i].UsagePage;
switch (page)
@ -529,25 +559,32 @@ namespace OpenTK.Platform.Windows
{
for (short usage = stick.ButtonCaps[i].Range.UsageMin; usage <= stick.ButtonCaps[i].Range.UsageMax; usage++)
{
buttons++;
Debug.Print("Found button {0} ({1} / {2})",
JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
page, usage);
stick.SetButton(page, usage, false);
}
}
else
{
buttons++;
Debug.Print("Found button {0} ({1} / {2})",
JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
page, stick.ButtonCaps[i].NotRange.Usage);
stick.SetButton(page, stick.ButtonCaps[i].NotRange.Usage, false);
}
break;
default:
Debug.Print("[WinRawJoystick] Unknown HIDPage {0} for button.", page);
Debug.Print("Unknown page {0} for button.", page);
break;
}
}
}
stick.SetCapabilities(new JoystickCapabilities(axes, buttons, dpads, true));
}
finally
{
Debug.Unindent();
}
}
static bool GetDeviceCaps(Device stick, byte[] preparsed_data, out HidProtocolCaps caps)