Represents a servo driver for servos attached to a PCA9685 servo controller.
Inheritance: IServoDriver
        /// <summary>
        /// Gets a driver for the requested pin.
        /// </summary>
        /// <param name="servoPin">
        /// The pin the driver is needed for.
        /// </param>
        /// <returns>
        /// The servo driver assigned to the pin. May be null if no driver is
        /// assigned or if the pin is unknown.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// The specified pin cannot be driven by any available servo driver
        /// because it is not a defined servo pin.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// No driver is assigned to the specified pin - or - Cannot drive servo
        /// from specified pin - or - another initialization error occurred.
        /// </exception>
        public IServoDriver GetServoDriver(IPin servoPin)
        {
            List <IPin> servoPins = this.DefinedServoPins;
            Int32       index     = servoPins.IndexOf(servoPin);

            if (index < 0)
            {
                throw new ArgumentException("Servo driver cannot drive pin " + servoPin.ToString());
            }

            PCA9685GpioServoDriver driver = null;

            lock (_lock) {
                if (this._allocatedDrivers.ContainsKey((PCA9685Pin)servoPin))
                {
                    driver = this._allocatedDrivers.Values.ElementAt(index);
                }
                else
                {
                    driver = new PCA9685GpioServoDriver(this._provider, (PCA9685Pin)servoPin);
                    this._allocatedDrivers.Add((PCA9685Pin)servoPin, driver);
                }
            }
            return(driver);
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Gets a driver for the requested pin.
		/// </summary>
		/// <param name="servoPin">
		/// The pin the driver is needed for.
		/// </param>
		/// <returns>
		/// The servo driver assigned to the pin. May be null if no driver is
		/// assigned or if the pin is unknown.
		/// </returns>
		/// <exception cref="ArgumentException">
		/// The specified pin cannot be driven by any available servo driver
		/// because it is not a defined servo pin.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// No driver is assigned to the specified pin - or - Cannot drive servo
		/// from specified pin - or - another initialization error occurred.
		/// </exception>
		public IServoDriver GetServoDriver(IPin servoPin) {
			List<IPin> servoPins = this.DefinedServoPins;
			Int32 index = servoPins.IndexOf(servoPin);
			if (index < 0) {
				throw new ArgumentException("Servo driver cannot drive pin " + servoPin.ToString());
			}

			PCA9685GpioServoDriver driver = null;
			lock (_lock) {
				if (this._allocatedDrivers.ContainsKey((PCA9685Pin)servoPin)) {
					driver = this._allocatedDrivers.Values.ElementAt(index);
				}
				else {
					driver = new PCA9685GpioServoDriver(this._provider, (PCA9685Pin)servoPin);
					this._allocatedDrivers.Add((PCA9685Pin)servoPin, driver);
				}
			}
			return driver;
		}