Esempio n. 1
0
        /// <summary>
        /// Reads the PWM channels from the device then updates the related properties.
        /// </summary>
        void INavioPwmDevice.Read()
        {
            // Thread-safe lock
            lock (_lock)
            {
                // Read channels together (BGR ordered)
                var channels = _device.ReadChannels(PwmChannelIndex, PwmChannelCount);

                // Update channel properties
                var frequency = _device.Frequency;
                for (int index = 0; index < PwmChannelCount; index++)
                {
                    var widthTicks = channels[index].Width;
                    var widthMs    = Pca9685ChannelValue.CalculateWidthMs(frequency, widthTicks);
                    _pwmChannels[index] = PwmPulse.FromWidth(frequency, widthMs);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the LED &amp; PWM channels from the device then updates the related properties.
        /// </summary>
        public void Read()
        {
            // Thread-safe lock
            lock (_lock)
            {
                // Read all PWM and LED channels
                _device.ReadAll();

                // Update LED properties
                _ledRed   = ~_device.Channels[LedRedChannelIndex].Width & 0xfff;
                _ledGreen = ~_device.Channels[LedGreenChannelIndex].Width & 0xfff;
                _ledBlue  = ~_device.Channels[LedGreenChannelIndex].Width & 0xfff;

                // Update PWM properties
                var frequency = _device.Frequency;
                for (int index = 0, pwmIndex = PwmChannelIndex; index < PwmChannelCount; index++, pwmIndex++)
                {
                    var widthTicks = _device.Channels[pwmIndex].Width;
                    var widthMs    = Pca9685ChannelValue.CalculateWidthMs(frequency, widthTicks);
                    _pwmChannels[index] = PwmPulse.FromWidth(frequency, widthMs);
                }
            }
        }