Пример #1
0
        private async Task InitPinConfigs()
        {
            bool isLoadSuccess = await ConfigManager.LoadConfiguration().ConfigureAwait(false);

            if (!isLoadSuccess || PinConfigManager.GetConfiguration().PinConfigs.Count <= 0 ||
                (isLoadSuccess && PinConfigManager.GetConfiguration().PinConfigs.Count <= 0))
            {
                generateConfigs();
                await ConfigManager.SaveConfig().ConfigureAwait(false);
            }

            void generateConfigs()
            {
                List <Pin> pinConfigs = new List <Pin>();

                for (int i = 0; i < Constants.BcmGpioPins.Length; i++)
                {
                    Pin config = PinController.GetDriver().GetPinConfig(Constants.BcmGpioPins[i]);

                    pinConfigs.Add(config);
                    Logger.Trace($"Generated pin config for {Pi.Gpio[i].PhysicalPinNumber} gpio pin.");
                }

                ConfigManager.Init(new PinConfig(pinConfigs, false));
            }
        }
Пример #2
0
        public async Task InitController()
        {
            if (IsAlreadyInit)
            {
                return;
            }

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

            PinController = new PinController();

            switch (GpioDriver)
            {
            case EGPIO_DRIVERS.RaspberryIODriver:
                PinController.InitPinController <RaspberryIODriver>(new RaspberryIODriver(), NumberingScheme.Logical);
                break;

            case EGPIO_DRIVERS.SystemDevicesDriver:
                PinController.InitPinController <SystemDeviceDriver>(new SystemDeviceDriver(), NumberingScheme.Logical);
                break;

            case EGPIO_DRIVERS.WiringPiDriver:
                PinController.InitPinController <WiringPiDriver>(new WiringPiDriver(), NumberingScheme.Logical);
                break;
            }

            IGpioControllerDriver?driver = PinController.GetDriver();

            if (driver == null || !driver.IsDriverProperlyInitialized)
            {
                Logger.Warning("Failed to initialize pin controller and its drivers.");
                return;
            }

            EventManager        = new PinEvents();
            MorseTranslator     = new GpioMorseTranslator();
            BluetoothController = new PiBluetoothController();
            SoundController     = new PiSoundController();

            SetEvents();

            if (ConfigManager != null && PinConfigManager.GetConfiguration().PinConfigs.Count <= 0)
            {
                await ConfigManager.LoadConfiguration().ConfigureAwait(false);
            }

            IsAlreadyInit = true;
        }
Пример #3
0
        private void MapInternalSensors()
        {
            for (int i = 0; i < PinConfigManager.GetConfiguration().PinConfigs.Count; i++)
            {
                Pin config = PinConfigManager.GetConfiguration().PinConfigs[i];

                SensorType sensorType = GetSensorType(Constants.BcmGpioPins[i]);
                switch (sensorType)
                {
                case SensorType.Buzzer:
                    PinController.GetDriver()?.MapSensor <TBuzzerModule>(new PinMap <TBuzzerModule>(config.PinNumber,
                                                                                                    MappingEvent.Both, sensorType, SensorEvents.IrSensorEvent));
                    break;

                case SensorType.Invalid:
                    break;

                case SensorType.IRSensor:
                    PinController.GetDriver()?.MapSensor <TIrSensor>(new PinMap <TIrSensor>(config.PinNumber,
                                                                                            MappingEvent.Both, sensorType, SensorEvents.IrSensorEvent));
                    break;

                case SensorType.Relay:
                    PinController.GetDriver()?.MapSensor <TRelaySwitch>(new PinMap <TRelaySwitch>(config.PinNumber,
                                                                                                  MappingEvent.Both, sensorType, SensorEvents.RelaySwitchEvent));
                    break;

                case SensorType.SoundSensor:
                    PinController.GetDriver()?.MapSensor <TSoundSensor>(new PinMap <TSoundSensor>(config.PinNumber,
                                                                                                  MappingEvent.Both, sensorType, SensorEvents.SoundSensorEvent));
                    break;
                }

                Logger.Trace($"Sensor Map generated for '{config.PinNumber}' / '{sensorType}' gpio pin.");
            }
        }