/// <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; } }
/// <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; } }
public static extern ResultCode GpioSetAlertFunc(UserGpio userGpio, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioAlertDelegate callback);