private double PulseIn(int pin_number, PinValue value, int timeout) { sw.Restart(); // Wait for pulse while (sw.ElapsedMilliseconds < timeout && _gpio.Read(pin_number) != value) { } if (sw.ElapsedMilliseconds >= timeout) { sw.Stop(); return(0); } sw.Restart(); // Wait for pulse end while (sw.ElapsedMilliseconds < timeout && _gpio.Read(pin_number) == value) { } sw.Stop(); return(sw.ElapsedMilliseconds < timeout ? sw.Elapsed.TotalMilliseconds : 0); }
protected PinValue InternalReadInterrupt(Port port) { int pinNumber; switch (port) { case Port.PortA: pinNumber = _interruptA; break; case Port.PortB: pinNumber = _interruptB; break; default: throw new ArgumentOutOfRangeException(nameof(port)); } if (pinNumber == -1) { throw new ArgumentException("No interrupt pin configured.", nameof(port)); } return(_masterGpioController.Read(pinNumber)); }
private async Task <bool> Read(int pinNumber) { try { await _semaphore.WaitAsync(); if (_initialized) { return(_gpioController.Read(pinNumber) == PinValue.Low); } return(false); } finally { _semaphore.Release(); } }
public PinValue Read(int pinNumber) { return(_controller.Read(pinNumber)); }