public devices.IDevice ResolveDevice (IHIDDevice hidDevice)
		{
			int i = 0;

			int inx;

			//Give Unity Update(Input works only in Update on Main single thread
			//and this funciton is happen on Event on other thread)
			//to be done so GetJoysticksNames return something
			//!!! Not tested yet on WIN
			System.Threading.Thread.Sleep (300);//sleep this Event add device thread
                    
			//find device match based on "names"
			string[] names = Input.GetJoystickNames ();
			inx = Array.IndexOf (names, hidDevice.Name);


			Debug.Log (String.Join (",", names));

			if (inx < 0)
				return null;

			if (inx > 3) {
				Debug.LogWarning ("Unity supports up to 4 Joysticks");
				return null;
			}

			DeviceProfile profile = hidDevice.loadProfile ();

					
                           
                        

			JoystickDevice device = new JoystickDevice (inx, hidDevice.PID, hidDevice.VID, hidDevice.ID, 12, 20, this);
			device.Name = hidDevice.Name;
			device.profile = profile;

			int numAxis = device.Axis.Count;
			int numButtons = device.Buttons.Count;

			for (; i < numAxis; i++) {
				device.Axis [i] = new AxisDetails ();
				if (profile != null && profile.axisNaming.Length > i) {
					device.Axis [i].name = profile.axisNaming [i];

				}
                
			}

			for (i=0; i < numButtons; i++) {
				device.Buttons [i] = new ButtonDetails ();
				if (profile != null && profile.buttonNaming.Length > i) {
					device.Buttons [i].name = profile.buttonNaming [i];
				}
			}
				
				

			return device;
		}
				public IDevice ResolveDevice (IHIDDevice hidDevice)
				{
						if (hidDevice.PID == 46675 && hidDevice.VID == 1103) {
								this.__hidInterface = hidDevice.hidInterface;

								//check for profile
								DeviceProfile profile = hidDevice.loadProfile();;




								JoystickDevice device = new ThrustmasterRGTFFDDevice (hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, 8, 10, this);
								device.Name = hidDevice.Name;
                                device.profile = profile;
								//JoystickDevice joystick = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, 8, 10, this);

               






								int index = 0;
								for (; index < 10; index++) {
										device.Buttons [index] = new ButtonDetails ();

										if (profile != null && profile.buttonNaming.Length > index) {
												device.Buttons [index].name = profile.buttonNaming [index];
										}
								}


								for (index = 0; index < 8; index++) {

										device.Axis [index] = new AxisDetails ();
										if (profile != null && profile.axisNaming.Length > index && device.Axis [index] != null) {
												device.Axis [index].name = profile.axisNaming [index];
						
										}

								}


           

								return device;
						}

						return null;
				}
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            if (hidDevice.PID == 46675 && hidDevice.VID == 1103)
            {
                this.__hidInterface = hidDevice.hidInterface;

                //check for profile
                DeviceProfile profile = hidDevice.loadProfile();;



                JoystickDevice device = new ThrustmasterRGTFFDDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, 8, 10, this);
                device.Name    = hidDevice.Name;
                device.profile = profile;
                //JoystickDevice joystick = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, 8, 10, this);



                int index = 0;
                for (; index < 10; index++)
                {
                    device.Buttons [index] = new ButtonDetails();

                    if (profile != null && profile.buttonNaming.Length > index)
                    {
                        device.Buttons [index].name = profile.buttonNaming [index];
                    }
                }


                for (index = 0; index < 8; index++)
                {
                    device.Axis [index] = new AxisDetails();
                    if (profile != null && profile.axisNaming.Length > index && device.Axis [index] != null)
                    {
                        device.Axis [index].name = profile.axisNaming [index];
                    }
                }



                return(device);
            }

            return(null);
        }
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        //public IDevice<IAxisDetails, IButtonDetails, IDeviceExtension> ResolveDevice(IHIDDeviceInfo info)
        {
            int type = -1;
            int len = XPAD_DEVICE.Length;
            for (int inx = 0; inx < len; inx += 3)
            {
                if (hidDevice.VID == XPAD_DEVICE[inx] && hidDevice.PID == XPAD_DEVICE[inx + 1])
                {
                    type = XPAD_DEVICE[inx + 2];
                    break;
                }
            }

            if (type < 0) return null;

            XInputDevice device;
            int i = 0;

           _hidInterface = hidDevice.hidInterface;


			//check for profile
			DeviceProfile profile = hidDevice.loadProfile();


           


            device = new XInputDevice(hidDevice.index, hidDevice.PID, hidDevice.VID,hidDevice.ID, 8, 20, this, type);
			device.Name = hidDevice.Name;
			device.profile = profile;

		

			
			
			//inti button structure
            for (; i < 20; i++)
            {
                device.Buttons[i] = new ButtonDetails();

				if (profile != null && profile.buttonNaming.Length > i) {
					device.Buttons [i].name = profile.buttonNaming [i];
				}
			}
			
			
			
			AxisDetails axisDetails;

            //LX
            axisDetails = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisX] = axisDetails;


            //LY
            axisDetails = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisY] = axisDetails;

            //RX
