コード例 #1
0
        /// <summary>
        /// Handler of callback by OS planned to be used with default OSXDriver
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="res">Res.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="valRef">Value reference.</param>
        internal void DeviceValueReceived(IntPtr context, IOReturn res, IntPtr sender, IOHIDValueRef valRef)
        {
            IOHIDElementRef element = Native.IOHIDValueGetElement(valRef);
            uint            uid     = Native.IOHIDElementGetCookie(element);
            int             value;

            Native.IOHIDElementType type = Native.IOHIDElementGetType(element);
            GenericHIDDevice        device;

            value = Native.IOHIDValueGetIntegerValue(valRef);

            //UnityEngine.Debug.Log ("DeviceValueReceived:"+value);


            try{
                GCHandle gch = GCHandle.FromIntPtr(context);
                device = (GenericHIDDevice)gch.Target;
            }
            catch (Exception e) {
                UnityEngine.Debug.LogException(e);
                return;
            }



            byte[] typeBuff  = BitConverter.GetBytes((uint)type);
            byte[] uidBuff   = BitConverter.GetBytes(uid);
            byte[] valueBuff = BitConverter.GetBytes(value);


            byte[] result = new byte[typeBuff.Length + uidBuff.Length + valueBuff.Length];
            System.Buffer.BlockCopy(typeBuff, 0, result, 0, typeBuff.Length);
            System.Buffer.BlockCopy(uidBuff, 0, result, typeBuff.Length, uidBuff.Length);
            System.Buffer.BlockCopy(valueBuff, 0, result, typeBuff.Length + uidBuff.Length, valueBuff.Length);



            device.__lastHIDReport.Status = HIDReport.ReadStatus.Success;
            device.__lastHIDReport.Data   = result;
        }