Exemple #1
0
        /// <summary>
        /// Write a series of bytes to the I2cDevice connected to the Seesaw board.
        /// </summary>
        /// <param name="moduleAddress">An Seesaw_Module enum that represents the module that we are writing to.</param>
        /// <param name="functionAddress">An Seesaw_Function enum that represents the Seesaw function to be called.</param>
        /// <param name="data">The Span containg data to be send as a parameter or parameters to the Seesaw device.</param>
        protected void Write(SeesawModule moduleAddress, SeesawFunction functionAddress, ReadOnlySpan<byte> data)
        {
            const int StackThreshold = 512;

            Span<byte> buffer = data.Length < StackThreshold ? stackalloc byte[data.Length + 2] : new byte[data.Length + 2];

            buffer[0] = (byte)moduleAddress;
            buffer[1] = (byte)functionAddress;
            data.CopyTo(buffer.Slice(2));

            I2cDevice.Write(buffer);
        }
Exemple #2
0
        /// <summary>
        /// Read a byte array from the I2cDevice connected to the Seesaw board.
        /// </summary>
        /// <param name="moduleAddress">A Seesaw_Module enum that represents the module that we are reading from.</param>
        /// <param name="functionAddress">A Seesaw_Function enum that represents the Seesaw function to be called.</param>
        /// <param name="length">The number of bytes that are expected to be returned from the Seesaw device.</param>
        /// <param name="readDelayMicroSeconds">The delay between sending the function and readinng the data in microseconds.</param>
        /// <returns>Returns the byte array representaing values from the Seesaw device.</returns>
        protected byte[] Read(SeesawModule moduleAddress, SeesawFunction functionAddress, int length, short readDelayMicroSeconds = 0)
        {
            byte[] retval = new byte[length];

            Span <byte> bytesToWrite = stackalloc byte[2] {
                (byte)moduleAddress, (byte)functionAddress
            };

            I2cDevice.Write(bytesToWrite);

            if (readDelayMicroSeconds > 0)
            {
                DelayHelper.DelayMicroseconds(readDelayMicroSeconds, true);
            }

            I2cDevice.Read(retval);

            return(retval);
        }
Exemple #3
0
 /// <summary>
 /// Read a byte from the I2cDevice connected to the Seesaw board.
 /// </summary>
 /// <param name="moduleAddress">A Seesaw_Module enum that represents the module that we are reading from.</param>
 /// <param name="functionAddress">A Seesaw_Function enum that represents the Seesaw function to be called.</param>
 /// <param name="readDelayMicroSeconds">The delay between sending the function and readinng the data in microseconds.</param>
 /// <returns>Returns the byte value from the Seesaw device.</returns>
 protected byte ReadByte(SeesawModule moduleAddress, SeesawFunction functionAddress, short readDelayMicroSeconds = 0) => Read(moduleAddress, functionAddress, 1, readDelayMicroSeconds)[0];
Exemple #4
0
 /// <summary>
 /// Write a byte to the I2cDevice connected to the Seesaw board.
 /// </summary>
 /// <param name="moduleAddress">An Seesaw_Module enum that represents the module that we are writing to.</param>
 /// <param name="functionAddress">An Seesaw_Function enum that represents the Seesaw function to be called.</param>
 /// <param name="value">The byte value ro be send as a parameter to the Seesaw device.</param>
 protected void WriteByte(SeesawModule moduleAddress, SeesawFunction functionAddress, byte value)
 {
     Write(moduleAddress, functionAddress, new byte[] { value });
 }