#if UNITY_STANDALONE_OSX 
            axisDetails = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisZ] = axisDetails;
#endif

 //RX
#if UNITY_STANDALONE_WIN
            axisDetails = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisU] = axisDetails;
#endif

            //RY
            axisDetails = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisR] = axisDetails;


            //TRIGGERS

            //LEFT TRIGGER
            #if UNITY_STANDALONE_OSX
            axisDetails = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisU] = axisDetails;

			//RIGHT TRIGGER
			axisDetails = new AxisDetails();
			axisDetails.max = 128;
			axisDetails.min = 0;
			device.Axis[JoystickAxis.AxisV] = axisDetails;
			#endif
			
			
			//LEFT TRIGGER
			#if UNITY_STANDALONE_WIN
            axisDetails = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisZ] = axisDetails;
          


            //RIGHT TRIGGER
            axisDetails = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisV] = axisDetails;
			#endif

            //POV
            axisDetails = new AxisDetails();
            axisDetails.isHat = true;
            device.Axis[JoystickAxis.AxisPovX] = axisDetails;
            axisDetails = new AxisDetails();
            axisDetails.isHat = true;
            device.Axis[JoystickAxis.AxisPovY] = axisDetails;

            ((HIDDevice)hidDevice).InputReportByteLength = 15;
            ((HIDDevice)hidDevice).OutputReportByteLength = 12;

			int numAxis=device.Axis.Count;
			for (i=0; i < numAxis; i++) {

				if (profile != null && profile.axisNaming.Length > i) {
					device.Axis [i].name = profile.axisNaming [i];
					
				}
				
			}
			
			
			return device;
			//return (IDevice<AxisDetails, ButtonDetails, XInputExtension>)joystick;
        }
Example #5
0
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        //public IDevice<IAxisDetails, IButtonDetails, IDeviceExtension> ResolveDevice(IHIDDeviceInfo info)
        {
            int type = -1;
            int len  = XPAD_DEVICE.Length;

            for (int inx = 0; inx < len; inx += 3)
            {
                if (hidDevice.VID == XPAD_DEVICE[inx] && hidDevice.PID == XPAD_DEVICE[inx + 1])
                {
                    type = XPAD_DEVICE[inx + 2];
                    break;
                }
            }

            if (type < 0)
            {
                return(null);
            }

            XInputDevice device;
            int          i = 0;

            _hidInterface = hidDevice.hidInterface;


            //check for profile
            DeviceProfile profile = hidDevice.loadProfile();



            device         = new XInputDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, 8, 20, this, type);
            device.Name    = hidDevice.Name;
            device.profile = profile;



            //inti button structure
            for (; i < 20; i++)
            {
                device.Buttons[i] = new ButtonDetails();

                if (profile != null && profile.buttonNaming.Length > i)
                {
                    device.Buttons [i].name = profile.buttonNaming [i];
                }
            }



            AxisDetails axisDetails;

            //LX
            axisDetails     = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisX] = axisDetails;


            //LY
            axisDetails     = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisY] = axisDetails;

            //RX
