private static void DisposeDevice(GamePadInfo info) { if (info.HapticType > 0) { Sdl.Haptic.Close(info.HapticDevice); } Sdl.GameController.Close(info.Device); }
internal static void UpdatePacketInfo(int instanceid, uint packetNumber) { int index; if (_translationTable.TryGetValue(instanceid, out index)) { GamePadInfo info = null; if (Gamepads.TryGetValue(index, out info)) { info.PacketNumber = packetNumber < int.MaxValue ? (int)packetNumber : (int)(packetNumber - (uint)int.MaxValue); } } }
internal static void AddDevice(int deviceId) { var gamepad = new GamePadInfo(); gamepad.Device = Sdl.GameController.Open(deviceId); gamepad.HapticDevice = Sdl.Haptic.OpenFromJoystick(Sdl.GameController.GetJoystick(gamepad.Device)); var id = 0; while (Gamepads.ContainsKey(id)) { id++; } Gamepads.Add(id, gamepad); if (gamepad.HapticDevice == IntPtr.Zero) { return; } try { if (Sdl.Haptic.EffectSupported(gamepad.HapticDevice, ref _hapticLeftRightEffect) == 1) { Sdl.Haptic.NewEffect(gamepad.HapticDevice, ref _hapticLeftRightEffect); gamepad.HapticType = 1; } else if (Sdl.Haptic.RumbleSupported(gamepad.HapticDevice) == 1) { Sdl.Haptic.RumbleInit(gamepad.HapticDevice); gamepad.HapticType = 2; } else { Sdl.Haptic.Close(gamepad.HapticDevice); } } catch { Sdl.Haptic.Close(gamepad.HapticDevice); gamepad.HapticDevice = IntPtr.Zero; Sdl.ClearError(); } RefreshTranslationTable(); }