Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public static extern ResultCode GpioSetPullUpDown(SystemGpio gpio, GpioPullMode pullMode);