[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 #endregion
} }
#if DEBUG
static readonly string TypeName = typeof(WinRawJoystick).Name;
#endif
XInputJoystick XInput = new XInputJoystick(); XInputJoystick XInput = new XInputJoystick();
// Defines which types of HID devices we are interested in // Defines which types of HID devices we are interested in
@ -464,21 +468,27 @@ namespace OpenTK.Platform.Windows
void QueryDeviceCaps(Device stick) void QueryDeviceCaps(Device stick)
{ {
HidProtocolCaps caps; Debug.Print("[{0}] Querying joystick {1}",
TypeName, stick.GetGuid());
// Discovered elements try
int axes = 0; {
int dpads = 0; Debug.Indent();
int buttons = 0; HidProtocolCaps caps;
if (GetPreparsedData(stick.Handle, ref PreparsedData) && if (GetPreparsedData(stick.Handle, ref PreparsedData) &&
GetDeviceCaps(stick, PreparsedData, out caps)) GetDeviceCaps(stick, PreparsedData, out caps))
{ {
for (int i = 0; i < stick.AxisCaps.Count; i++) 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; continue;
} }
@ -497,10 +507,16 @@ namespace OpenTK.Platform.Windows
case HIDUsageGD.Slider: case HIDUsageGD.Slider:
case HIDUsageGD.Dial: case HIDUsageGD.Dial:
case HIDUsageGD.Wheel: 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); stick.SetAxis(page, stick.AxisCaps[i].NotRange.Usage, 0);
break; break;
case HIDUsageGD.Hatswitch: 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); stick.SetHat(page, stick.AxisCaps[i].NotRange.Usage, HatPosition.Centered);
break; break;
} }
@ -511,6 +527,9 @@ namespace OpenTK.Platform.Windows
{ {
case HIDUsageSim.Rudder: case HIDUsageSim.Rudder:
case HIDUsageSim.Throttle: 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); stick.SetAxis(page, stick.AxisCaps[i].NotRange.Usage, 0);
break; break;
} }
@ -520,6 +539,17 @@ namespace OpenTK.Platform.Windows
for (int i = 0; i < stick.ButtonCaps.Count; i++) 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; bool is_range = stick.ButtonCaps[i].IsRange;
HIDPage page = stick.ButtonCaps[i].UsagePage; HIDPage page = stick.ButtonCaps[i].UsagePage;
switch (page) 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++) 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); stick.SetButton(page, usage, false);
} }
} }
else 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); stick.SetButton(page, stick.ButtonCaps[i].NotRange.Usage, false);
} }
break; break;
default: default:
Debug.Print("[WinRawJoystick] Unknown HIDPage {0} for button.", page); Debug.Print("Unknown page {0} for button.", page);
break; break;
} }
} }
} }
}
stick.SetCapabilities(new JoystickCapabilities(axes, buttons, dpads, true)); finally
{
Debug.Unindent();
}
} }
static bool GetDeviceCaps(Device stick, byte[] preparsed_data, out HidProtocolCaps caps) static bool GetDeviceCaps(Device stick, byte[] preparsed_data, out HidProtocolCaps caps)