Пример #1
0
        /// <summary>
        /// Attempt to get the best applicable driver for the board the program is executing on.
        /// </summary>
        /// <returns>A driver that works with the board the program is executing on.</returns>
        private static GpioDriver GetBestDriverForBoard()
        {
            string[] cpuInfoLines = File.ReadAllLines(CpuInfoPath);
            Regex    regex        = new Regex(@"Hardware\s*:\s*(.*)");

            foreach (string cpuInfoLine in cpuInfoLines)
            {
                Match match = regex.Match(cpuInfoLine);
                if (match.Success)
                {
                    if (match.Groups.Count > 1)
                    {
                        if (match.Groups[1].Value == RaspberryPiHardware)
                        {
                            return(new RaspberryPi3Driver());
                        }
                        // Commenting out as HummingBoard driver is not implemented yet, will be added back after implementation
                        // https://github.com/dotnet/iot/issues/76
                        //if (match.Groups[1].Value == HummingBoardHardware)
                        //{
                        //    return new HummingBoardDriver();
                        //}
                        return(UnixDriver.Create());
                    }
                }
            }
            return(UnixDriver.Create());
        }
Пример #2
0
        /// <summary>
        /// Attempt to get the best applicable driver for the board the program is executing on.
        /// </summary>
        /// <returns>A driver that works with the board the program is executing on.</returns>
        private static GpioDriver GetBestDriverForBoardOnLinux()
        {
            RaspberryPi3LinuxDriver?internalDriver = RaspberryPi3Driver.CreateInternalRaspberryPi3LinuxDriver(out _);

            if (internalDriver is object)
            {
                return(new RaspberryPi3Driver(internalDriver));
            }

            return(UnixDriver.Create());
        }
Пример #3
0
        /// <summary>
        /// Attempt to get the best applicable driver for the board the program is executing on.
        /// </summary>
        /// <returns>A driver that works with the board the program is executing on.</returns>
        private static GpioDriver GetBestDriverForBoardOnLinux()
        {
            try
            {
                // Because we can't construct the internal driver here (and the identification isn't public either), we'll have to go trough the exception
                return(new RaspberryPi3Driver());
            }
            catch (Exception x) when(x is NotSupportedException || x is PlatformNotSupportedException)
            {
            }

            return(UnixDriver.Create());
        }
Пример #4
0
        // TODO: remove try catch after https://github.com/dotnet/corefx/issues/32015 deployed
        public static UnixDriver Create()
        {
            UnixDriver driver = null;

            try
            {
                driver = new LibGpiodDriver();
            }
            catch (DllNotFoundException)
            {
                driver = new SysfsDriver();
            }
            return(driver);
        }
Пример #5
0
        // TODO: remove try catch after https://github.com/dotnet/corefx/issues/32015 deployed
        public static UnixDriver Create()
        {
            UnixDriver driver = null;

            try
            {
                driver = new LibGpiodDriver();
            }
            catch (PlatformNotSupportedException)
            {
                driver = new SysFsDriver();
            }
            return(driver);
        }
Пример #6
0
        internal static void Lcd(string message)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var driver = new UnixDriver())
                using (var controller = new GpioController(driver))
                {
                    GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                    GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                    GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                    var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                    lcd.Begin(16, 2);
                    lcd.Print(message);
                }
        }
Пример #7
0
        /// <summary>
        /// Attempt to get the best applicable driver for the board the program is executing on.
        /// </summary>
        /// <returns>A driver that works with the board the program is executing on.</returns>
        private static GpioDriver GetBestDriverForBoard()
        {
            string[] cpuInfoLines = File.ReadAllLines(CpuInfoPath);
            Regex    regex        = new Regex(@"Hardware\s*:\s*(.*)");

            foreach (string cpuInfoLine in cpuInfoLines)
            {
                Match match;

                // a first chance of finding a raspberry pi..... perhaps not on Raspbian. note
                // that we want this to fail quietly if something goes wrong with the test and continue
                // with detecing a PI usiing /dev/cpuinfo
                try
                {
                    if (File.ReadAllText(ModelInfoPath).StartsWith("Raspberry Pi"))
                    {
                        return(new RaspberryPi3Driver());
                    }
                }
                catch { }

                match = regex.Match(cpuInfoLine);

                if (match.Success)
                {
                    if (match.Groups.Count > 1)
                    {
                        if (match.Groups[1].Value == RaspberryPiHardware)
                        {
                            return(new RaspberryPi3Driver());
                        }
                        // Commenting out as HummingBoard driver is not implemented yet, will be added back after implementation
                        // https://github.com/dotnet/iot/issues/76
                        //if (match.Groups[1].Value == HummingBoardHardware)
                        //{
                        //    return new HummingBoardDriver();
                        //}
                        return(UnixDriver.Create());
                    }
                }
            }
            return(UnixDriver.Create());
        }
Пример #8
0
        /// <summary>
        /// Static factory method
        /// </summary>
        /// <returns>An instance of GpioDriver, depending on which one fits</returns>
        // TODO: remove try catch after https://github.com/dotnet/corefx/issues/32015 deployed
        public static UnixDriver Create()
        {
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                throw new PlatformNotSupportedException(nameof(UnixDriver) + " is only supported on Linux/Unix");
            }

            UnixDriver driver = null;

            try
            {
                driver = new LibGpiodDriver();
            }
            catch (PlatformNotSupportedException)
            {
                driver = new SysFsDriver();
            }

            return(driver);
        }