[Win] Refactored UpdateAxes

This commit is contained in:
thefiddler 2014-07-31 23:47:18 +02:00
parent 354fc04614
commit be575d4475

View file

@ -320,20 +320,25 @@ namespace OpenTK.Platform.Windows
Array.Resize(ref DataBuffer, report_count);
}
/*
if (HidProtocol.GetData(HidProtocolReportType.Input,
DataBuffer, ref size, PreparsedData,
new IntPtr((void*)&rin->Data.HID.RawData),
rin->Data.HID.Size) != HidProtocolStatus.Success)
{
Debug.Print("[WinRawJoystick] HidProtocol.GetData() failed with {0}",
Marshal.GetLastWin32Error());
UpdateAxes(rin, stick);
UpdateButtons(rin, stick);
return true;
}
}
return false;
}
*/
UpdateButtons(rin, stick);
HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps)
{
if (caps.LogicalMax == 8)
return (HatPosition)value;
else
return HatPosition.Centered;
}
unsafe void UpdateAxes(RawInput* rin, Device stick)
{
for (int i = 0; i < stick.AxisCaps.Count; i++)
{
if (stick.AxisCaps[i].IsRange)
@ -374,20 +379,6 @@ namespace OpenTK.Platform.Windows
stick.SetAxis(page, usage, scaled_value);
}
}
return true;
}
}
return false;
}
private HatPosition GetHatPosition(uint value, HidProtocolValueCaps caps)
{
if (caps.LogicalMax == 8)
return (HatPosition)value;
else
return HatPosition.Centered;
}
unsafe void UpdateButtons(RawInput* rin, Device stick)
@ -642,43 +633,6 @@ namespace OpenTK.Platform.Windows
return guid;
}
static void UpdateAxes(Device stick, HidProtocolCaps caps, HidProtocolValueCaps[] axes, int axes_count, HidProtocolData[] data)
{
// Use the data indices in the axis and button caps arrays to
// access the data buffer we just filled.
for (int i = 0; i < axes_count; i++)
{
if (!axes[i].IsRange)
{
int index = axes[i].NotRange.DataIndex;
if (index < 0 || index >= caps.NumberInputValueCaps)
{
// Should never happen
Debug.Print("[WinRawJoystick] Error: DataIndex out of range");
continue;
}
if (data[index].DataIndex != i)
{
// Should also never happen
Debug.Print("[WinRawJoystick] DataIndex != index ({0} != {1})",
data[index].DataIndex, i);
continue;
}
short value = (short)HidHelper.ScaleValue(data[i].RawValue,
axes[i].LogicalMin, axes[i].LogicalMax,
short.MinValue, short.MaxValue);
stick.SetAxis(axes[i].UsagePage, axes[i].NotRange.Usage, value);
}
else
{
// Todo: fall back to HidProtocol.GetLinkCollectionNodes
}
}
}
Device GetDevice(IntPtr handle)
{
long hardware_id = handle.ToInt64();