Exemplo n.º 1
0
        /// <summary>
        /// Clears the alert callback and stops reporting changes.
        /// </summary>
        /// <exception cref="NotSupportedException">IsUserGpio is false.</exception>
        public void Stop()
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                // TODO: For some reason passing NULL to cancel the alert makes everything hang!
                // This looks like a bug in the pigpio library.
                BoardException.ValidateResult(
                    IO.GpioSetAlertFunc((UserGpio)Pin.PinNumber, (g, l, t) => { }));
                Callback = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Start the alert 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(PiGpioAlertDelegate callback)
        {
            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.GpioSetAlertFunc((UserGpio)Pin.PinNumber, callback));
                Callback = callback;
            }
        }
Exemplo n.º 3
0
 public static extern ResultCode GpioSetAlertFunc(UserGpio userGpio, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioAlertDelegate callback);