Ejemplo n.º 1
0
        /// <summary>
        /// searchForNew is used when panel has been detached => attached but not found again because there is no hook (new HID instance ID).
        /// So already found panels should be left as is.
        /// </summary>
        /// <param name="loadStreamDeck"></param>
        /// <param name="searchForNew"></param>
        public void Startup(bool loadStreamDeck)
        {
            try
            {
                foreach (var gamingPanelSkeleton in Common.GamingPanelSkeletons)
                {
                    foreach (var hidDevice in HidDevices.Enumerate(gamingPanelSkeleton.VendorId, gamingPanelSkeleton.ProductId))
                    {
                        if (hidDevice != null)
                        {
                            if (!loadStreamDeck && gamingPanelSkeleton.VendorId == (int)GamingPanelVendorEnum.Elgato)
                            {
                                continue;
                            }

                            var hidIinstance = hidDevice.DevicePath;
                            if (!HIDDeviceAlreadyExists(hidIinstance))
                            {
                                var hidSkeleton = new HIDSkeleton(gamingPanelSkeleton, hidIinstance);
                                HIDSkeletons.Add(hidSkeleton);

                                hidDevice.MonitorDeviceEvents = true;
                                hidDevice.Inserted           += hidSkeleton.HIDDeviceOnInserted;
                                hidDevice.Removed            += hidSkeleton.HIDDeviceOnRemoved;

                                //Only Saitek needs this hid library, Stream Deck uses an other. But Stream Deck is added in order to have references.
                                if (hidSkeleton.PanelInfo.VendorId == (int)GamingPanelVendorEnum.Saitek || hidSkeleton.PanelInfo.VendorId == (int)GamingPanelVendorEnum.MadCatz)
                                {
                                    hidSkeleton.HIDReadDevice = hidDevice;
                                    hidSkeleton.HIDReadDevice.OpenDevice(DeviceMode.NonOverlapped, DeviceMode.NonOverlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                                    hidSkeleton.HIDReadDevice.MonitorDeviceEvents = true;

                                    hidSkeleton.HIDWriteDevice = hidDevice;
                                    hidSkeleton.HIDWriteDevice.OpenDevice(DeviceMode.NonOverlapped, DeviceMode.NonOverlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                                    hidSkeleton.HIDWriteDevice.MonitorDeviceEvents = true;
                                }
                            }
                        }
                    }
                }

                /*foreach (var hidSkeleton in HIDSkeletons)
                 * {
                 *  if (hidSkeleton.IsAttached)
                 *  {
                 *      Debug.WriteLine(hidSkeleton.GamingPanelType + "   " + hidSkeleton.HIDInstance);
                 *  }
                 * }*/
                Debug.WriteLine("*** HIDSkeleton count is " + HIDSkeletons.Count);
                //Broadcast that this panel was found.
                HIDSkeletons.FindAll(o => o.IsAttached).ToList().ForEach(o => AppEventHandler.PanelEvent(this, o.HIDInstance, o, PanelEventType.Found));

                //Broadcast that panel search is over and all panels have been found that exists.
                AppEventHandler.PanelEvent(this, null, null, PanelEventType.AllPanelsFound);
            }
            catch (Exception ex)
            {
                Common.ShowErrorMessageBox(ex);
            }
        }