/// <summary>
        /// Initializes a new instance of the <see cref="Pcf8574InputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        public Pcf8574InputBinaryPin(Pcf8574I2cConnection connection, Pcf8574Pin pin)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetInputPin(pin, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Pcf8574OutputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        public Pcf8574OutputBinaryPin(Pcf8574I2cConnection connection, Pcf8574Pin pin)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetInputPin(pin, false);
        }
        private static Hd44780Configuration LoadPcf8574Configuration(IEnumerable<string> args)
        {
            var addressText = args.SkipWhile(s => !String.Equals(s, "pcf8574", StringComparison.InvariantCultureIgnoreCase)).Skip(1).DefaultIfEmpty("0x20").First();
            var address = addressText.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)
                ? Int32.Parse(addressText.Substring(2), NumberStyles.HexNumber)
                : Int32.Parse(addressText);

            const Pcf8574Pin clockPin = Pcf8574Pin.P2;
            const Pcf8574Pin readWritePin = Pcf8574Pin.P1;
            const Pcf8574Pin registerSelectPin = Pcf8574Pin.P0;
            const Pcf8574Pin backlightPin = Pcf8574Pin.P3;
            var dataPins = new[]
            {
                Pcf8574Pin.P4,
                Pcf8574Pin.P5,
                Pcf8574Pin.P6,
                Pcf8574Pin.P7
            };

            Console.WriteLine();
            Console.WriteLine("Using I2C connection over PCF8574 expander");
            Console.WriteLine("\tRegister Select: {0}", registerSelectPin);
            Console.WriteLine("\tClock: {0}", clockPin);
            Console.WriteLine("\tData 1: {0}", dataPins[0]);
            Console.WriteLine("\tData 2: {0}", dataPins[1]);
            Console.WriteLine("\tData 3: {0}", dataPins[2]);
            Console.WriteLine("\tData 4: {0}", dataPins[3]);
            Console.WriteLine("\tBacklight: {0}", backlightPin);
            Console.WriteLine("\tRead/write: {0}", readWritePin);
            Console.WriteLine();

            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()) { ClockDivider = 512 };
            var connection = new Pcf8574I2cConnection(driver.Connect(address));

            return new Hd44780Configuration(driver)
            {
                Pins = new Hd44780Pins(
                    connection.Out(registerSelectPin),
                    connection.Out(clockPin),
                    dataPins.Select(p => (IOutputBinaryPin)connection.Out(p)))
                {
                    Backlight = connection.Out(backlightPin),
                    ReadWrite = connection.Out(readWritePin),
                }
            };
        }