/// <summary>
        /// Updates the display when the <see cref="Device"/> channels change.
        /// </summary>
        private void OnChannelsChanged(object sender, PwmFrame frame)
        {
            // Dump statistics to output
            WriteOutput(frame.ToString());

            // Update display
            DoPropertyChanged(nameof(Device));
        }
Example #2
0
        /// <summary>
        /// Decodes the incoming PWM signal (each complete cycle) using the CPPM protocol.
        /// </summary>
        /// <param name="cycle">PWM cycle to decode.</param>
        /// <returns>
        /// <see cref="PwmFrame"/> when complete else null whilst decoding or skipping invalid cycles.
        /// </returns>
        private PwmFrame Decode(PwmCycle cycle)
        {
            // Validate
            // TODO: This dirty filter is necessary because the user mode GPIO updates are erratic and have too much latency.
            // There appears to be a problem with the Microsoft IoT build and GPIO4 and/or changing drive modes.
            // In fact the Navio pin 4 is not officially supported right now!!!
            if (cycle.LowLength >= PwmLowLimit || cycle.HighLength <= PwmLowLimit)
            {
                // Discard frame
                _channel = null;
                return(null);
            }

            // Detect start frame
            if (cycle.HighLength >= PwmSyncLengthMinium)
            {
                // Start decoding from channel 0 at next pulse
                _channel = 0;
                _frame   = new PwmFrame(cycle.LowTime, new int[ChannelCount]);
                return(null);
            }

            // Do nothing when not decoding
            if (!_channel.HasValue)
            {
                return(null);
            }
            var decodeIndex = _channel.Value;

            // Store channel value whilst decoding
            if (decodeIndex < ChannelCount)
            {
                // Store channel value
                _frame.Channels[decodeIndex] = (int)cycle.Length;

                // Wait for next channel...
                _channel = decodeIndex + 1;

                // Complete frame when all channels decoded...
                if (decodeIndex == ChannelCount - 1)
                {
                    var frame = _frame;
                    _frame = null;
                    return(frame);
                }
            }

            // Continue...
            return(null);
        }
 /// <summary>
 /// Receives updates when new PWM frames arrive.
 /// </summary>
 private void OnChannelsChanged(object sender, PwmFrame frame)
 {
     // Write contents to the debug output
     Debug.WriteLine(frame);
 }
        /// <summary>
        /// Decodes the incoming PWM signal (each complete cycle) using the CPPM protocol.
        /// </summary>
        /// <param name="cycle">PWM cycle to decode.</param>
        /// <returns>
        /// <see cref="PwmFrame"/> when complete else null whilst decoding or skipping invalid cycles.
        /// </returns>
        private PwmFrame Decode(PwmCycle cycle)
        {
            // Validate
            // TODO: This dirty filter is necessary because the user mode GPIO updates are erratic and have too much latency.
            // There appears to be a problem with the Microsoft IoT build and GPIO4 and/or changing drive modes.
            // In fact the Navio pin 4 is not officially supported right now!!!
            if (cycle.LowLength >= PwmLowLimit || cycle.HighLength <= PwmLowLimit)
            {
                // Discard frame
                _channel = null;
                return null;
            }

            // Detect start frame
            if (cycle.HighLength >= PwmSyncLengthMinium)
            {
                // Start decoding from channel 0 at next pulse
                _channel = 0;
                _frame = new PwmFrame(cycle.LowTime, new int[ChannelCount]);
                return null;
            }

            // Do nothing when not decoding
            if (!_channel.HasValue)
                return null;
            var decodeIndex = _channel.Value;

            // Store channel value whilst decoding
            if (decodeIndex < ChannelCount)
            {
                // Store channel value
                _frame.Channels[decodeIndex] = (int)cycle.Length;

                // Wait for next channel...
                _channel = decodeIndex + 1;

                // Complete frame when all channels decoded...
                if (decodeIndex == ChannelCount - 1)
                {
                    var frame = _frame;
                    _frame = null;
                    return frame;
                }
            }

            // Continue...
            return null;
        }