Exemplo n.º 1
0
        /// <summary>
        /// Returns the short value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to retrieve.</param>
        /// <param name="result">Receives the result of the operation.</param>
        /// <returns>True if successful.</returns>
        /// <remarks></remarks>
        public bool HidGetFeature(byte featureCode, ref short result)
        {
            bool HidGetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(3L);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_GetFeature(hfile, mm, 3))
            {
                HidGetFeatureRet = false;
            }
            else
            {
                HidGetFeatureRet = true;
                result           = mm.ShortAtAbsolute(1L);
            }

            mm.Free();
            HidFeatures.CloseHid(hfile);
            return(HidGetFeatureRet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the long value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool HidSetFeature(byte featureCode, long value)
        {
            bool HidSetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(9L);
            mm.ByteAt(0L)         = featureCode;
            mm.LongAtAbsolute(1L) = value;
            if (!UsbLibHelpers.HidD_SetFeature(hfile, mm, 9))
            {
                HidSetFeatureRet = false;
            }
            else
            {
                HidSetFeatureRet = true;
            }

            HidFeatures.CloseHid(hfile);
            mm.Free();
            return(HidSetFeatureRet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the raw byte data for a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to retrieve.</param>
        /// <param name="result">Receives the result of the operation.</param>
        /// <param name="expectedSize">The expected size, in bytes, of the result.</param>
        /// <returns>True if successful.</returns>
        /// <remarks></remarks>
        public bool HidGetFeature(byte featureCode, ref byte[] result, int expectedSize)
        {
            bool HidGetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(expectedSize + 1);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_GetFeature(hfile, mm, expectedSize))
            {
                HidGetFeatureRet = false;
            }
            else
            {
                HidGetFeatureRet = true;
                result           = mm.ToByteArray(1L, expectedSize);
            }

            HidFeatures.CloseHid(hfile);
            mm.Free();
            return(HidGetFeatureRet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the raw byte value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool HidSetFeature(byte featureCode, byte[] value)
        {
            bool HidSetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(value.Length + 1);
            mm.FromByteArray(value, 1L);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_SetFeature(hfile, mm, (int)mm.Length))
            {
                HidSetFeatureRet = false;
            }
            else
            {
                HidSetFeatureRet = true;
            }

            mm.Free();
            HidFeatures.CloseHid(hfile);
            return(HidSetFeatureRet);
        }