コード例 #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 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 });
        }
コード例 #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);
        }
コード例 #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));
 }