Example #1
0
        /// <summary>
        ///
        /// </summary>
        public List <ButtonBaseItem> ReadInputReport()
        {
            var data   = ReadRawInputReport();
            int length = 100;
            var uu     = new NativeMethods.HIDP_DATA[length];

            if (NativeMethods.HidP_GetData(NativeMethods.HIDP_REPORT_TYPE.HidP_Input, uu, ref length, preparedData, data,
                                           data.Length) != NativeMethods.HIDP_STATUS_SUCCESS)
            {
                throw new Win32Exception();
            }

            var ret = new List <ButtonBaseItem>();

            for (var i = 0; i < length; i++)
            {
                foreach (var inputButtonCap in inputButtonCaps)
                {
                    if (inputButtonCap.NotRange.DataIndex == uu[i].DataIndex)
                    {
                        if (inputButtonCap.IsRange)
                        {
                            var newItem = new ButtonRangeItem();
                            newItem.TopLevelUsagePage = hidCaps.UsagePage;
                            newItem.UsagePage         = inputButtonCap.UsagePage;
                            newItem.ReportId          = inputButtonCap.ReportID;
                            newItem.UsageMin          = inputButtonCap.Range.UsageMin;
                            newItem.UsageMax          = inputButtonCap.Range.UsageMax;
                            ret.Add(newItem);
                        }
                        else
                        {
                            var newItem = new ButtonItem();
                            newItem.TopLevelUsagePage = hidCaps.UsagePage;
                            newItem.UsagePage         = inputButtonCap.UsagePage;
                            newItem.ReportId          = inputButtonCap.ReportID;
                            newItem.Usage             = inputButtonCap.NotRange.Usage;
                            ret.Add(newItem);
                        }
                    }
                }
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public void WriteOutputReport(List <ButtonBaseItem> usages)
        {
            var hidItems = new NativeMethods.HIDP_DATA[100];
            int lenght   = 0;

            byte reportId = 0;

            foreach (var usage in usages)
            {
                foreach (var outputButtonCap in outputButtonCaps)
                {
                    var notRangeItem = usage as ButtonItem;
                    if (notRangeItem != null)
                    {
                        if (notRangeItem.ReportId == outputButtonCap.ReportID && notRangeItem.UsagePage == outputButtonCap.UsagePage && notRangeItem.Usage == outputButtonCap.NotRange.Usage)
                        {
                            if (lenght == 0)
                            {
                                reportId = outputButtonCap.ReportID;
                            }
                            hidItems[lenght].DataIndex = outputButtonCap.NotRange.DataIndex;
                            hidItems[lenght].On        = true;
                            lenght++;
                        }
                    }
                    // TODO: Handle ButtonRangeItem
                }
            }

            var data = CreateRawOutputReport(reportId);

            if (NativeMethods.HidP_SetData(NativeMethods.HIDP_REPORT_TYPE.HidP_Output, hidItems, ref lenght, preparedData, data,
                                           data.Length) != NativeMethods.HIDP_STATUS_SUCCESS)
            {
                throw new Win32Exception();
            }

            WriteRawOutputReport(data);

//      // TODO: Do some LINQ'ing here
//      foreach (var outputButtonCap in outputButtonCaps)
//      {
//        if (outputButtonCap.IsRange == false && usagePage == outputButtonCap.UsagePage && usage == outputButtonCap.NotRange.Usage)
//        {
//          var data = CreateRawOutputReport(outputButtonCap.ReportID);
//
//          var b = new NativeMethods.HIDP_DATA[1];
//          b[0].DataIndex = outputButtonCap.NotRange.DataIndex;
//          b[0].On = true;
//          int lenght = 1;
//
//          if (NativeMethods.HidP_SetData(NativeMethods.HIDP_REPORT_TYPE.HidP_Output, b, ref lenght, preparedData, data,
//                                               data.Length) != NativeMethods.HIDP_STATUS_SUCCESS)
//          {
//            throw new Win32Exception();
//          }
//
//          WriteRawOutputReport(data);
//          return;
//        }
//      }
//      throw new Exception("Could not find UsagePage/Usage");
        }