/// <summary> /// Registers the interrupt callback on the pin. Pin mode has to be set to Input. /// /// </summary> /// <param name="edgeDetection">The edge detection.</param> /// <param name="callback">The callback.</param> /// <exception cref="System.ArgumentException">callback</exception> /// <exception cref="System.InvalidOperationException"> /// An interrupt callback was already registered. /// or /// RegisterInterruptCallback /// </exception> /// <exception cref="System.InvalidProgramException"></exception> public void RegisterInterruptCallback(EdgeDetection edgeDetection, InterrputServiceRoutineCallback callback) { if (callback == null) { throw new ArgumentException($"{nameof(callback)} cannot be null"); } if (InterruptCallback != null) { throw new InvalidOperationException("An interrupt callback was already registered."); } if (PinMode != GpioPinDriveMode.Input) { throw new InvalidOperationException($"Unable to {nameof(RegisterInterruptCallback)} for pin {PinNumber} because operating mode is {PinMode}." + $" Calling {nameof(RegisterInterruptCallback)} is only allowed if {nameof(PinMode)} is set to {GpioPinDriveMode.Input}"); } lock (_syncLock) { var registerResult = WiringPi.wiringPiISR(PinNumber, (int)edgeDetection, callback); if (registerResult == 0) { InterruptEdgeDetection = edgeDetection; InterruptCallback = callback; } else { HardwareException.Throw(nameof(GpioPin), nameof(RegisterInterruptCallback)); } } }
public static extern int wiringPiISR(int pin, int mode, InterrputServiceRoutineCallback method);