Exemplo n.º 1
0
        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 ?
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        /// <inheritDoc />
        public void SetPullUpDown(int gpio, PullUpDown pud)
        {
            short ret = PiGpioNativeMethods.SetPullUpDown((ushort)gpio, (ushort)pud);

            if (ret < 0)
            {
                throw new PiGPIOException(ret);
            }
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        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));
            }
        }
Exemplo n.º 6
0
 public Task SetupAsync(int pin, Direction direction, PullUpDown pullUpDown)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public void Setup(int pin, Direction direction, PullUpDown pullUpDown)
 {
     textWriter.WriteLine("Setup pin {0} Direction {1} PullUpDown {2}", pin, direction, pullUpDown);
 }
Exemplo n.º 8
0
 public async Task SetupAsync(int pin, Direction direction, PullUpDown pullUpDown)
 {
     Setup(pin, direction, pullUpDown);
 }
Exemplo n.º 9
0
 void IPiGPIO.SetPullUpDown(int gpio, PullUpDown pud)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public void SetPullUpDown(int gpio, PullUpDown pud)
 {
     throw new NotImplementedException();
 }