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
        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);
        }