#if UNITY_STANDALONE_OSX
            axisDetails     = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisZ] = axisDetails;
#endif

            //RX
#if UNITY_STANDALONE_WIN
            axisDetails     = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisU] = axisDetails;
#endif

            //RY
            axisDetails     = new AxisDetails();
            axisDetails.max = 65535;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisR] = axisDetails;


            //TRIGGERS

            //LEFT TRIGGER
            #if UNITY_STANDALONE_OSX
            axisDetails     = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisU] = axisDetails;

            //RIGHT TRIGGER
            axisDetails     = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisV] = axisDetails;
                        #endif


            //LEFT TRIGGER
                        #if UNITY_STANDALONE_WIN
            axisDetails     = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisZ] = axisDetails;



            //RIGHT TRIGGER
            axisDetails     = new AxisDetails();
            axisDetails.max = 128;
            axisDetails.min = 0;
            device.Axis[JoystickAxis.AxisV] = axisDetails;
                        #endif

            //POV
            axisDetails       = new AxisDetails();
            axisDetails.isHat = true;
            device.Axis[JoystickAxis.AxisPovX] = axisDetails;
            axisDetails       = new AxisDetails();
            axisDetails.isHat = true;
            device.Axis[JoystickAxis.AxisPovY] = axisDetails;

            ((HIDDevice)hidDevice).InputReportByteLength  = 15;
            ((HIDDevice)hidDevice).OutputReportByteLength = 12;

            int numAxis = device.Axis.Count;
            for (i = 0; i < numAxis; i++)
            {
                if (profile != null && profile.axisNaming.Length > i)
                {
                    device.Axis [i].name = profile.axisNaming [i];
                }
            }


            return(device);
            //return (IDevice<AxisDetails, ButtonDetails, XInputExtension>)joystick;
        }
		public IDevice ResolveDevice(IHIDDevice hidDevice)
		{
			_hidInterface = hidDevice.hidInterface;
			
			JoystickDevice device;
			
			//Get jostick capabilities
			Native.JoyCaps caps;
			Native.JoystickError result = Native.JoystickError.InvalidParameters;



            DeviceProfile profile;

          
			
			int i;
			for (i = 0; i < 16; i++)
			{
				
				result = Native.joyGetDevCaps(i, out caps, Native.JoyCaps.SizeInBytes);
				
				
				if (result == Native.JoystickError.NoError && caps.PID == hidDevice.PID && hidDevice.VID == caps.VID)
				{
					
					
					//UnityEngine.Debug.Log("ID:"+i+" on PID:"+info.PID+" VID:"+info.VID+" info:"+info.DevicePath+"Bts"+caps.NumButtons.ToString()+"axes"+caps.NumAxes
					//  +"ProdID"+caps.PID+" name:"+caps.ProductName+" regkey"+caps.RegKey+"Man:"+caps.VID);
					
					
					
					
					
					
					
					int num_axes = caps.NumAxes;
					
					//!!! save ordNumber(I don't have still function that would return ordNum for WinMM from PID);
					((GenericHIDDevice)hidDevice).ord = i;
					
                    profile=hidDevice.loadProfile();
					
					device = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID,hidDevice.ID, 8, caps.NumButtons, this);
					device.Extension = new WinDefaultExtension();
					device.Name = hidDevice.Name;
					device.profile = profile;
					
					int buttonIndex = 0;
					for (; buttonIndex < caps.NumButtons; buttonIndex++)
					{
						device.Buttons[buttonIndex] = new ButtonDetails();
						
						if (profile != null && profile.buttonNaming.Length > buttonIndex)
						{
							device.Buttons[buttonIndex].name = profile.buttonNaming[buttonIndex];
						}
					}
					
					
					// Make sure to reverse the vertical axes, so that +1 points up and -1 points down.
					int axis = 0;
					AxisDetails axisDetails;
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.max = caps.XMax;
						axisDetails.min = caps.XMin;
						device.Axis[axis] = axisDetails;
						//if(axisDetails.min==0 && axisDetails.max==255) axisDetails.isTrigger=true;
						
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						
						axis++;
					}
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.max = caps.YMax;
						axisDetails.min = caps.YMin;
						// if (axisDetails.min == 0 && axisDetails.max == 32767) axisDetails.isTrigger = true;
						device.Axis[axis] = axisDetails;
						
						
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						
						//	stick.Details.Min[axis] = caps.YMin; stick.Details.Max[axis] = caps.YMax; 
						axis++;
					}
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.max = caps.ZMax;
						axisDetails.min = caps.ZMin;
						//if(axisDetails.min==0) axisDetails.isTrigger=true;
						device.Axis[axis] = axisDetails;
						
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						
						axis++;
					}
					
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.min = caps.RMin;
						axisDetails.max = caps.RMax;
						//    if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
						device.Axis[axis] = axisDetails;
						
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						
						axis++;
					}
					
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.min = caps.UMin;
						axisDetails.max = caps.UMax;
						//     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
						device.Axis[axis] = axisDetails;
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						axis++;
					}
					
					if (axis < num_axes)
					{
						axisDetails = new AxisDetails();
						axisDetails.max = caps.VMax;
						axisDetails.min = caps.VMin;
						//     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
						device.Axis[axis] = axisDetails;
						
						if (profile != null && profile.axisNaming.Length > axis)
						{
							axisDetails.name = profile.axisNaming[axis];
							
						}
						axis++;
					}
					
					if ((caps.Capabilities & Native.JoystCapsFlags.HasPov) != 0)
					{
						device.Axis[JoystickAxis.AxisPovX] = new AxisDetails();
						device.Axis[JoystickAxis.AxisPovY] = new AxisDetails();
						
						if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovX)
						{
							device.Axis[JoystickAxis.AxisPovX].name = profile.axisNaming[(int)JoystickAxis.AxisPovX];
							
						}
						
						if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovY)
						{
							device.Axis[JoystickAxis.AxisPovY].name = profile.axisNaming[(int)JoystickAxis.AxisPovY];
							
						}
						
						
						device.numPOV = 1;
						
						//                        WinDefaultExtension extension = joystick.Extension as WinDefaultExtension;
						//
						//                        extension.PovType = Native.PovType.Exists;
						//                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPov4Dir) != 0)
						//                            extension.PovType |= Native.PovType.Discrete;
						//                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPovContinuous) != 0)
						//                            extension.PovType |= Native.PovType.Continuous;
					}
					
					
					
					//  UnityEngine.Debug.Log(" max:" + caps.YMax + " min:" + caps.YMin + " max:" + caps.ZMax + " min:" + caps.ZMin);
					
					//    UnityEngine.Debug.Log(" max:" + caps.RMax + " min:" + caps.RMin + " max:" + caps.UMax + " min:" + caps.UMin);
					
					return device;
					
					
				}
			}
			
			
			return null;
			
			//return (IDevice<IAxisDetails, IButtonDetails, IDeviceExtension>)joystick;
		}
