public void Setup(int pin, Direction direction, PullUpDown pullUpDown) { Pin pinObj; if (pins.ContainsKey(pin)) { pinObj = pins[pin]; } else { pinObj = new Pin(); // export pin Export(pin); // create direction streams pinObj.DirectionStream = new FileStream(string.Format(GpioPinDirectionPath, pin), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); pinObj.DirectionWriter = new StreamWriter(pinObj.DirectionStream, Encoding.ASCII); pinObj.DirectionReader = new StreamReader(pinObj.DirectionStream, Encoding.ASCII); // create value streams pinObj.ValueStream = new FileStream(string.Format(GpioPinValuePath, pin), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); pinObj.ValueWriter = new StreamWriter(pinObj.ValueStream, Encoding.ASCII); pinObj.ValueReader = new StreamReader(pinObj.ValueStream, Encoding.ASCII); pins.Add(pin, pinObj); } // set pin direction PosixUtils.Echo(pinObj.DirectionWriter, direction == Direction.Input ? "in" : "out"); // TODO : and pull up down ? }
private static unsafe void SetPullUpDown(int *gpioMapPtr, int gpio, PullUpDown pud) { var clkOffset = PULLUPDNCLK_OFFSET + (gpio / 32); var shift = (gpio % 32); if (pud == PullUpDown.Down) { *(gpioMapPtr + PULLUPDN_OFFSET) = (*(gpioMapPtr + PULLUPDN_OFFSET) & ~3) | PUD_DOWN; } else if (pud == PullUpDown.Up) { *(gpioMapPtr + PULLUPDN_OFFSET) = (*(gpioMapPtr + PULLUPDN_OFFSET) & ~3) | PUD_UP; } else { *(gpioMapPtr + PULLUPDN_OFFSET) &= ~3; } Thread.SpinWait(150); *(gpioMapPtr + clkOffset) = 1 << shift; Thread.SpinWait(150); *(gpioMapPtr + PULLUPDN_OFFSET) &= ~3; *(gpioMapPtr + clkOffset) = 0; }
/// <inheritDoc /> public void SetPullUpDown(int gpio, PullUpDown pud) { short ret = PiGpioNativeMethods.SetPullUpDown((ushort)gpio, (ushort)pud); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <summary> /// http://abyz.co.uk/rpi/pigpio/pigs.html#PUD /// </summary> /// <param name="gpio"></param> /// <param name="pullUp"></param> public void SetPullUpDown(int gpio, PullUpDown pullUp) { Commands cmd = Commands.PUD; uint p1 = (uint)gpio; uint p2 = (uint)pullUp; int p3 = 0; byte[] extension = null; int res; byte[] resExtension; this.m_control.RunCommand(cmd, p1, p2, p3, extension, out res, out resExtension); }
public unsafe void Setup(int pin, Direction direction, PullUpDown pullUpDown) { var gpioMapPtr = (int *)gpioMap; var offset = FSEL_OFFSET + (pin / 10); var shift = (pin % 10) * 3; SetPullUpDown(gpioMapPtr, pin, pullUpDown); if (direction == Direction.Output) { *(gpioMapPtr + offset) = (*(gpioMapPtr + offset) & ~(7 << shift)) | (1 << shift); } else { *(gpioMapPtr + offset) = (*(gpioMapPtr + offset) & ~(7 << shift)); } }
public Task SetupAsync(int pin, Direction direction, PullUpDown pullUpDown) { throw new NotImplementedException(); }
public void Setup(int pin, Direction direction, PullUpDown pullUpDown) { textWriter.WriteLine("Setup pin {0} Direction {1} PullUpDown {2}", pin, direction, pullUpDown); }
public async Task SetupAsync(int pin, Direction direction, PullUpDown pullUpDown) { Setup(pin, direction, pullUpDown); }
void IPiGPIO.SetPullUpDown(int gpio, PullUpDown pud) { throw new NotImplementedException(); }
public void SetPullUpDown(int gpio, PullUpDown pud) { throw new NotImplementedException(); }