Example #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it.
        /// </summary>
        /// <param name="connection">A open SPI connection</param>
        /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param>
        /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param>
        public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices)
        {
            if (ReferenceEquals(connection, null))
            {
                throw new ArgumentNullException("connection");
            }

            if (numberOfDevices <= 0)
            {
                throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device.");
            }

            this.connection = connection;

            if (initializeWithDefault)
            {
                connection.SetBitsPerWord(BITS_PER_WORD);
                connection.SetSpiMode(SPI_MODE_0);
                connection.SetMaxSpeed(SPEED);
                connection.SetDelay(DELAY);
            }

            var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE;

            transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write);

            deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it.
        /// </summary>
        /// <param name="connection">A open SPI connection</param>
        /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param>
        /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param>
        public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) {
            if (ReferenceEquals(connection, null))
                throw new ArgumentNullException("connection");

            if (numberOfDevices <= 0)
                throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device.");

            this.connection = connection;
            
            if (initializeWithDefault) {
                connection.SetBitsPerWord(BITS_PER_WORD);
                connection.SetSpiMode(SPI_MODE_0);
                connection.SetMaxSpeed(SPEED);
                connection.SetDelay(DELAY);
            }

            var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE;
            transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write);

            deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices);
        }