Represents a servo driver for servos attached to the Raspberry Pi and driven via ServoBlaster.
Inheritance: IServoDriver
示例#1
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 servo pin 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)
        {
            Int32 index = this.DefinedServoPins.IndexOf(servoPin);

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

            RPIServoBlasterDriver driver = null;

            if (!this._allocatedDrivers.TryGetValue(servoPin, out driver))
            {
                String pinName = String.Empty;
                if (PIN_MAP.TryGetValue((IRaspiGpio)servoPin, out pinName))
                {
                    driver = new RPIServoBlasterDriver((IRaspiGpio)servoPin, index, pinName, this);
                    this.EnsureWriterIsCreated();
                }
            }
            return(driver);
        }
		/// <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 servo pin 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) {
			Int32 index = this.DefinedServoPins.IndexOf(servoPin);
			if (index < 0) {
				throw new ArgumentException("Servo driver cannot drive pin " + servoPin.ToString());
			}

			RPIServoBlasterDriver driver = null;
			if (!this._allocatedDrivers.TryGetValue(servoPin, out driver)) {
				String pinName = String.Empty;
				if (PIN_MAP.TryGetValue((IRaspiGpio)servoPin, out pinName)) {
					driver = new RPIServoBlasterDriver((IRaspiGpio)servoPin, index, pinName, this);
					this.EnsureWriterIsCreated();
				}
			}
			return driver;
		}