static void Main(string[] args)
        {
            Console.WriteLine("\n GPIO Interrupt Button and LED Test using libsimpleio\n");

            // Create GPIO pin objects

            IO.Interfaces.GPIO.Pin Button =
                new IO.Objects.libsimpleio.GPIO.Pin(0, 19,
                                                    IO.Interfaces.GPIO.Direction.Input, false,
                                                    IO.Objects.libsimpleio.GPIO.Pin.Driver.PushPull,
                                                    IO.Objects.libsimpleio.GPIO.Pin.Edge.Both);

            IO.Interfaces.GPIO.Pin LED =
                new IO.Objects.libsimpleio.GPIO.Pin(0, 26,
                                                    IO.Interfaces.GPIO.Direction.Output, false);

            // Main event loop

            for (;;)
            {
                if (Button.state)
                {
                    Console.WriteLine("PRESSED");
                    LED.state = true;
                }
                else
                {
                    Console.WriteLine("RELEASED");
                    LED.state = false;
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IO.Objects.libsimpleio.Device.Designator desg;

            Console.WriteLine("\nGPIO Pin Toggle Test\n");

            // Create GPIO pin object

            Console.Write("GPIO chip number?    ");
            desg.chip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO channel number? ");
            desg.chan = uint.Parse(Console.ReadLine());

            IO.Interfaces.GPIO.Pin Output =
                new IO.Objects.libsimpleio.GPIO.Pin(desg,
                                                    IO.Interfaces.GPIO.Direction.Output, false);

            // Toggle the GPIO output

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                Output.state = !Output.state;
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nGPIO Pin Toggle Test using libsimpleio\n");

            // Create GPIO pin object

            Console.Write("GPIO chip number? ");
            uint chip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO line number? ");
            uint line = uint.Parse(Console.ReadLine());

            IO.Interfaces.GPIO.Pin Output =
                new IO.Objects.libsimpleio.GPIO.Pin(chip, line,
                                                    IO.Interfaces.GPIO.Direction.Output, false);

            // Toggle the GPIO output

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                Output.state = !Output.state;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Constructor for a single SPI device.
        /// </summary>
        /// <param name="desg">SPI device designator.</param>
        /// <param name="mode">SPI clock mode.</param>
        /// <param name="wordsize">SPI transfer word size.</param>
        /// <param name="speed">SPI transfer speed.</param>
        /// <param name="cspin">SPI slave select GPIO pin number, or
        /// <c>AUTOCHIPSELECT</c>.</param>
        public Device(IO.Objects.libsimpleio.Device.Designator desg, int mode,
                      int wordsize, int speed,
                      IO.Objects.libsimpleio.GPIO.Pin cspin = AUTOCHIPSELECT)
        {
            // Validate the I2C bus designator

            if ((desg.chip == IO.Objects.libsimpleio.Device.Designator.Unavailable.chip) ||
                (desg.chan == IO.Objects.libsimpleio.Device.Designator.Unavailable.chan))
            {
                throw new Exception("Invalid designator");
            }

            System.String devname = System.String.Format("/dev/spidev{0}.{1}",
                                                         desg.chip, desg.chan);

            IO.Bindings.libsimpleio.SPI_open(devname, mode, wordsize,
                                             speed, out this.myfd, out int error);

            if (error != 0)
            {
                throw new Exception("SPI_open() failed, " +
                                    errno.strerror(error));
            }

            if (cspin == AUTOCHIPSELECT)
            {
                this.myfdcs = IO.Bindings.libsimpleio.SPI_AUTO_CS;
            }
            else
            {
                this.myfdcs = cspin.fd;
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test Using PWM (speed) and GPIO (direction) Outputs\n");

            IO.Objects.libsimpleio.Device.Designator desg_GPIO;

            Console.Write("GPIO chip number:    ");
            desg_GPIO.chip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO line number:    ");
            desg_GPIO.chan = uint.Parse(Console.ReadLine());

            IO.Objects.libsimpleio.Device.Designator desg_PWM;

            Console.Write("PWM chip:            ");
            desg_PWM.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg_PWM.chan = uint.Parse(Console.ReadLine());

            // Create GPIO pin object

            IO.Interfaces.GPIO.Pin GPIO0 =
                new IO.Objects.libsimpleio.GPIO.Pin(desg_GPIO,
                                                    IO.Interfaces.GPIO.Direction.Output);

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(desg_PWM, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(GPIO0, PWM0);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test using libsimpleio\n");

            Console.Write("GPIO chip number:    ");
            uint gpiochip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO line number:    ");
            uint gpioline = uint.Parse(Console.ReadLine());

            Console.Write("PWM chip:            ");
            int pwmchip = int.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            int pwmchan = int.Parse(Console.ReadLine());

            // Create GPIO pin object

            IO.Interfaces.GPIO.Pin GPIO0 =
                new IO.Objects.libsimpleio.GPIO.Pin(gpiochip, gpioline,
                                                    IO.Interfaces.GPIO.Direction.Output);

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(pwmchip, pwmchan, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(GPIO0, PWM0);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nGPIO Button and LED Test\n");

            // Create GPIO pin objects

            IO.Objects.libsimpleio.Device.Designator desg_Button =
                new IO.Objects.libsimpleio.Device.Designator(0, 6);

            IO.Interfaces.GPIO.Pin Button =
                new IO.Objects.libsimpleio.GPIO.Pin(desg_Button,
                                                    IO.Interfaces.GPIO.Direction.Input);

            IO.Objects.libsimpleio.Device.Designator desg_LED =
                new IO.Objects.libsimpleio.Device.Designator(0, 26);

            IO.Interfaces.GPIO.Pin LED =
                new IO.Objects.libsimpleio.GPIO.Pin(desg_LED,
                                                    IO.Interfaces.GPIO.Direction.Output, false);

            // Force initial state change

            bool ButtonOld = false;
            bool ButtonNew = false;

            ButtonOld = !Button.state;

            // Main event loop

            for (;;)
            {
                ButtonNew = Button.state;

                if (ButtonNew != ButtonOld)
                {
                    Console.WriteLine(ButtonNew ? "PRESSED" : "RELEASED");
                    LED.state = ButtonNew;
                    ButtonOld = ButtonNew;
                }

                System.Threading.Thread.Sleep(100);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Constructor for a single SPI device.
        /// </summary>
        /// <param name="devname">SPI device node name.</param>
        /// <param name="mode">SPI clock mode.</param>
        /// <param name="wordsize">SPI transfer word size.</param>
        /// <param name="speed">SPI transfer speed.</param>
        /// <param name="cspin">SPI slave select GPIO pin number, or
        /// <c>AUTOCHIPSELECT</c>.</param>
        public Device(string devname, int mode, int wordsize,
                      int speed, IO.Objects.libsimpleio.GPIO.Pin cspin = AUTOCHIPSELECT)
        {
            IO.Bindings.libsimpleio.SPI_open(devname, mode, wordsize,
                                             speed, out this.myfd, out int error);

            if (error != 0)
            {
                throw new Exception("SPI_open() failed, " +
                                    errno.strerror(error));
            }

            if (cspin == AUTOCHIPSELECT)
            {
                this.myfdcs = IO.Bindings.libsimpleio.SPI_AUTO_CS;
            }
            else
            {
                this.myfdcs = cspin.fd;
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMuntsOS C# LED Test\n");

            // Configure a GPIO output to drive an LED

            IO.Objects.libsimpleio.Device.Designator desg_LED =
                new IO.Objects.libsimpleio.Device.Designator(0, 26);

            IO.Interfaces.GPIO.Pin LED =
                new IO.Objects.libsimpleio.GPIO.Pin(desg_LED,
                                                    IO.Interfaces.GPIO.Direction.Output);

            // Flash the LED forever (until killed)

            Console.WriteLine("Press CONTROL-C to exit.\n");

            for (;;)
            {
                LED.state = !LED.state;
                System.Threading.Thread.Sleep(500);
            }
        }