/// <summary> /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/> object. /// </summary> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/>. The <see cref="Dispose"/> method /// leaves the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/> in an unusable state. After /// calling <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/> so the garbage collector can reclaim /// the memory that the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/> was occupying.</remarks> public void Dispose() { if (this._isDisposed) { return; } if (this._provider != null) { this._provider.Dispose(); this._provider = null; } // Dispose the drivers, but not the pins. if (this._allocatedDrivers != null) { foreach (KeyValuePair <IPCA9685Pin, PCA9685GpioServoDriver> drv in this._allocatedDrivers) { drv.Value.Dispose(); } this._allocatedDrivers.Clear(); this._allocatedDrivers = null; } this._isDisposed = true; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoProvider"/> /// class with the GPIO provider for the PCA9685. /// </summary> /// <param name="provider"> /// A GPIO provider for the PCA9685 /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="provider"/> cannot be null. /// </exception> public PCA9685GpioServoProvider(PCA9685GpioProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } this._provider = provider; this._allocatedDrivers = new Dictionary <IPCA9685Pin, PCA9685GpioServoDriver>(); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoDriver"/> /// class with a PCA9685 GPIO provider and pin. /// </summary> /// <param name="provider"> /// The PCA9685 GPIO provider. /// </param> /// <param name="pin"> /// The PCA9685 pin (channel) the servo is attached to. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="provider"/> cannot be null. - or - /// <paramref name="pin"/> cannot be null. /// </exception> public PCA9685GpioServoDriver(PCA9685GpioProvider provider, IPCA9685Pin pin) { if (provider == null) { throw new ArgumentNullException("provider"); } if (pin == null) { throw new ArgumentNullException("pin"); } this._provider = provider; this._pin = pin; this.UpdateResolution(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// <filterpriority>2</filterpriority> /// <remarks>Call <see cref="Dispose"/> when you are finished using the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoDriver"/>. The <see cref="Dispose"/> method leaves /// the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoDriver"/> in an unusable state. After calling /// <see cref="Dispose"/>, you must release all references to the /// <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoDriver"/> so the garbage collector can reclaim the /// memory that the <see cref="CyrusBuilt.MonoPi.Components.Servos.PCA9685GpioServoDriver"/> was occupying.</remarks> public void Dispose() { if (this._isDisposed) { return; } if (this._provider != null) { this._provider.Dispose(); this._provider = null; } if (this._pin != null) { this._pin.Dispose(); this._pin = null; } this._pos = 0; this._res = 0; this._isDisposed = true; }