Example #7
0
        /// <summary>
        /// Resolves the device.
        /// </summary>
        /// <returns>returns JoystickDevice if driver is for this device or null</returns>
        /// <param name="info">Info.</param>
        /// <param name="hidDevice">Hid device.</param>
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            this._hidInterface = hidDevice.hidInterface;

            IntPtr deviceRef = hidDevice.deviceHandle;

            JoystickDevice device;
            int            axisIndex   = 0;
            int            buttonIndex = 0;

            Native.CFArray   elements = new Native.CFArray();
            IOHIDElementRef  element;
            IOHIDElementType type;

            //copy all matched
            elements.typeRef = Native.IOHIDDeviceCopyMatchingElements(deviceRef, IntPtr.Zero, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);

            int numButtons = 0;

            int numPov = 0;

            int numElements    = elements.Length;
            int HIDElementType = Native.IOHIDElementGetTypeID();

            //check for profile
            DeviceProfile profile = hidDevice.loadProfile();



            IAxisDetails axisDetailsPovX = null;
            IAxisDetails axisDetailsPovY = null;

            List <IAxisDetails> axisDetailsList = new List <IAxisDetails>();


            IAxisDetails axisDetails;

            for (int elementIndex = 0; elementIndex < numElements; elementIndex++)
            {
                element = elements[elementIndex].typeRef;


                if (element != IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType)
                {
                    type = Native.IOHIDElementGetType(element);


                    // All of the axis elements I've ever detected have been kIOHIDElementTypeInput_Misc. kIOHIDElementTypeInput_Axis is only included for good faith...
                    if (type == IOHIDElementType.kIOHIDElementTypeInput_Misc ||
                        type == IOHIDElementType.kIOHIDElementTypeInput_Axis)
                    {
                        axisDetails = new AxisDetails();

                        axisDetails.uid        = Native.IOHIDElementGetCookie(element);
                        axisDetails.min        = (int)Native.IOHIDElementGetLogicalMin(element);
                        axisDetails.max        = (int)Native.IOHIDElementGetLogicalMax(element);
                        axisDetails.isNullable = Native.IOHIDElementHasNullState(element);



                        if (Native.IOHIDElementGetUsage(element) == (uint)Native.HIDUsageGD.Hatswitch)
                        {
                            axisDetails.isHat = true;
                            axisDetailsPovX   = axisDetails;

                            axisDetailsPovY = new AxisDetails();

                            axisDetailsPovY.uid        = Native.IOHIDElementGetCookie(element);
                            axisDetailsPovY.min        = (int)Native.IOHIDElementGetLogicalMin(element);
                            axisDetailsPovY.max        = (int)Native.IOHIDElementGetLogicalMax(element);
                            axisDetailsPovY.isNullable = Native.IOHIDElementHasNullState(element);
                            axisDetailsPovY.isHat      = true;

                            numPov++;
                        }
                        else
                        {
                            if (axisDetails.min == 0)
                            {
                                axisDetails.isTrigger = true;
                            }
                            axisDetailsList.Add(axisDetails);
                        }
                    }
                    else if (type == IOHIDElementType.kIOHIDElementTypeInput_Button)
                    {
                        numButtons++;
                    }
                }
            }


            if (axisDetailsPovX != null)
            {
                int diff;

                diff = axisDetailsList.Count - 8;
                //need 2 slots for Pov X,Y
                if (diff >= 0)
                {
                    //just insert them
                    axisDetailsList.Insert((int)JoystickAxis.AxisPovX, axisDetailsPovX);
                    axisDetailsList.Insert((int)JoystickAxis.AxisPovY, axisDetailsPovY);
                }
                else if (diff < -1)
                {
                    diff = diff + 2;
                    while (diff < 0)
                    {
                        axisDetailsList.Add(null);
                        diff += 1;
                    }

                    axisDetailsList.Add(axisDetailsPovX);
                    axisDetailsList.Add(axisDetailsPovY);
                }
                else                  //=-1
                {
                    axisDetailsList.Resize(9);
                    axisDetailsList[(int)JoystickAxis.AxisPovX] = axisDetailsPovX;
                    axisDetailsList[(int)JoystickAxis.AxisPovY] = axisDetailsPovY;
                }
            }


            device         = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, axisDetailsList.Count, numButtons, this);
            device.Name    = hidDevice.Name;
            device.numPOV  = numPov;
            device.profile = profile;

            for (; axisIndex < device.Axis.Count; axisIndex++)
            {
                device.Axis[(JoystickAxis)axisIndex] = axisDetailsList[axisIndex];
                if (profile != null && profile.axisNaming.Length > axisIndex && device.Axis[axisIndex] != null)
                {
                    device.Axis[axisIndex].name = profile.axisNaming [axisIndex];
                }
            }



            for (int elementIndex = 0; elementIndex < numElements; elementIndex++)
            {
                element = elements[elementIndex].typeRef;

                if (element != IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType)
                {
                    type = Native.IOHIDElementGetType(element);
                    if (type == IOHIDElementType.kIOHIDElementTypeInput_Button)
                    {
                        //
                        device.Buttons[buttonIndex] = new ButtonDetails(Native.IOHIDElementGetCookie(element));


                        if (profile != null && profile.buttonNaming.Length > buttonIndex)
                        {
                            device.Buttons[buttonIndex].name = profile.buttonNaming [buttonIndex];
                        }
                        buttonIndex++;
                    }
                }
            }



            //joystick.isReady = false;

            device.Extension = new OSXDefaultExtension();



            return(device);
        }
