Exemplo n.º 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);
        }
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the resistor.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public void SetResistor(Mcp23008Pin pin, Mcp23008PinResistor resistor)
        {
            var register = Register.GPPU;

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

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

            connection.Write(new[] { (byte)register, (byte)newResistors });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the resistor.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public void SetResistor(Mcp23008Pin pin, Mcp23008PinResistor resistor)
        {
            var register = Register.Gppu;

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

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

            this.connection.Write((byte)register, (byte)newResistors);
        }
 /// <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));
 }
 /// <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);
 }
Exemplo n.º 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));
 }