/// <summary> /// Devices the added. /// </summary> /// <param name="context">Context.</param> /// <param name="res">Res.</param> /// <param name="sender">Sender.</param> /// <param name="device">Device.</param> void HidDeviceAdded(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef deviceRef) { //IOReturn success = Native.IOHIDDeviceOpen (device, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone); if (deviceRef == IntPtr.Zero) { Debug.LogWarning("IOHIDeviceRef of Added Device equal to IntPtr.Zero"); return; } int product_id = (int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDProductIDKey)))).ToInteger(); int vendor_id =(int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDVendorIDKey)))).ToInteger(); string manufacturer=(new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDManufacturerKey)))).ToString(); string description =manufacturer+" "+(new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDProductKey)))).ToString(); int location=(int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDLocationIDKey)))).ToInteger(); string transport=(new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDTransportKey)))).ToString(); string path=String.Format("{0:s}_{1,4:X}_{2,4:X}_{3:X}", transport, vendor_id, product_id, location);//"%s_%04hx_%04hx_%x" //string serial=(new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDSerialNumberKey)))).ToString(); if(Generics.ContainsKey(path)) return; GenericHIDDevice hidDevice; IDevice joyDevice = null; // IDevice<IAxisDetails, IButtonDetails, IDeviceExtension> joyDevice = null; ///loop thru specific drivers and attach the driver to device if compatible if (__drivers != null) foreach (var driver in __drivers) { hidDevice=new GenericHIDDevice(GetIndexForDeviceWithID(path),vendor_id, product_id, path,deviceRef, this,path,description); if ((joyDevice = driver.ResolveDevice(hidDevice)) != null) { lock(syncRoot){ __Generics[path] = hidDevice; } //if (context != IntPtr.Zero) { Native.IOHIDDeviceRegisterRemovalCallback(deviceRef,HandleDeviceRemoved,context); //}else{ // Debug.LogWarning("IOHIDDeviceRegisterRemovalCallback not registerd cos of Context IntPtr.Zero"); //} Debug.Log("Device PID:" + joyDevice.PID + " VID:" + joyDevice.VID + "["+joyDevice.Name+"] attached to " + driver.GetType().ToString()); break; } } if (joyDevice == null) {//set default driver as resolver if no custom driver match device hidDevice=new GenericHIDDevice(GetIndexForDeviceWithID(path),vendor_id, product_id,path, deviceRef, this,path,description); if ((joyDevice = defaultDriver.ResolveDevice(hidDevice)) != null) { lock(syncRoot){ __Generics[path] = hidDevice; } //if (context != IntPtr.Zero) { Native.IOHIDDeviceRegisterRemovalCallback(deviceRef,HandleDeviceRemoved,context); //}else{ // Debug.LogWarning("IOHIDDeviceRegisterRemovalCallback not registerd cos of Context IntPtr.Zero"); //} Debug.Log("Device PID:" + joyDevice.PID + " VID:" + joyDevice.VID + "["+joyDevice.Name+"] attached to " + defaultDriver.GetType().ToString()); } else { Debug.LogWarning("Device PID:" + product_id.ToString() + " VID:" + vendor_id.ToString() + " not found compatible driver on the system.Removed!"); } } if(joyDevice!=null) this.DeviceConnectEvent(this,new DeviceEventArgs<IDevice>(joyDevice)); }
/// <summary> /// Devices the removed. /// </summary> /// <param name="context">Context.</param> /// <param name="res">Res.</param> /// <param name="sender">Sender.</param> /// <param name="device">Device.</param> void HidDeviceRemoved(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef deviceRef) { RemoveDevice (deviceRef); }
void DeviceRemoved(IntPtr inContext, IOReturn result, IntPtr sender) { RemoveDevice (sender); }