Esempio n. 1
0
        public static void TestGpio()
        {
            var pin11 = new OutputGpioPin(GpioPinNumber.Gpio11);
            var pin2  = new OutputGpioPin(GpioPinNumber.Gpio17);

            var pin4 = new InputGpioPin(GpioPinNumber.Gpio4);

            pin4.Read();

            Console.WriteLine("Press ESC to stop");

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                pin11.Write(State.Low);
                Console.WriteLine("Pin 11 : " + pin11.State);
                pin2.Write(State.High);
                Console.WriteLine("Pin 2 : " + pin2.State);
                Thread.Sleep(750);
                pin11.Write(State.High);
                Console.WriteLine("Pin 11 : " + pin11.State);
                pin2.Write(State.Low);
                Console.WriteLine("Pin 2 : " + pin2.State);
                Thread.Sleep(750);
            }


            pin11.Cleanup();
            pin2.Cleanup();
        }
        /// <summary>
        /// Set up the SPI device and the controller for the transfer ready pin
        /// </summary>
        public static void Init()
        {
            // Initialize TX header. This only needs to happen once
            Serialization.Writer.InitTransferHeader(ref _txHeader);

            // Initialize transfer ready pin
            _transferReadyPin             = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin);
            _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set();
            _transferReadyPin.StartMonitoring(Program.CancelSource.Token);

            // Initialize SPI device
            _spiDevice = new SpiDevice(Settings.SpiDevice, Settings.SpiFrequency);

            // Check if large transfers can be performed
            try
            {
                int maxSpiBufferSize = int.Parse(File.ReadAllText("/sys/module/spidev/parameters/bufsiz"));
                if (maxSpiBufferSize < Communication.Consts.BufferSize)
                {
                    Console.WriteLine($"[warn] Kernel SPI buffer size is smaller than RepRapFirmware buffer size ({maxSpiBufferSize} configured vs {Communication.Consts.BufferSize} required)");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[warn] Failed to retrieve Kernel SPI buffer size:");
                Console.WriteLine(e);
            }
        }
        /// <summary>
        /// Set up the SPI device and the controller for the transfer ready pin
        /// </summary>
        public static void Init()
        {
            // Initialize TX header. This only needs to happen once
            Serialization.Writer.InitTransferHeader(ref _txHeader);

            // Initialize TX buffers
            for (int i = 0; i < NumTxBuffers; i++)
            {
                _txBuffers.AddLast(new byte[Communication.Consts.BufferSize]);
            }
            _txBuffer = _txBuffers.First;

            // Initialize transfer ready pin
            _transferReadyPin             = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin, $"dcs-trp-{Settings.TransferReadyPin}");
            _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set();
            _ = _transferReadyPin.StartMonitoring(Program.CancelSource.Token);

            // Initialize SPI device
            _spiDevice = new SpiDevice(Settings.SpiDevice, Settings.SpiFrequency);

            // Check if large transfers can be performed
            try
            {
                int maxSpiBufferSize = int.Parse(File.ReadAllText("/sys/module/spidev/parameters/bufsiz"));
                if (maxSpiBufferSize < Communication.Consts.BufferSize)
                {
                    _logger.Warn("Kernel SPI buffer size is smaller than RepRapFirmware buffer size ({0} configured vs {1} required)", maxSpiBufferSize, Communication.Consts.BufferSize);
                }
            }
            catch (Exception e)
            {
                _logger.Warn(e, "Failed to retrieve Kernel SPI buffer size");
            }
        }
        /// <summary>
        /// Set up the SPI device and the controller for the transfer ready pin
        /// </summary>
        public static void Initialize()
        {
            // Initialize TX header. This only needs to happen once
            Serialization.Writer.InitTransferHeader(ref _txHeader);

            // Initialize transfer ready pin
            _transferReadyPin             = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin);
            _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set();
            _transferReadyPin.StartMonitoring(Program.CancelSource.Token);

            // Initialize SPI device
            _spiDevice = new SpiDevice($"/dev/spidev{Settings.SpiBusID}.{Settings.SpiChipSelectLine}", Settings.SpiFrequency);
        }
Esempio n. 5
0
 public PirSensor(int inputPinNo = 26)
 {
     inputPin = new InputGpioPin((GpioPinNumber)inputPinNo);
     Thread.Sleep(2000);
 }
Esempio n. 6
0
 public UltraSonicDistanceSensor(int inputPinNo = 16, int OutputPinNo = 12)
 {
     OutputGpioPin OutputPin = new OutputGpioPin((GpioPinNumber)OutputPinNo);
     InputGpioPin  inputPin  = new InputGpioPin((GpioPinNumber)inputPinNo);
 }