Beispiel #1
0
		protected GamePad(InputDevice device)
		{
			_device = device;
			_deviceId = device.Id;

			_capabilities = CapabilitiesOfDevice(device);
		}
Beispiel #2
0
        public OuyaGamePad(InputDevice device)
        {
            _device = device;
            _deviceId = device.Id;
            _descriptor = device.Descriptor;
            _isConnected = true;

            _capabilities = CapabilitiesOfDevice(device);
        }
Beispiel #3
0
        //Check for any connected game controllers
        private void CheckGameControllers()
        {
            int[] deviceIds = input_manager.GetInputDeviceIds();
            foreach (int deviceId in deviceIds)
            {
                Android.Views.InputDevice dev = InputDevice.GetDevice(deviceId);
                int sources = (int)dev.Sources;

                if (((sources & (int)InputSourceType.Gamepad) == (int)InputSourceType.Gamepad) ||
                    ((sources & (int)InputSourceType.Joystick) == (int)InputSourceType.Joystick))
                {
                    if (!connected_devices.Contains(deviceId))
                    {
                        connected_devices.Add(deviceId);
                        if (current_device_id == -1)
                        {
                            current_device_id = deviceId;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private static GamePadCapabilities CapabilitiesOfDevice(InputDevice device)
        {
            //TODO: There is probably a better way to do this. Maybe device.GetMotionRange and device.GetKeyCharacterMap?
            //Or not http://stackoverflow.com/questions/11686703/android-enumerating-the-buttons-on-a-gamepad

            var capabilities = new GamePadCapabilities();
            capabilities.IsConnected = true;
            capabilities.GamePadType = GamePadType.GamePad;
            capabilities.HasLeftVibrationMotor = capabilities.HasRightVibrationMotor = device.Vibrator.HasVibrator;

            switch (device.Name)
            {
                case "OUYA Game Controller":

                    capabilities.HasAButton = true;
                    capabilities.HasBButton = true;
                    capabilities.HasXButton = true;
                    capabilities.HasYButton = true;

                    capabilities.HasLeftXThumbStick = true;
                    capabilities.HasLeftYThumbStick = true;
                    capabilities.HasRightXThumbStick = true;
                    capabilities.HasRightYThumbStick = true;

                    capabilities.HasLeftShoulderButton = true;
                    capabilities.HasRightShoulderButton = true;
                    capabilities.HasLeftTrigger = true;
                    capabilities.HasRightTrigger = true;

                    capabilities.HasDPadDownButton = true;
                    capabilities.HasDPadLeftButton = true;
                    capabilities.HasDPadRightButton = true;
                    capabilities.HasDPadUpButton = true;
                    break;

                case "Microsoft X-Box 360 pad":
                    capabilities.HasAButton = true;
                    capabilities.HasBButton = true;
                    capabilities.HasXButton = true;
                    capabilities.HasYButton = true;

                    capabilities.HasLeftXThumbStick = true;
                    capabilities.HasLeftYThumbStick = true;
                    capabilities.HasRightXThumbStick = true;
                    capabilities.HasRightYThumbStick = true;

                    capabilities.HasLeftShoulderButton = true;
                    capabilities.HasRightShoulderButton = true;
                    capabilities.HasLeftTrigger = true;
                    capabilities.HasRightTrigger = true;

                    capabilities.HasDPadDownButton = true;
                    capabilities.HasDPadLeftButton = true;
                    capabilities.HasDPadRightButton = true;
                    capabilities.HasDPadUpButton = true;

                    capabilities.HasStartButton = true;
                    capabilities.HasBackButton = true;
                    break;
            }
            return capabilities;
        }
Beispiel #5
0
        internal static OuyaGamePad GetGamePad(InputDevice device)
        {
            if (device == null || (device.Sources & InputSourceType.Gamepad) != InputSourceType.Gamepad)
                return null;

            // The recommended way to map devices to players numbers is to use OuyaController.GetPlayerNumByDeviceId(), 
            // however as of ODK 0.0.6 there is a bug where disconnected and reconnected controllers get mapped
            // to new player numbers. Also, the player number returned does not match the LED on the controller.
            // Once this is fixed, we could consider using OuyaController.GetPlayerNumByDeviceId()
            // http://forums.ouya.tv/discussion/819/getplayernumbydeviceid-can-return-1-after-controllers-disconnect-and-reconnect

            int firstDisconnectedPadId = -1;
            for (int i = 0; i < GamePads.Length; i++)
            {
                var pad = GamePads[i];
                if (pad != null && pad._isConnected && pad._deviceId == device.Id)
                {
                    return pad;
                }
                else if (pad != null && !pad._isConnected && pad._descriptor == device.Descriptor)
                {
                    Debug.WriteLine("Found previous controller [" + i + "] " + device.Name);
                    pad._deviceId = device.Id;
                    pad._isConnected = true;
                    return pad;
                }
                else if (pad == null)
                {
                    Debug.WriteLine("Found new controller [" + i + "] " + device.Name);
                    pad = new OuyaGamePad(device);
                    GamePads[i] = pad;
                    return pad;
                }
                else if (!pad._isConnected && firstDisconnectedPadId < 0)
                {
                    firstDisconnectedPadId = i;
                }
            }

            // If we get here, we failed to find a game pad or an empty slot to create one.
            // If we're holding onto a disconnected pad, overwrite it with this one
            if (firstDisconnectedPadId >= 0)
            {
                Debug.WriteLine("Found new controller in place of disconnected controller [" + firstDisconnectedPadId + "] " + device.Name);
                var pad = new OuyaGamePad(device);
                GamePads[firstDisconnectedPadId] = pad;
                return pad;
            }

            // All pad slots are taken so ignore further devices.
            return null;
        }
		private bool IsGamepad(InputDevice device)
		{
			if ((device.Sources & InputSourceType.Gamepad) == InputSourceType.Gamepad ||
			   (device.Sources & InputSourceType.ClassJoystick) == InputSourceType.Joystick) {
				return true;
			}
			return false;
		}
		//Get the centered position for the joystick axis
		private float GetCenteredAxis(MotionEvent e, InputDevice device, Axis axis)
		{
			InputDevice.MotionRange range = device.GetMotionRange (axis, e.Source);
			if (range != null) {
				float flat = range.Flat;
				float value = e.GetAxisValue (axis);
				if (System.Math.Abs (value) > flat) 
					return value;
			}

			return 0;

		}
Beispiel #8
0
		internal static GamePad GetGamePad(InputDevice device)
		{
			if ((device.Sources & InputSourceType.Gamepad) != InputSourceType.Gamepad)
				return null;

			for (int i = 0; i < GamePads.Length; i++)
			{
				if (GamePads[i] == null) //Have looked at all the gamepads, must be a new one
				{
					Console.WriteLine("Found new controller [" + i + "] " + device.Name);
					GamePads[i] = new GamePad(device);
					return GamePads[i];
				}

				if (GamePads[i]._deviceId == device.Id)
				{
					return GamePads[i];
				}
			}

			return null;
		}