/// <summary>
        /// Drives the specified value onto the general purpose I/O (GPIO) pin according to the current drive mode for the pin
        /// if the pin is configured as an output, or updates the latched output value for the pin if the pin is configured as an input.
        /// </summary>
        /// <param name="value">The enumeration value to write to the GPIO pin.
        /// <para>If the GPIO pin is configured as an output, the method drives the specified value onto the pin according to the current drive mode for the pin.</para>
        /// <para>If the GPIO pin is configured as an input, the method updates the latched output value for the pin. The latched output value is driven onto the pin when the configuration for the pin changes to output.</para>
        /// </param>
        /// <remarks>The following exceptions can be thrown by this method:
        /// <list type="bullet">
        /// <item><term>E_ACCESSDENIED : The GPIO pin is open in shared read-only mode. To write to the pin, close the pin and reopen the pin in exclusive mode.</term></item>
        /// </list>
        /// </remarks>
        public void Write(GpioPinValue value)
        {
            lock (_syncLock)
            {
                // check if pin has been disposed
                if (_disposedValue)
                {
                    throw new ObjectDisposedException();
                }

                if (_lastOutputValue != value)
                {
                    // value has changed
                    // native write
                    WriteNative(value);

                    // trigger the pin value changed event, if any is set
                    GpioPinValueChangedEventHandler callbacks = _callbacks;

                    if (_lastOutputValue == GpioPinValue.Low)
                    {
                        // last value is now LOW, so it was HIGH
                        callbacks?.Invoke(this, new GpioPinValueChangedEventArgs(GpioPinEdge.FallingEdge));
                    }
                    else
                    {
                        // last value is now HIGH, so it was LOW
                        callbacks?.Invoke(this, new GpioPinValueChangedEventArgs(GpioPinEdge.RisingEdge));
                    }
                }
            }
        }
        /// <summary>
        /// Handles internal events and re-dispatches them to the publicly subscribed delegates.
        /// </summary>
        /// <param name="edge">The state transition for this event.</param>
        internal void OnPinChangedInternal(GpioPinEdge edge)
        {
            GpioPinValueChangedEventHandler callbacks = null;

            lock (_syncLock)
            {
                if (!_disposedValue)
                {
                    callbacks = _callbacks;
                }
            }

            callbacks?.Invoke(this, new GpioPinValueChangedEventArgs(edge));
        }
示例#3
0
        /// <summary>
        /// Handles internal events and re-dispatches them to the publicly subsribed delegates.
        /// </summary>
        /// <param name="edge">The state transition for this event.</param>
        internal void OnPinChangedInternal(GpioPinEdge edge)
        {
            GpioPinValueChangedEventHandler callbacks = null;

            lock (m_syncLock)
            {
                if (!m_disposed)
                {
                    callbacks = m_callbacks;
                }
            }

            if (callbacks != null)
            {
                callbacks(this, new GpioPinValueChangedEventArgs(edge));
            }
        }