Example #1
0
 /// <summary>
 /// Writes a HID report, calling back a provided function for each segment.
 /// </summary>
 /// <param name="callback">
 ///     This callback will be called for each report segment.
 ///     Write to each segment to write a complete HID report.
 /// </param>
 public byte[] Write(ReportScanCallback callback)
 {
     byte[] buffer = new byte[1 + Length];
     buffer[0] = ID;
     Scan(buffer, 1, callback);
     return(buffer);
 }
Example #2
0
        /// <summary>
        /// Reads a HID report, calling back a provided function for each segment.
        /// </summary>
        /// <param name="buffer">The buffer containing the report.</param>
        /// <param name="offset">The offset to begin reading the report at.</param>
        /// <param name="callback">
        ///     This callback will be called for each report segment.
        ///     Use this to read every value you need.
        /// </param>
        public void Scan(byte[] buffer, int offset, ReportScanCallback callback)
        {
            int bitOffset = offset * 8;

            foreach (ReportSegment segment in Segments)
            {
                callback(buffer, bitOffset, segment);
                bitOffset += segment.BitCount;
            }
        }
Example #3
0
        /// <summary>
        /// Reads a HID report, calling back a provided function for each segment.
        /// </summary>
        /// <param name="buffer">The buffer containing the report.</param>
        /// <param name="offset">The offset to begin reading the report at.</param>
        /// <param name="callback">
        ///     This callback will be called for each report segment.
        ///     Use this to read every value you need.
        /// </param>
        public void Scan(byte[] buffer, int offset, ReportScanCallback callback)
        {
            int bitOffset = offset * 8;

            foreach (ReportSegment segment in Segments)
            {
                callback(buffer, bitOffset, segment);
                bitOffset += segment.BitCount;
            }
        }
Example #4
0
        /// <summary>
        /// Reads a HID report, calling back a provided function for each data item.
        /// </summary>
        /// <param name="buffer">The buffer containing the report.</param>
        /// <param name="offset">The offset to begin reading the report at.</param>
        /// <param name="callback">
        ///     This callback will be called for each data item.
        ///     Use this to read every value you need.
        /// </param>
        public void Read(byte[] buffer, int offset, ReportScanCallback callback)
        {
            Throw.If.Null(buffer).OutOfRange(buffer, offset, Length).Null(callback);
            if (buffer[offset] != ReportID)
            {
                throw new ArgumentException("Report ID not correctly set.", "buffer");
            }
            int bitOffset = (offset + 1) * 8;

            var dataItems     = DataItems;
            int dataItemCount = dataItems.Count;

            for (int indexOfDataItem = 0; indexOfDataItem < dataItemCount; indexOfDataItem++)
            {
                var dataItem = dataItems[indexOfDataItem];
                callback(buffer, bitOffset, dataItem, indexOfDataItem);
                bitOffset += dataItem.TotalBits;
            }
        }
Example #5
0
 public void Write(byte[] buffer, int offset, ReportScanCallback callback)
 {
     Throw.If.OutOfRange(buffer, offset, Length);
     buffer[offset] = ReportID; Array.Clear(buffer, offset + 1, Length - 1);
     Read(buffer, offset, callback);
 }
Example #6
0
 /// <summary>
 /// Writes a HID report, calling back a provided function for each data item.
 /// </summary>
 /// <param name="callback">
 ///     This callback will be called for each report data item.
 ///     Write to each data item to write a complete HID report.
 /// </param>
 public byte[] Write(ReportScanCallback callback)
 {
     byte[] buffer = new byte[Length];
     Write(buffer, 0, callback);
     return(buffer);
 }
Example #7
0
 /// <summary>
 /// Writes a HID report, calling back a provided function for each segment.
 /// </summary>
 /// <param name="callback">
 ///     This callback will be called for each report segment.
 ///     Write to each segment to write a complete HID report.
 /// </param>
 public byte[] Write(ReportScanCallback callback)
 {
     byte[] buffer = new byte[1 + Length];
     buffer[0] = ID; Scan(buffer, 1, callback);
     return buffer;
 }