Open() static private method

static private Open ( string devicePath ) : HidDevice
devicePath string
return HidDevice
Esempio n. 1
0
        private static void DeviceAdded(object sender, DeviceEventArgs args)
        {
            HidDevice hidDevice = HidDevice.Open(args.DevicePath);

            // We can be sure a hid device was be returned,
            // since we only registered device notifications
            // for hid devices.
            if (vendorId == hidDevice.VendorId &&
                productIds.Contains(hidDevice.ProductId))
            {
                // The device added appears to be a backlight device.
                devices.Add(args.DevicePath.ToUpper(), hidDevice);
            }
            else
            {
                // Not a backlight device, dispose!
                hidDevice.Dispose();
            }
        }
Esempio n. 2
0
        private static void DeviceAdded(object sender, DeviceEventArgs args)
        {
            HidDevice hidDevice = HidDevice.Open(args.DevicePath);

            // We can be sure a hid device was be returned,
            // since we only registered device notifications
            // for hid devices.
            if (VENDOR_ID == hidDevice.VendorId && KeyboardsToListenFor.Any(d => d.ProductID == hidDevice.ProductId))
            {
                // The device added appears to be a backlight device.
                LogitechKeyboard keyboard = new LogitechKeyboard(hidDevice, KeyboardsToListenFor.Where(k => k.ProductID == hidDevice.ProductId).First());
                devices.Add(keyboard);
                if (KeyboardConnected != null)
                {
                    KeyboardConnected(null, new LogitechKeyboardEventArgs(keyboard));
                }
            }
            else
            {
                // Not a backlight device, dispose!
                hidDevice.Dispose();
            }
        }
Esempio n. 3
0
        public static void Init(IntPtr windowHandle, params LogitechKeyboardType[] keyboardsToListenFor)
        {
            KeyboardsToListenFor = keyboardsToListenFor;

            // Initialize device event dispatcher.
            Guid hidClassGuid;

            Hid.HidD_GetHidGuid(out hidClassGuid);
            deviceEventNotifier = new DeviceEventNotifier(windowHandle, hidClassGuid);
            // Register for device removal/arrival events so we can keep
            // track of the currently attached devices of interest.
            deviceEventNotifier.DeviceArrival += DeviceAdded;
            deviceEventNotifier.DeviceRemoval += DeviceRemoved;

            devices = new List <LogitechKeyboard>();

            // Open all devices we can find for now.
            var devs = HidDevice.Open(VENDOR_ID, keyboardsToListenFor.Select(d => d.ProductID));

            foreach (var dev in devs)
            {
                devices.Add(new LogitechKeyboard(dev, keyboardsToListenFor.Where(k => k.ProductID == dev.ProductId).First()));
            }
        }