public GpioInputPort(GpioPin pin, GpioInputMonitoringMode mode, GpioPullMode pullMode) { _pin = pin ?? throw new ArgumentNullException(nameof(pin)); if (pullMode == GpioPullMode.High) { _pin.SetDriveMode(GpioPinDriveMode.InputPullUp); } else if (pullMode == GpioPullMode.Low) { _pin.SetDriveMode(GpioPinDriveMode.InputPullDown); } else { _pin.SetDriveMode(GpioPinDriveMode.Input); } if (mode == GpioInputMonitoringMode.Polling) { ThreadPoolTimer.CreatePeriodicTimer(PollState, TimeSpan.FromMilliseconds(PollInterval)); } else if (mode == GpioInputMonitoringMode.Interrupt) { //_pin.DebounceTimeout = TimeSpan.FromTicks(DebounceTimeoutTicks); // TODO: Set from constructor. _pin.ValueChanged += HandleInterrupt; } _latestState = ReadAndConvert(); }
/// <summary> /// Initializes a new instance of the <see cref="GpioPin"/> class. /// </summary> /// <param name="gpio">The gpio.</param> internal GpioPin(SystemGpio gpio) { PinGpio = gpio; PinNumber = (int)gpio; IsUserGpio = gpio.GetIsUserGpio(Board.BoardType); PadId = Constants.GetPad(PinGpio); m_PullMode = Constants.GetDefaultPullMode(PinGpio); // Instantiate the pin services Alerts = new GpioPinAlertService(this); Interrupts = new GpioPinInterruptService(this); Servo = new GpioPinServoService(this); SoftPwm = new GpioPinSoftPwmService(this); Clock = new GpioPinClockService(this); Pwm = new GpioPinPwmService(this); }
public IBinaryInput GetInput(int number, GpioPullMode pullMode, GpioInputMonitoringMode monitoringMode) { GpioInputPort port; lock (_openInputPorts) { if (_openInputPorts.TryGetValue(number, out port)) { return(port); } var pin = _gpioController.OpenPin(number, GpioSharingMode.Exclusive); port = new GpioInputPort(pin, monitoringMode, pullMode); _openInputPorts.Add(number, port); } return(port); }
public static extern ResultCode GpioSetPullUpDown(SystemGpio gpio, GpioPullMode pullMode);