Ejemplo n.º 1
0
        public async Task InitController(IGpioControllerDriver?_driver, bool isUnixSys, NumberingScheme _scheme)
        {
            if (IsInitSuccess || _driver == null)
            {
                return;
            }

            IsAllowedToExecute = isUnixSys && Helpers.GetPlatform() == OSPlatform.Linux;

            if (!IsAllowedToExecute)
            {
                Logger.Warning("Running OS platform is unsupported.");
                return;
            }

            PinController.InitPinController(_driver, _scheme);
            IGpioControllerDriver?driver = PinController.GetDriver();

            if (driver == null || !driver.IsDriverInitialized)
            {
                Logger.Warning($"{_driver.DriverName} failed to initialize properly. Restart of entire application is recommended.");
                throw new DriverInitializationFailedException(_driver.DriverName.ToString());
            }

            GeneratePinConfiguration(driver);
            await InitEvents().ConfigureAwait(false);

            IsInitSuccess = true;
        }
Ejemplo n.º 2
0
        internal async Task InitController(GpioControllerDriver?driver, NumberingScheme numberingScheme)
        {
            if (IsInitSuccess || driver == null)
            {
                return;
            }

            if (!IsAllowedToExecute)
            {
                Logger.Warn("Running OS platform is unsupported.");
                return;
            }

            PinController.InitPinController(driver);
            GpioControllerDriver?gpioDriver = PinController.GetDriver();

            if (driver == null || !driver.IsDriverInitialized)
            {
                Logger.Warn($"{gpioDriver.DriverName} failed to initialize properly. Restart of entire application is recommended.");
                throw new DriverInitializationFailedException(gpioDriver.DriverName.ToString());
            }

            if (!await PinConfig.LoadConfiguration().ConfigureAwait(false))
            {
                GeneratePinConfiguration();
                await PinConfig.SaveConfig().ConfigureAwait(false);
            }

            EventGenerator.InitEventGeneration();
            IsInitSuccess = true;
        }