コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23008OutputBinaryPin"/> 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 Mcp23008OutputBinaryPin(Mcp23008I2cConnection connection, Mcp23008Pin pin,
                                       Mcp23008PinResistor resistor = Mcp23008PinResistor.None,
                                       Mcp23008PinPolarity polarity = Mcp23008PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin        = pin;

            connection.SetDirection(pin, Mcp23008PinDirection.Output);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23008InputBinaryPin"/> 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 Mcp23008InputBinaryPin(Mcp23008I2cConnection connection, Mcp23008Pin pin,
            Mcp23008PinResistor resistor = Mcp23008PinResistor.None,
            Mcp23008PinPolarity polarity = Mcp23008PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetDirection(pin, Mcp23008PinDirection.Input);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
コード例 #3
0
        /// <summary>
        /// Sets the polarity.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="polarity">The polarity.</param>
        public void SetPolarity(Mcp23008Pin pin, Mcp23008PinPolarity polarity)
        {
            var register = Register.IPOL;

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

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

            connection.Write(new[] { (byte)register, (byte)newPolarities });
        }
コード例 #4
0
        /// <summary>
        /// Sets the polarity.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="polarity">The polarity.</param>
        public void SetPolarity(Mcp23008Pin pin, Mcp23008PinPolarity polarity)
        {
            var register = Register.Ipol;

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

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

            this.connection.Write((byte)register, (byte)newPolarities);
        }
コード例 #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 pin.</returns>
 public static Mcp23008InputBinaryPin In(this Mcp23008I2cConnection connection, Mcp23008Pin pin, Mcp23008PinResistor resistor = Mcp23008PinResistor.None, Mcp23008PinPolarity polarity = Mcp23008PinPolarity.Normal)
 {
     return(new Mcp23008InputBinaryPin(connection, pin, resistor, polarity));
 }
コード例 #6
0
 /// <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 Mcp23008OutputBinaryPin Out(this Mcp23008I2cConnection connection, Mcp23008Pin pin, Mcp23008PinResistor resistor = Mcp23008PinResistor.None, Mcp23008PinPolarity polarity = Mcp23008PinPolarity.Normal)
 {
     return new Mcp23008OutputBinaryPin(connection, pin, resistor, polarity);
 }
コード例 #7
0
 /// <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 output pin.</returns>
 public static Mcp23008OutputBinaryPin Out(this Mcp23008Device connection, Mcp23008Pin pin, Mcp23008PinResistor resistor = Mcp23008PinResistor.None, Mcp23008PinPolarity polarity = Mcp23008PinPolarity.Normal)
 {
     return(new Mcp23008OutputBinaryPin(connection, pin, resistor, polarity));
 }