Example #8
0
		/// <summary>
		/// Resolves the device.
		/// </summary>
		/// <returns>returns JoystickDevice if driver is for this device or null</returns>
		/// <param name="info">Info.</param>
		/// <param name="hidDevice">Hid device.</param>
		public IDevice ResolveDevice (IHIDDevice hidDevice)
		{
	
			this._hidInterface = hidDevice.hidInterface;

			IntPtr deviceRef=hidDevice.deviceHandle;

			JoystickDevice device;
			int axisIndex=0;
			int buttonIndex=0;

			Native.CFArray elements=new Native.CFArray();
			IOHIDElementRef element;
			IOHIDElementType type;

			//copy all matched 
			elements.typeRef=Native.IOHIDDeviceCopyMatchingElements(deviceRef, IntPtr.Zero,(int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone );
			
			int numButtons=0;
		
			int numPov=0;

			int numElements=elements.Length;
			int HIDElementType=Native.IOHIDElementGetTypeID();

			//check for profile
			DeviceProfile profile = hidDevice.loadProfile();




					




			IAxisDetails axisDetailsPovX=null;
			IAxisDetails axisDetailsPovY=null;

			List<IAxisDetails> axisDetailsList = new List <IAxisDetails>();
		

			IAxisDetails axisDetails;
			
							for (int elementIndex = 0; elementIndex < numElements; elementIndex++){

									element =  elements[elementIndex].typeRef;


								if(element!=IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType){
												
												type = Native.IOHIDElementGetType(element);
							
							
												// All of the axis elements I've ever detected have been kIOHIDElementTypeInput_Misc. kIOHIDElementTypeInput_Axis is only included for good faith...
												if (type == IOHIDElementType.kIOHIDElementTypeInput_Misc ||
												    type == IOHIDElementType.kIOHIDElementTypeInput_Axis) {
												


													axisDetails=new AxisDetails();
													
													axisDetails.uid=Native.IOHIDElementGetCookie(element);
													axisDetails.min=(int)Native.IOHIDElementGetLogicalMin(element);
													axisDetails.max=(int)Native.IOHIDElementGetLogicalMax(element);
													axisDetails.isNullable=Native.IOHIDElementHasNullState(element);

													

					

										            
													if(Native.IOHIDElementGetUsage(element)==(uint)Native.HIDUsageGD.Hatswitch){
												
														axisDetails.isHat=true;
														axisDetailsPovX=axisDetails;
		
														axisDetailsPovY=new AxisDetails();
														
														axisDetailsPovY.uid=Native.IOHIDElementGetCookie(element);
														axisDetailsPovY.min=(int)Native.IOHIDElementGetLogicalMin(element);
														axisDetailsPovY.max=(int)Native.IOHIDElementGetLogicalMax(element);
														axisDetailsPovY.isNullable=Native.IOHIDElementHasNullState(element);
														axisDetailsPovY.isHat=true;

							numPov++;


													}else{
							if(axisDetails.min==0) axisDetails.isTrigger=true;
							axisDetailsList.Add(axisDetails);

						}

										          
											
												} else if (type == IOHIDElementType.kIOHIDElementTypeInput_Button) {
													numButtons++;
												}
								}
			
						}


			if (axisDetailsPovX != null) {
				int diff;

				diff=axisDetailsList.Count -8;
				//need 2 slots for Pov X,Y
				if(diff>=0){
					//just insert them
					axisDetailsList.Insert((int)JoystickAxis.AxisPovX,axisDetailsPovX);
					axisDetailsList.Insert((int)JoystickAxis.AxisPovY,axisDetailsPovY);
				}else if(diff<-1){
					diff=diff+2;
					while(diff<0){
						axisDetailsList.Add(null);
						diff+=1;
					}

					axisDetailsList.Add(axisDetailsPovX);
					axisDetailsList.Add(axisDetailsPovY);

				}else{//=-1
					axisDetailsList.Resize (9);
					axisDetailsList[(int)JoystickAxis.AxisPovX]=axisDetailsPovX;
					axisDetailsList[(int)JoystickAxis.AxisPovY]=axisDetailsPovY;
				}

								
								
			}


			device=new JoystickDevice(hidDevice.index,hidDevice.PID,hidDevice.VID,hidDevice.ID,axisDetailsList.Count,numButtons,this);
			device.Name = hidDevice.Name;
			device.numPOV = numPov;
			device.profile = profile;

			for(;axisIndex<device.Axis.Count;axisIndex++)
			{
				
				device.Axis[(JoystickAxis)axisIndex]=axisDetailsList[axisIndex];
				if (profile != null && profile.axisNaming.Length > axisIndex && device.Axis[axisIndex]!=null) {
					device.Axis[axisIndex].name = profile.axisNaming [axisIndex];
					
				}

			}
			

			
			
			
			for (int elementIndex = 0; elementIndex < numElements; elementIndex++){
				element = elements[elementIndex].typeRef;

				if(element!=IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType){
				type = Native.IOHIDElementGetType(element);
				 if (type == IOHIDElementType.kIOHIDElementTypeInput_Button) {
								//
								device.Buttons[buttonIndex]=new ButtonDetails(Native.IOHIDElementGetCookie(element));


						if (profile != null && profile.buttonNaming.Length > buttonIndex) {
							device.Buttons[buttonIndex].name = profile.buttonNaming [buttonIndex];
						}
						buttonIndex++;
							
				}
			}
				
		}







			//joystick.isReady = false;

						device.Extension=new OSXDefaultExtension();








             return device;

		}
Example #9
0
        public devices.IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            int i = 0;

            int inx;

            //Give Unity Update(Input works only in Update on Main single thread
            //and this funciton is happen on Event on other thread)
            //to be done so GetJoysticksNames return something
            //!!! Not tested yet on WIN
            System.Threading.Thread.Sleep(300);             //sleep this Event add device thread

            //find device match based on "names"
            string[] names = Input.GetJoystickNames();
            inx = Array.IndexOf(names, hidDevice.Name);


            Debug.Log(String.Join(",", names));

            if (inx < 0)
            {
                return(null);
            }

            if (inx > 3)
            {
                Debug.LogWarning("Unity supports up to 4 Joysticks");
                return(null);
            }

            DeviceProfile profile = hidDevice.loadProfile();



            JoystickDevice device = new JoystickDevice(inx, hidDevice.PID, hidDevice.VID, hidDevice.ID, 12, 20, this);

            device.Name    = hidDevice.Name;
            device.profile = profile;

            int numAxis    = device.Axis.Count;
            int numButtons = device.Buttons.Count;

            for (; i < numAxis; i++)
            {
                device.Axis [i] = new AxisDetails();
                if (profile != null && profile.axisNaming.Length > i)
                {
                    device.Axis [i].name = profile.axisNaming [i];
                }
            }

            for (i = 0; i < numButtons; i++)
            {
                device.Buttons [i] = new ButtonDetails();
                if (profile != null && profile.buttonNaming.Length > i)
                {
                    device.Buttons [i].name = profile.buttonNaming [i];
                }
            }



            return(device);
        }
