Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        public IGpioControllerDriver InitDriver(ILogger _logger, AvailablePins _availablePins, NumberingScheme _scheme)
        {
            Logger        = _logger ?? throw new ArgumentNullException(nameof(_logger));
            AvailablePins = _availablePins;

            if (!IsWiringPiInstalled())
            {
                throw new DriverInitializationFailedException(nameof(WiringPiDriver), "WiringPi Library isn't installed on the system.");
            }

            if (!GpioCore.IsAllowedToExecute)
            {
                IsDriverInitialized = false;
                throw new DriverInitializationFailedException(nameof(WiringPiDriver), "Driver isn't allowed to execute.");
            }

            NumberingScheme = _scheme;

            //for (int i = 0; i < AvailablePins.OutputPins.Length; i++) {
            //	SetMode(AvailablePins.OutputPins[i], GpioPinMode.Output);
            //}

            //for (int i = 0; i < AvailablePins.InputPins.Length; i++) {
            //	SetMode(AvailablePins.InputPins[i], GpioPinMode.Input);
            //}

            IsDriverInitialized = true;
            return(this);
        }
Ejemplo n.º 3
0
        public async Task InitController <T>(T selectedDriver, NumberingScheme _scheme) where T : IGpioControllerDriver
        {
            if (IsAlreadyInit)
            {
                return;
            }

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

            PinController.InitPinController <T>(selectedDriver, _scheme);
            IGpioControllerDriver?driver = PinController.GetDriver();

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

            await InitPinConfigs().ConfigureAwait(false);
            await SetEvents().ConfigureAwait(false);

            IsAlreadyInit = true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes the gpio driver.
 /// </summary>
 /// <param name="pins">The available pins on the device.</param>
 /// <param name="scheme">The numbering scheme to use.</param>
 /// <returns>The driver.</returns>
 internal GpioControllerDriver(InternalLogger logger, PinsWrapper pins, GpioDriver driverName, PinConfig pinConfig, NumberingScheme scheme)
 {
     Logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     Pins                = pins;
     NumberingScheme     = scheme;
     DriverName          = driverName;
     PinConfig           = pinConfig;
     IsDriverInitialized = true;
 }
Ejemplo n.º 5
0
        public IGpioControllerDriver InitDriver(NumberingScheme numberingScheme)
        {
            if (!PiGpioController.IsAllowedToExecute)
            {
                CastDriver <IGpioControllerDriver>(this).Logger.Warning("Failed to initialize Gpio Controller Driver.");
                IsDriverProperlyInitialized = false;
                return(null);
            }

            NumberingScheme             = numberingScheme;
            DriverController            = new GpioController((PinNumberingScheme)numberingScheme);
            IsDriverProperlyInitialized = true;
            return(this);
        }
        public IGpioControllerDriver InitDriver(NumberingScheme scheme)
        {
            if (!PiGpioController.IsAllowedToExecute)
            {
                CastDriver <IGpioControllerDriver>(this)?.Logger.Warning("Failed to initialize Gpio Controller Driver. (Driver isn't allowed to execute.)");
                IsDriverProperlyInitialized = false;
                return(this);
            }

            NumberingScheme = scheme;
            Pi.Init <BootstrapWiringPi>();
            IsDriverProperlyInitialized = true;
            return(this);
        }
Ejemplo n.º 7
0
        public IGpioControllerDriver InitDriver(ILogger _logger, AvailablePins _availablePins, NumberingScheme _scheme)
        {
            Logger        = _logger ?? throw new ArgumentNullException(nameof(_logger));
            AvailablePins = _availablePins;

            if (!GpioCore.IsAllowedToExecute)
            {
                IsDriverInitialized = false;
                throw new DriverInitializationFailedException(nameof(RaspberryIODriver), "Not allowed to initialize.");
            }

            NumberingScheme = _scheme;
            Pi.Init <BootstrapWiringPi>();
            IsDriverInitialized = true;
            return(this);
        }
Ejemplo n.º 8
0
 public SystemDeviceDriver(InternalLogger logger, PinsWrapper pins, PinConfig pinConfig, NumberingScheme scheme) : base(logger, pins, Enums.GpioDriver.SystemDevicesDriver, pinConfig, scheme)
 {
 }
Ejemplo n.º 9
0
 internal WiringPiDriver(InternalLogger logger, PinsWrapper pins, PinConfig pinConfig, NumberingScheme scheme) : base(logger, pins, GpioDriver.WiringPiDriver, pinConfig, scheme)
 {
     CommandLine = new OSCommandLineInterfacer(OSPlatform.Linux, false, false, false);
 }
Ejemplo n.º 10
0
 internal RaspberryIODriver(InternalLogger logger, PinsWrapper pins, PinConfig pinConfig, NumberingScheme scheme) : base(logger, pins, GpioDriver.RaspberryIODriver, pinConfig, scheme)
 {
 }
Ejemplo n.º 11
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.º 12
0
        //Method Name: assignGridOrdering
        //Objectives: gives each block in the grid a number according to the numbering scheme used
        //Inputs: an array of the (x, y, z) grid dimensions and an array of the Inactive blocks numberings
        //Ouputs: an array of GridBlocks that are given numbers according to the numbering scheme used
        public static GridBlock[] assignGridOrdering(int[] grid_dimensions, int[] inactive_blocks, NumberingScheme scheme)
        {
            //variables to store the grid dimensions
            int x, y, z;

            //store the grid dimensions
            x = grid_dimensions[0]; y = grid_dimensions[1]; z = grid_dimensions[2];
            //an array to store a block's i, j and k coordinates within the grid according to the engineering notation
            int[] block_coordinates = new int[3];
            //A variable to store block's data
            GridBlock block;

            //A variable representing the grid array of blocks
            GridBlock[] grid = new GridBlock[0];
            if (scheme == NumberingScheme.All)
            {
                //Grid array size is equal to all the block "including in-active blocks"
                grid = new GridBlock[x * y * z];
            }
            else if (scheme == NumberingScheme.Active_Only)
            {
                //Grid array size is equal to the number of active-only blocks
                grid = new GridBlock[x * y * z - inactive_blocks.Length];
            }


            //A general loop counter
            int counter = 0;
            //A block counter
            //This variable is used only with the "assignBlockOrdering_ActiveOnly" method to keep track of the number of active blocks added to the grid
            int block_counter = 0;

            //A loop to iterate over all the blocks in the grid according to the engineering notation
            for (int k = 0; k < z; k++)
            {
                for (int j = 0; j < y; j++)
                {
                    for (int i = 0; i < x; i++)
                    {
                        block = new GridBlock();
                        //assign the values of the block coordinates
                        block.x = i; block.y = j; block.z = k;

                        //set block type "either Inactive or normal"
                        if (inactive_blocks.Contains(counter))
                        {
                            block.type = GridBlock.Type.Inactive;
                        }

                        //set the block coordinates array that will be passed to other methods
                        block_coordinates[0] = i; block_coordinates[1] = j; block_coordinates[2] = k;

                        //###########################################################################################

                        if (scheme == NumberingScheme.All)
                        {
                            //Natural ordering for the entire grid "both active and in-active blocks"
                            RectangularBlockNumbering.assignBlockOrdering_Natural(block, counter, block_coordinates, grid_dimensions, inactive_blocks);
                        }
                        else if (scheme == NumberingScheme.Active_Only)
                        {
                            //Natural ordering for the grid "active blocks only"
                            if (block.type == GridBlock.Type.Inactive)
                            {
                                //increment the general loop counter and skip this block
                                counter += 1;
                                continue;
                            }

                            RectangularBlockNumbering.assignBlockOrdering_ActiveOnly(block, counter, block_counter, block_coordinates, grid_dimensions, inactive_blocks);
                        }

                        //###########################################################################################

                        //increment counter at the end of the loop
                        counter += 1;
                        //this statement adds the block to the grid array
                        grid[block_counter] = block;
                        //only increment block_counter when a block is added to the grid to keep track of how many blocks have been added
                        block_counter += 1;
                    }
                }
            }

            return(grid);
        }