/// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017InputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017InputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
                                      Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
                                      Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin        = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Input);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017InputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017InputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
            Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
            Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Input);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
        /// <summary>
        /// Sets the resistor.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public void SetResistor(Mcp23017Pin pin, Mcp23017PinResistor resistor)
        {
            var register = ((int)pin & 0x0100) == 0x0000 ? Register.GPPUA : Register.GPPUB;

            connection.WriteByte((byte)register);
            var resistors = connection.ReadByte();

            var bit          = (byte)((int)pin & 0xFF);
            var newResistors = (resistor == Mcp23017PinResistor.PullUp)
                                   ? resistors | bit
                                   : resistors & ~bit;

            connection.Write(new[] { (byte)register, (byte)newResistors });
        }
        /// <summary>
        /// Sets the resistor.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public void SetResistor(Mcp23017Pin pin, Mcp23017PinResistor resistor)
        {
            var register = ((int) pin & 0x0100) == 0x0000 ? Register.GPPUA : Register.GPPUB;

            connection.WriteByte((byte) register);
            var resistors = connection.ReadByte();

            var bit = (byte) ((int) pin & 0xFF);
            var newResistors = (resistor == Mcp23017PinResistor.PullUp)
                                   ? resistors | bit
                                   : resistors & ~bit;

            connection.Write(new[] {(byte) register, (byte) newResistors});
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an input binary pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 /// <param name="polarity">The polarity.</param>
 /// <returns>The input pin.</returns>
 public static Mcp23017InputBinaryPin In(this Mcp23017Device connection, Mcp23017Pin pin, Mcp23017PinResistor resistor = Mcp23017PinResistor.None, Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
 {
     return(new Mcp23017InputBinaryPin(connection, pin, resistor, polarity));
 }
 /// <summary>
 /// Creates an output binary pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 /// <param name="polarity">The polarity.</param>
 /// <returns>The pin.</returns>
 public static Mcp23017OutputBinaryPin Out(this Mcp23017I2cConnection connection, Mcp23017Pin pin, Mcp23017PinResistor resistor = Mcp23017PinResistor.None, Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
 {
     return(new Mcp23017OutputBinaryPin(connection, pin, resistor, polarity));
 }
 /// <summary>
 /// Creates an input binary pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="pin">The pin.</param>
 /// <param name="resistor">The resistor.</param>
 /// <param name="polarity">The polarity.</param>
 /// <returns>The pin.</returns>
 public static Mcp23017InputBinaryPin In(this Mcp23017I2cConnection connection, Mcp23017Pin pin, Mcp23017PinResistor resistor = Mcp23017PinResistor.None, Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
 {
     return new Mcp23017InputBinaryPin(connection, pin, resistor, polarity);
 }