From b513e35ea8a3169754a993447fd7ed1bf4c96714 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Thu, 2 Jan 2014 19:24:38 +0100 Subject: [PATCH] [SDL2] Implemented PacketNumber property --- Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 25b6b253..faff9226 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -42,6 +42,7 @@ namespace OpenTK.Platform.SDL2 { public IntPtr Handle { get; set; } public Guid Guid { get; set; } + public int PacketNumber { get; set; } public int HatCount { get; set; } public int BallCount { get; set; } public bool IsConnected { get; set; } @@ -73,7 +74,6 @@ namespace OpenTK.Platform.SDL2 readonly Dictionary sdl_instanceid_to_controllers = new Dictionary(); #endif - public Sdl2JoystickDriver() { joysticks_readonly = joysticks.AsReadOnly(); @@ -339,6 +339,7 @@ namespace OpenTK.Platform.SDL2 JoystickDevice joystick = (JoystickDevice)joysticks[index]; float value = ev.Value * RangeMultiplier; joystick.SetAxis((JoystickAxis)ev.Axis, value); + joystick.Details.PacketNumber = Math.Max(0, unchecked(joystick.Details.PacketNumber + 1)); } else { @@ -354,6 +355,7 @@ namespace OpenTK.Platform.SDL2 int index = sdl_instanceid_to_joysticks[id]; JoystickDevice joystick = (JoystickDevice)joysticks[index]; // Todo: does it make sense to support balls? + joystick.Details.PacketNumber = Math.Max(0, unchecked(joystick.Details.PacketNumber + 1)); } else { @@ -369,6 +371,7 @@ namespace OpenTK.Platform.SDL2 int index = sdl_instanceid_to_joysticks[id]; JoystickDevice joystick = (JoystickDevice)joysticks[index]; joystick.SetButton((JoystickButton)ev.Button, ev.State == State.Pressed); + joystick.Details.PacketNumber = Math.Max(0, unchecked(joystick.Details.PacketNumber + 1)); } else { @@ -384,6 +387,7 @@ namespace OpenTK.Platform.SDL2 int index = sdl_instanceid_to_joysticks[id]; JoystickDevice joystick = (JoystickDevice)joysticks[index]; // Todo: map hat to an extra axis + joystick.Details.PacketNumber = Math.Max(0, unchecked(joystick.Details.PacketNumber + 1)); } else { @@ -588,6 +592,7 @@ namespace OpenTK.Platform.SDL2 } state.SetIsConnected(joystick.Details.IsConnected); + state.SetPacketNumber(joystick.Details.PacketNumber); } return state;