/// <summary> /// Sets pin value. /// </summary> public void Write(GpioPinValue value) { var ret = NativeGpio.Write(_handle, value == GpioPinValue.High ? 1 : (uint)0); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } }
private void SetIntteruptedCallback() { _interruptedEventCallback = OnInterrupted; var ret = NativeGpio.SetInterruptedCb(_handle, _interruptedEventCallback, IntPtr.Zero); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } }
/// <summary> /// Gets pin value. /// </summary> /// <returns>Pin value</returns> public GpioPinValue Read() { var ret = NativeGpio.Read(_handle, out uint value); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } return(value == 1 ? GpioPinValue.High : GpioPinValue.Low); }
/// <summary> /// Disposes GPIO. /// </summary> protected virtual void Dispose(bool disposing) { if (_disposed) { return; } NativeGpio.UnsetInterruptedCb(_handle); NativeGpio.Close(_handle); _disposed = true; }
/// <summary> /// Opens a GPIO pin. /// </summary> /// <param name="pinNumber">The GPIO pin number.</param> /// <param name="mode">GPIO direction.</param> public GpioPin(int pinNumber, GpioPinDriveMode mode) { var ret = NativeGpio.Open(pinNumber, out _handle); try { if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } PinNumber = pinNumber; switch (mode) { case GpioPinDriveMode.Input: ret = NativeGpio.SetEdgeMode(_handle, NativeGpio.EdgeType.Both); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } ret = NativeGpio.SetDirection(_handle, NativeGpio.Direction.In); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } SetIntteruptedCallback(); break; case GpioPinDriveMode.OutputInitiallyLow: ret = NativeGpio.SetDirection(_handle, NativeGpio.Direction.OutLow); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } break; case GpioPinDriveMode.OutputInitiallyHigh: ret = NativeGpio.SetDirection(_handle, NativeGpio.Direction.OutHigh); if (ret != ErrorCode.None) { throw ExceptionFactory.CreateException(ret); } break; } } catch (Exception err) { Dispose(); throw; } }