Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
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;

		}
Exemplo n.º 4
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;
		}
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hidDevice"></param>
        /// <returns></returns>
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {


            if ((hidDevice.VID == VID && hidDevice.PID == PID) || (hidDevice.VID == VID && hidDevice.PID == PID_MOTION_PLUS_INSIDE))
            {
                _hidInterface = hidDevice.hidInterface;


                WiimoteDevice device;
                int inx = 0;


                // create new Device
                device = new WiimoteDevice(((IHIDInterface)_hidInterface).Generics.Count, hidDevice.PID, hidDevice.VID,hidDevice.ID, 16, 12, 4, 4, this);



                //inti button structure
                for (; inx < 12; inx++)
                {
                    device.Buttons[inx] = new ButtonDetails();
                }

                AxisDetails axisDetails;


                //AccX
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccX] = axisDetails;

                //AccY
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccY] = axisDetails;

                //AccZ
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccZ] = axisDetails;

                //AccR
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccR] = axisDetails;

                //AccU
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccU] = axisDetails;

                //AccV
                axisDetails = new AxisDetails();
                device.Axis[JoystickAxis.AxisAccV] = axisDetails;


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

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

                //RX
                axisDetails = new AxisDetails();
                //       axisDetails.max = 32767;
                //        axisDetails.min = -32767;
                device.Axis[JoystickAxis.AxisZ] = axisDetails;

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


                //TRIGGERS
                axisDetails = new AxisDetails();
                axisDetails.max = 255;
                axisDetails.min = 0;
                axisDetails.isTrigger = true;
                device.Axis[JoystickAxis.AxisU] = axisDetails;


                axisDetails = new AxisDetails();
                axisDetails.max = 255;
                axisDetails.min = 0;
                axisDetails.isTrigger = true;
                device.Axis[JoystickAxis.AxisV] = axisDetails;

                //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 = REPORT_LENGTH;
                ((HIDDevice)hidDevice).OutputReportByteLength = REPORT_LENGTH;

            
              

               

                return device;

            }


            return null;
        }