/// <summary>
        /// Stops the hardware ISR callbacks.
        /// </summary>
        public void Stop()
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                BoardException.ValidateResult(
                    IO.GpioSetIsrFunc(Pin.PinGpio, 0, 0, null));
                Callback = null;
            }
        }
        public void RegisterPinInterruptCallback(int pin, Action <int, LevelChange, uint> callback, EdgeDetection edgeDetection)
        {
            var gpio = (SystemGpio)pin;

            PiGpioIsrDelegate cb = new PiGpioIsrDelegate((gpioPin, levelChange, time) =>
            {
                callback((int)gpioPin, levelChange, time);
            });

            Pi.IO.GpioSetIsrFunc(gpio, edgeDetection, 0, cb);
        }
        /// <summary>
        /// Starts the hardware ISR callbacks.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="edgeDetection">The edge detection.</param>
        /// <param name="timeoutMilliseconds">The timeout milliseconds.</param>
        /// <exception cref="ArgumentNullException">callback - Use Stop first.</exception>
        /// <exception cref="ArgumentException">A callback is already registered. Clear the current callback before registering a new one. - callback</exception>
        public void Start(PiGpioIsrDelegate callback, EdgeDetection edgeDetection, int timeoutMilliseconds)
        {
            ValidateAvailable();

            if (callback == null)
                throw new ArgumentNullException(nameof(callback), $"The callback cannot be null. Use the '{nameof(Stop)}' method instead.");

            lock (SyncLock)
            {
                if (Callback != null)
                    throw new ArgumentException("A callback is already registered. Clear the current callback before registering a new one.", nameof(callback));

                BoardException.ValidateResult(
                    IO.GpioSetIsrFunc(Pin.PinGpio, edgeDetection, timeoutMilliseconds, callback));

                m_EdgeDetection = edgeDetection;
                m_TimeoutMilliseconds = timeoutMilliseconds;
                Callback = callback;
            }
        }
 /// <summary>
 /// Starts the hardware ISR callbacks.
 /// </summary>
 /// <param name="callback">The callback.</param>
 /// <exception cref="NotSupportedException">IsUserGpio is false</exception>
 /// <exception cref="ArgumentNullException">callback - ClearAlertCallback</exception>
 /// <exception cref="ArgumentException">A callback is already registered. Clear the current callback before registering a new one. - callback</exception>
 public void Start(PiGpioIsrDelegate callback)
 {
     Start(callback, EdgeDetection, TimeoutMilliseconds);
 }
예제 #5
0
 public static extern ResultCode GpioSetIsrFunc(SystemGpio gpio, EdgeDetection edge, int timeout, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioIsrDelegate callback);