/// <summary>
 /// Sets the non-volatility mode.
 /// </summary>
 /// <param name="mode">
 /// The way non-volatile reads or writes are done.
 /// </param>
 /// <remarks>
 /// The visibility of this method is protected because not all
 /// devices support non-volatile wipers. Any derived class may
 /// publish this method.
 /// </remarks>
 /// <exception cref="InvalidOperationException">
 /// This device is not capable of non-volatile wipers.
 /// </exception>
 protected void SetNonVolatileMode(MicrochipPotNonVolatileMode mode)
 {
     if ((!this.IsNonVolatileWiperCapable) &&
         (this._nonVolMode != MicrochipPotNonVolatileMode.VolatileOnly))
     {
         throw new InvalidOperationException("This device is not capable of non-volatile wipers." +
                                             " You *must* use MicrochipPotNonVolatileMode.VolatileOnly.");
     }
     this._nonVolMode = mode;
 }
        /// <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.Potentiometers.Microchip.MicrochipPotentiometerBase"/>. The
        /// <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> in an unusable
        /// state. After calling <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> so the garbage
        /// collector can reclaim the memory that the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> was occupying.
        /// </remarks>
        public override void Dispose()
        {
            if (base.IsDisposed)
            {
                return;
            }

            if (this._controller != null)
            {
                this._controller.Dispose();
                this._controller = null;
            }

            this._currentValue = -1;
            this._channel      = MicrochipPotChannel.None;
            this._nonVolMode   = MicrochipPotNonVolatileMode.VolatileAndNonVolatile;
            base.Dispose();
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/>
        /// class with the I2C device connection, pin A0,A1, and A2 states,
        /// the potentiometer (channel) provided by the device, how to do
        /// non-volatile I/O and the initial value for devices which are not
        /// capable of non-volatile wipers.
        /// </summary>
        /// <param name="device">
        /// The I2C bus device this instance is connected to.
        /// </param>
        /// <param name="pinA0">
        /// Whether the device's address pin A0 is high (true) or low (false).
        /// </param>
        /// <param name="pinA1">
        /// Whether the device's address pin A1 is high (true) or low (false).
        /// </param>
        /// <param name="pinA2">
        /// Whether the device's address pin A2 is high (true) or low (false).
        /// </param>
        /// <param name="channel">
        /// Which of the potentiometers provided by the device to control.
        /// </param>
        /// <param name="nonVolatileMode">
        /// The way non-volatile reads or writes are done.
        /// </param>
        /// <param name="initialNonVolWiperValue">
        /// The value for devices which are not capable of non-volatile wipers.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
        /// cannot be null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="channel"/> is not supported by this device.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// Unable to open the I2C bus.
        /// </exception>
        protected MicrochipPotentiometerBase(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
                                             MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode, Int32 initialNonVolWiperValue)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (!this.IsChannelSupported(channel))
            {
                throw new ArgumentException("Specified channel not supported by device.", "channel");
            }

            this._channel    = channel;
            this._nonVolMode = nonVolatileMode;
            Int32 deviceAddr = BuildI2CAddress(pinA0, pinA1, pinA2);

            this._controller       = new MicrochipPotDeviceController(device, deviceAddr);
            this.WiperActionEvent += this.MicrochipPotentiometerBase_WiperActionEvent;
            this.Initialize(initialNonVolWiperValue);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4641"/>
 /// class with the I2C device connection, pin A0, A1, and A2 states,
 /// the potentiometer (channel) provided by the device, and how to
 /// do non-volatile I/O.
 /// </summary>
 /// <param name="device">
 /// The I2C bus device this instance is connected to.
 /// </param>
 /// <param name="pinA0">
 /// Whether the device's address pin A0 is high (true) or low (false).
 /// </param>
 /// <param name="pinA1">
 /// Whether the device's address pin A1 is high (true) or low (false).
 /// </param>
 /// <param name="pinA2">
 /// Whether the device's address pin A2 is high (true) or low (false).
 /// </param>
 /// <param name="channel">
 /// Which of the potentiometers provided by the device to control.
 /// </param>
 /// <param name="nonVolatileMode">
 /// The way non-volatile reads or writes are done.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
 /// cannot be null.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// <paramref name="channel"/> is not supported by this device.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// Unable to open the I2C bus.
 /// </exception>
 public MCP4641(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
                MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode)
     : base(device, pinA0, pinA1, pinA2, channel, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM)
 {
 }
Example #5
0
 /// <summary>
 /// Sets the way in which non-volatile reads and writes are done.
 /// </summary>
 /// <param name="mode">
 /// The non-volatile mode.
 /// </param>
 new public void SetNonVolatileMode(MicrochipPotNonVolatileMode mode)
 {
     base.SetNonVolatileMode(mode);
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4561"/>
 /// class with the I2C device that is the connection to MCP4561,
 /// whether the address pin A0 is high or not, and the way to
 /// handle non-volatile I/O.
 /// </summary>
 /// <param name="device">
 /// The I2C bus device this instance is connected to.
 /// </param>
 /// <param name="pinA0">
 /// Whether the device's address pin A0 is high (true) or low (false).
 /// </param>
 /// <param name="nonVolatileMode">
 /// The way non-volatile reads or writes are done.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="device"/> cannot be null.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// Unable to open the I2C bus.
 /// </exception>
 public MCP4561(II2CBus device, Boolean pinA0, MicrochipPotNonVolatileMode nonVolatileMode)
     : base(device, pinA0, PIN_NOT_AVAILABLE, PIN_NOT_AVAILABLE,
            MicrochipPotChannel.A, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM)
 {
 }
		/// <summary>
		/// Sets the non-volatility mode.
		/// </summary>
		/// <param name="mode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <remarks>
		/// The visibility of this method is protected because not all
		/// devices support non-volatile wipers. Any derived class may
		/// publish this method.
		/// </remarks>
		/// <exception cref="InvalidOperationException">
		/// This device is not capable of non-volatile wipers.
		/// </exception>
		protected void SetNonVolatileMode(MicrochipPotNonVolatileMode mode) {
			if ((!this.IsNonVolatileWiperCapable) &&
				(this._nonVolMode != MicrochipPotNonVolatileMode.VolatileOnly)) {
				throw new InvalidOperationException("This device is not capable of non-volatile wipers." +
													" You *must* use MicrochipPotNonVolatileMode.VolatileOnly.");
			}
			this._nonVolMode = mode;
		}
		/// <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.Potentiometers.Microchip.MicrochipPotentiometerBase"/>. The
		/// <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> in an unusable
		/// state. After calling <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> so the garbage
		/// collector can reclaim the memory that the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/> was occupying.
		/// </remarks>
		public override void Dispose() {
			if (base.IsDisposed) {
				return;
			}

			if (this._controller != null) {
				this._controller.Dispose();
				this._controller = null;
			}

			this._currentValue = -1;
			this._channel = MicrochipPotChannel.None;
			this._nonVolMode = MicrochipPotNonVolatileMode.VolatileAndNonVolatile;
			base.Dispose();
		}
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MicrochipPotentiometerBase"/>
		/// class with the I2C device connection, pin A0,A1, and A2 states,
		/// the potentiometer (channel) provided by the device, how to do
		/// non-volatile I/O and the initial value for devices which are not
		/// capable of non-volatile wipers.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="pinA2">
		/// Whether the device's address pin A2 is high (true) or low (false).
		/// </param>
		/// <param name="channel">
		/// Which of the potentiometers provided by the device to control.
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <param name="initialNonVolWiperValue">
		/// The value for devices which are not capable of non-volatile wipers.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
		/// cannot be null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="channel"/> is not supported by this device.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		protected MicrochipPotentiometerBase(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
			MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode, Int32 initialNonVolWiperValue)
			: base() {
			if (device == null) {
				throw new ArgumentNullException("device");
			}
				
			if (!this.IsChannelSupported(channel)) {
				throw new ArgumentException("Specified channel not supported by device.", "channel");
			}
				
			this._channel = channel;
			this._nonVolMode = nonVolatileMode;
			Int32 deviceAddr = BuildI2CAddress(pinA0, pinA1, pinA2);
			this._controller = new MicrochipPotDeviceController(device, deviceAddr);
			this.WiperActionEvent += this.MicrochipPotentiometerBase_WiperActionEvent;
			this.Initialize(initialNonVolWiperValue);
		}
Example #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4541"/>
		/// class with the I2C device that is the connection to MCP4541,
		/// whether the address pin A0 is high or not, and the way to
		/// handle non-volatile I/O.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4541(II2CBus device, Boolean pinA0, MicrochipPotNonVolatileMode nonVolatileMode)
			: base(device, pinA0, PIN_NOT_AVAILABLE, PIN_NOT_AVAILABLE,
				MicrochipPotChannel.A, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM) {
		}
Example #11
0
		/// <summary>
		/// Sets the way in which non-volatile reads and writes are done.
		/// </summary>
		/// <param name="mode">
		/// The non-volatile mode.
		/// </param>
		new public void SetNonVolatileMode(MicrochipPotNonVolatileMode mode) {
			base.SetNonVolatileMode(mode);
		}
Example #12
0
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Potentiometers.Microchip.MCP4661"/>
		/// class with the I2C device connection, pin A0, A1, and A2 states,
		/// the potentiometer (channel) provided by the device, and how to
		/// do non-volatile I/O.
		/// </summary>
		/// <param name="device">
		/// The I2C bus device this instance is connected to.
		/// </param>
		/// <param name="pinA0">
		/// Whether the device's address pin A0 is high (true) or low (false).
		/// </param>
		/// <param name="pinA1">
		/// Whether the device's address pin A1 is high (true) or low (false).
		/// </param>
		/// <param name="pinA2">
		/// Whether the device's address pin A2 is high (true) or low (false).
		/// </param>
		/// <param name="channel">
		/// Which of the potentiometers provided by the device to control.
		/// </param>
		/// <param name="nonVolatileMode">
		/// The way non-volatile reads or writes are done.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="device"/> cannot be null. - or - <paramref name="channel"/>
		/// cannot be null.
		/// </exception>
		/// <exception cref="ArgumentException">
		/// <paramref name="channel"/> is not supported by this device.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// Unable to open the I2C bus.
		/// </exception>
		public MCP4661(II2CBus device, Boolean pinA0, Boolean pinA1, Boolean pinA2,
						MicrochipPotChannel channel, MicrochipPotNonVolatileMode nonVolatileMode)
			: base(device, pinA0, pinA1, pinA2, channel, nonVolatileMode, INITIALVALUE_LOADED_FROM_EEPROM) {
		}