/// <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 polarity.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="polarity">The polarity.</param>
        public void SetPolarity(Mcp23017Pin pin, Mcp23017PinPolarity polarity)
        {
            var register = ((int)pin & 0x0100) == 0x0000 ? Register.IPOLA : Register.IPOLB;

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

            var bit           = (byte)((int)pin & 0xFF);
            var newPolarities = (polarity == Mcp23017PinPolarity.Inverted)
                                    ? polarities | bit
                                    : polarities & ~bit;

            connection.Write(new[] { (byte)register, (byte)newPolarities });
        }
        public void SetPolarity(Mcp23017Pin pin, Mcp23017PinPolarity polarity)
        {
            var register = ((int)pin & 0x0100) == 0x0000 ? Register.IPOLA : Register.IPOLB;

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

            var bit = (byte)((int)pin & 0xFF);
            var newPolarities = (polarity == Mcp23017PinPolarity.Inverted)
                                    ? polarities | bit
                                    : polarities & ~bit;

            connection.Write(new[] { (byte)register, (byte)newPolarities });
        }
Example #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);
 }