Example #10
0
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            _hidInterface = hidDevice.hidInterface;

            JoystickDevice device;

            //Get jostick capabilities
            Native.JoyCaps       caps;
            Native.JoystickError result = Native.JoystickError.InvalidParameters;



            DeviceProfile profile;



            int i;

            for (i = 0; i < 16; i++)
            {
                result = Native.joyGetDevCaps(i, out caps, Native.JoyCaps.SizeInBytes);


                if (result == Native.JoystickError.NoError && caps.PID == hidDevice.PID && hidDevice.VID == caps.VID)
                {
                    //UnityEngine.Debug.Log("ID:"+i+" on PID:"+info.PID+" VID:"+info.VID+" info:"+info.DevicePath+"Bts"+caps.NumButtons.ToString()+"axes"+caps.NumAxes
                    //  +"ProdID"+caps.PID+" name:"+caps.ProductName+" regkey"+caps.RegKey+"Man:"+caps.VID);



                    int num_axes = caps.NumAxes;

                    //!!! save ordNumber(I don't have still function that would return ordNum for WinMM from PID);
                    ((GenericHIDDevice)hidDevice).ord = i;

                    profile = hidDevice.loadProfile();

                    device           = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, 8, caps.NumButtons, this);
                    device.Extension = new WinDefaultExtension();
                    device.Name      = hidDevice.Name;
                    device.profile   = profile;

                    int buttonIndex = 0;
                    for (; buttonIndex < caps.NumButtons; buttonIndex++)
                    {
                        device.Buttons[buttonIndex] = new ButtonDetails();

                        if (profile != null && profile.buttonNaming.Length > buttonIndex)
                        {
                            device.Buttons[buttonIndex].name = profile.buttonNaming[buttonIndex];
                        }
                    }


                    // Make sure to reverse the vertical axes, so that +1 points up and -1 points down.
                    int         axis = 0;
                    AxisDetails axisDetails;
                    if (axis < num_axes)
                    {
                        axisDetails       = new AxisDetails();
                        axisDetails.max   = caps.XMax;
                        axisDetails.min   = caps.XMin;
                        device.Axis[axis] = axisDetails;
                        //if(axisDetails.min==0 && axisDetails.max==255) axisDetails.isTrigger=true;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }
                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.YMax;
                        axisDetails.min = caps.YMin;
                        // if (axisDetails.min == 0 && axisDetails.max == 32767) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;


                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        //	stick.Details.Min[axis] = caps.YMin; stick.Details.Max[axis] = caps.YMax;
                        axis++;
                    }
                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.ZMax;
                        axisDetails.min = caps.ZMin;
                        //if(axisDetails.min==0) axisDetails.isTrigger=true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.min = caps.RMin;
                        axisDetails.max = caps.RMax;
                        //    if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.min = caps.UMin;
                        axisDetails.max = caps.UMax;
                        //     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;
                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }
                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.VMax;
                        axisDetails.min = caps.VMin;
                        //     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }
                        axis++;
                    }

                    if ((caps.Capabilities & Native.JoystCapsFlags.HasPov) != 0)
                    {
                        device.Axis[JoystickAxis.AxisPovX] = new AxisDetails();
                        device.Axis[JoystickAxis.AxisPovY] = new AxisDetails();

                        if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovX)
                        {
                            device.Axis[JoystickAxis.AxisPovX].name = profile.axisNaming[(int)JoystickAxis.AxisPovX];
                        }

                        if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovY)
                        {
                            device.Axis[JoystickAxis.AxisPovY].name = profile.axisNaming[(int)JoystickAxis.AxisPovY];
                        }


                        device.numPOV = 1;

                        //                        WinDefaultExtension extension = joystick.Extension as WinDefaultExtension;
                        //
                        //                        extension.PovType = Native.PovType.Exists;
                        //                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPov4Dir) != 0)
                        //                            extension.PovType |= Native.PovType.Discrete;
                        //                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPovContinuous) != 0)
                        //                            extension.PovType |= Native.PovType.Continuous;
                    }



                    //  UnityEngine.Debug.Log(" max:" + caps.YMax + " min:" + caps.YMin + " max:" + caps.ZMax + " min:" + caps.ZMin);

                    //    UnityEngine.Debug.Log(" max:" + caps.RMax + " min:" + caps.RMin + " max:" + caps.UMax + " min:" + caps.UMin);

                    return(device);
                }
            }


            return(null);

            //return (IDevice<IAxisDetails, IButtonDetails, IDeviceExtension>)joystick;
        }