/// <summary> /// Creates a new instance of a <see cref = "Device" /> object that can manage a single PPJoy virtual device. /// </summary> /// <param name = "lptNum">LPT number that the device is attached to. /// A value of Zero specifies a virtual device.</param> /// <param name = "type"><see cref = "JoystickTypes">JoystickType</see> of the device.</param> /// <param name = "subType"><see cref = "JoystickSubTypes">JoystickSubType</see> of this device.</param> /// <param name = "productId">Product ID associated with the device.</param> /// <param name = "vendorId">Vendor ID associated with the device.</param> /// <param name = "unitNum">Unit number of the device.</param> internal Device(int lptNum, JoystickTypes type, JoystickSubTypes subType, int productId, int vendorId, int unitNum) { if (_lptNum < 0) { throw new ArgumentOutOfRangeException(nameof(lptNum)); } _lptNum = lptNum; _joyType = type; SetSubtype(subType); _productId = productId; _vendorId = vendorId; SetUnitNumber(unitNum); }
/// <summary> /// Sets the subtype of this device. /// </summary> /// <param name = "subType">a value from the JoystickSubTypes enumeration, indicating the desired subtype that this device should have</param> private void SetSubtype(JoystickSubTypes subType) { var deviceType = DeviceType; //validate the supplied subtype value, with respect to the known JoystickType value of this device if (DeviceManager.IsSubTypeValidGivenJoystickType(deviceType, subType)) { _subType = subType; } else { //the supplied subtype value is not valid, given the current type (JoystickType) of this device throw new ArgumentException("Invalid subtype: " + Enum.GetName(typeof(JoystickSubTypes), subType) + ", given known joystick type:" + Enum.GetName(typeof(JoystickTypes), deviceType)); } }