예제 #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 ?
        }
예제 #2
0
        private void Unexport(int pin)
        {
            if (!IsExported(pin))
            {
                return;
            }

            PosixUtils.Echo(unexportWriter, pin.ToString());
        }
예제 #3
0
        private void OutputGpio(Pin pin, HighLow value, long duration = -1)
        {
            PosixUtils.Echo(pin.ValueWriter, value == HighLow.High ? "1" : "0");

            if (duration != -1)
            {
                operatingSystemService.NanoSleep(duration);
            }
        }