示例#1
0
        /// <summary>
        /// Reads the current value of the <see cref="Pca9685Register.Mode2"/> register.
        /// </summary>
        /// <returns>Bit flags corresponding to the actual mode byte.</returns>
        public Pca9685Mode2Bits ReadMode2()
        {
            // Read register
            var value = (Pca9685Mode2Bits)I2cExtensions.WriteReadByte(_hardware, (byte)Pca9685Register.Mode2);

            // Update property
            Mode2Register = value;

            // Return result
            return(value);
        }
示例#2
0
        /// <summary>
        /// Reads a single byte "randomly" at the specified address.
        /// </summary>
        public byte ReadByte(int address)
        {
            // Validate
            if (address < 0 || address > Size - 1)
            {
                throw new ArgumentOutOfRangeException(nameof(address));
            }

            // Get correct I2C device and data for memory address and flags
            var device       = GetI2cDeviceForMemoryAddress(address);
            var addressBytes = GetMemoryAddressBytes(address);

            // Read and return data
            return(I2cExtensions.WriteReadByte(device, addressBytes));
        }
示例#3
0
        /// <summary>
        /// Reads the prescale register and calculates the <see cref="Frequency"/> (and related properties)
        /// based on <see cref="ClockSpeed"/>.
        /// </summary>
        /// <returns>
        /// Frequency in Hz. Related properties are also updated.
        /// </returns>
        public int ReadFrequency()
        {
            // Read prescale register
            var prescale = I2cExtensions.WriteReadByte(_hardware, (byte)Pca9685Register.Prescale);

            // Calculate frequency
            var frequency = CalculateFrequency(prescale, ClockSpeed);

            // Update related properties
            Frequency    = frequency;
            PwmMsMinimum = Pca9685ChannelValue.CalculateWidthMs(frequency, 0);
            PwmMsMaximum = Pca9685ChannelValue.CalculateWidthMs(frequency, Pca9685ChannelValue.Maximum);

            // Return result
            return(frequency);
        }