Пример #1
0
        public BIPhysicalDeviceInfo[] GetDevices(bool throwOnFail)
        {
            DetectHIDDevices(throwOnFail);
            var devices = new List <BIPhysicalDeviceInfo>();

            for (var i = 0; i < _numDevices; i++)
            {
                var devName = Encoding.Default.GetString(_deviceList[i].DeviceName);
                devName = devName.Substring(0, (int)_deviceList[i].DeviceNameLength);
                var serial = Encoding.Default.GetString(_deviceList[i].SerialNum)
                             .Substring(0,
                                        (int)
                                        _deviceList[i].SerialNumLength);
                if (!string.IsNullOrEmpty(serial))
                {
                    devName += " (Serial #:";
                    devName += serial;
                    devName += ")";
                }
                var devicePath = Encoding.Default.GetString(_deviceList[i].DevicePath)
                                 .Substring(0,
                                            (int)
                                            _deviceList[i].PathLength);
                var deviceInfo = new BIPhysicalDeviceInfo(devicePath, devName);
                devices.Add(deviceInfo);
            }
            return(devices.ToArray());
        }
Пример #2
0
 public bool[] Poll(BIPhysicalDeviceInfo device, bool throwOnFail)
 {
     for (var i = 0; i < _numDevices; i++)
     {
         var thisDevice     = _deviceList[i];
         var thisDevicePath = Encoding.Default.GetString(thisDevice.DevicePath)
                              .Substring(0,
                                         (int)
                                         thisDevice.PathLength);
         if (device.Key == null || !thisDevicePath.Equals(device.Key.ToString(),
                                                          StringComparison.InvariantCultureIgnoreCase))
         {
             continue;
         }
         var result = ReadInputData(ref thisDevice, out var outbuffer, throwOnFail);
         //if (result == BIUSB.DEV_INPUT || result == BIUSB.DEV_WAIT)
         {
             var state = new bool[thisDevice.NumberInputIndices];
             for (var j = 0; j < System.Math.Min(outbuffer.Length, thisDevice.NumberInputIndices); j++)
             {
                 state[j] = outbuffer[j] == 1;
             }
             return(state);
         }
     }
     if (throwOnFail)
     {
         throw new OperationFailedException("Device not found.");
     }
     return(null);
 }
Пример #3
0
        public BIPhysicalControlInfo[] GetControlsOnDevice(BIPhysicalDeviceInfo device, bool throwOnFail)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }
            var devicePath = device.Key.ToString();

            if (!_devicesOpen)
            {
                GetDevices(throwOnFail);
            }
            var controls = new List <BIPhysicalControlInfo>();

            for (var i = 0; i < _numDevices; i++)
            {
                var thisDevice     = _deviceList[i];
                var thisDevicePath = Encoding.Default.GetString(thisDevice.DevicePath)
                                     .Substring(0,
                                                (int)
                                                thisDevice.PathLength);
                if (thisDevicePath.Equals(devicePath, StringComparison.InvariantCultureIgnoreCase))
                {
                    var numInputs = thisDevice.NumberInputIndices;
                    for (ushort j = 0; j < numInputs; j++)
                    {
                        var thisControl = new BIPhysicalControlInfo(device, j, "Button " + (j + 1));
                        controls.Add(thisControl);
                    }
                    break;
                }
            }
            return(controls.ToArray());
        }
Пример #4
0
 public bool IsDeviceAttached(BIPhysicalDeviceInfo device, bool throwOnFail)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     return(IsDeviceAttached(device.Key.ToString(), throwOnFail));
 }
Пример #5
0
        /// <summary>
        ///     Factory method to create instances of this class.  Stands in place of a constructor,
        ///     in order to re-use instances
        ///     when relevant constructor parameters are the same
        /// </summary>
        /// <param name="device">a BIPhysicalDeviceInfo object representing the Beta Innovations device to monitor</param>
        /// <returns>
        ///     a BIDeviceMonitor object representing the BetaInnovations device
        ///     being monitored, either created newly from-scratch, or returned from
        ///     this class's internal object pool if a monitor instance already exists
        /// </returns>
        public static BIDeviceMonitor GetInstance(BIPhysicalDeviceInfo device)
        {
            if (_monitors.ContainsKey(device))
            {
                return(_monitors[device]);
            }

            var monitor = new BIDeviceMonitor(device);

            _monitors.Add(device, monitor);
            return(monitor);
        }
Пример #6
0
 public BIPhysicalControlInfo[] GetControlsOnDevice(BIPhysicalDeviceInfo device)
 {
     return(GetControlsOnDevice(device, true));
 }
Пример #7
0
 /// <summary>
 ///     Hidden constructor -- forces callers to use one of the static factory methods
 ///     on this class.
 ///     Creates a new BIDeviceMonitor object
 ///     <param name="device">a BIPhysicalDeviceInfo object representing the device to monitor.</param>
 /// </summary>
 private BIDeviceMonitor(BIPhysicalDeviceInfo device)
 {
     Device = device;
     Prepare();
 }
 /// <summary>
 ///     Creates a new BIPhysicalControlInfo object.
 /// </summary>
 /// <param name="parent">
 ///     a BIPhysicalDeviceInfo object representing
 ///     the physical device on which this control appears
 /// </param>
 /// <param name="controlNum">
 ///     an integer indicating the relative zero-based
 ///     "offset" of this control in the collection of similar controls on the
 ///     same device.  Button 1 would be controlNum=0; the first slider would
 ///     similarily be controlNum=0; as would the first Pov control, etc.
 /// </param>
 /// <param name="alias">
 ///     A string containing a "friendly name" (alias) to
 ///     associate with this control.
 /// </param>
 public BIPhysicalControlInfo(BIPhysicalDeviceInfo parent, int controlNum, string alias)
     : base(parent, controlNum, ControlType.Button, AxisType.Unknown, alias)
 {
 }