Ejemplo n.º 1
0
        public Task ApplyAsync()
        {
            var hsrt16 = _ccToolsBoardService.RegisterHSRT16("HSRT16", new I2CSlaveAddress(32));

            var garden = _areaService.RegisterArea("Garden");

            var parkingLotLamp = new LogicalBinaryOutput(hsrt16[HSRT16Pin.Relay6], hsrt16[HSRT16Pin.Relay7], hsrt16[HSRT16Pin.Relay8]);

            _actuatorFactory.RegisterLamp(garden, Garden.LampParkingLot, parkingLotLamp);
            // Relay 9 is free.
            _actuatorFactory.RegisterSocket(garden, Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11]);
            _actuatorFactory.RegisterLamp(garden, Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampTap, hsrt16[HSRT16Pin.Relay13]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampGarage, hsrt16[HSRT16Pin.Relay14]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15]);
            var stateMachine = _actuatorFactory.RegisterStateMachine(garden, Garden.StateMachine, InitializeStateMachine);

            var button = _sensorFactory.RegisterButton(garden, Garden.Button, _pi2GpioService.GetInput(4).WithInvertedState());

            button.PressedShortTrigger.Attach(() => stateMachine.TrySetNextState());
            button.PressedLongTrigger.Attach(() => stateMachine.TryTurnOff());

            _automationFactory.RegisterConditionalOnAutomation(garden, Garden.LampParkingLotAutomation)
            .WithComponent(garden.GetLamp(Garden.LampParkingLot))
            .WithOnAtNightRange()
            .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00"));

            var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4), _logService);

            ioBoardsInterruptMonitor.AddCallback(_ccToolsBoardService.PollInputBoardStates);
            ioBoardsInterruptMonitor.Start();

            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
        public Task ApplyAsync()
        {
            var hsrt16 = _deviceRegistryService.GetDevice <HSRT16>("HSRT16");

            var garden = _areaService.RegisterArea("Garden");

            var parkingLotOutput = new LogicalBinaryOutput(hsrt16[HSRT16Pin.Relay6], hsrt16[HSRT16Pin.Relay7], hsrt16[HSRT16Pin.Relay8]);

            _actuatorFactory.RegisterLamp(garden, Garden.LampParkingLot, parkingLotOutput);
            // Relay 9 is free.
            _actuatorFactory.RegisterSocket(garden, Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11]);
            _actuatorFactory.RegisterLamp(garden, Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampTap, hsrt16[HSRT16Pin.Relay13]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampGarage, hsrt16[HSRT16Pin.Relay14]);
            _actuatorFactory.RegisterLamp(garden, Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15]);
            var stateMachine = _actuatorFactory.RegisterStateMachine(garden, Garden.StateMachine, InitializeStateMachine);

            var button = _sensorFactory.RegisterButton(garden, Garden.Button, _gpioService.GetInput(4, GpioPullMode.High, GpioInputMonitoringMode.Interrupt).WithInvertedState());

            button.CreatePressedShortTrigger(_messageBroker).Attach(() => stateMachine.TrySetNextState());
            button.CreatePressedLongTrigger(_messageBroker).Attach(() => stateMachine.TryTurnOff());

            _automationFactory.RegisterConditionalOnAutomation(garden, Garden.LampParkingLotAutomation)
            .WithComponent(garden.GetLamp(Garden.LampParkingLot))
            .WithOnAtNightRange()
            .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00"));

            return(Task.FromResult(0));
        }
Ejemplo n.º 3
0
        public void RegisterInterrupts()
        {
            var configuration = _configurationService.GetConfiguration <InterruptMonitorServiceConfiguration>("InterruptMonitorService");

            foreach (var interruptConfiguration in configuration.Interrupts)
            {
                var gpio = _gpioService.GetInput(interruptConfiguration.Value.Gpio, interruptConfiguration.Value.PullMode, interruptConfiguration.Value.MonitoringMode);
                if (interruptConfiguration.Value.IsInverted)
                {
                    gpio = gpio.WithInvertedState();
                }

                RegisterInterrupt(interruptConfiguration.Key, gpio);
            }
        }
Ejemplo n.º 4
0
        public Task ApplyAsync()
        {
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input0.ToString(), new I2CSlaveAddress(42));
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input1.ToString(), new I2CSlaveAddress(43));
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input2.ToString(), new I2CSlaveAddress(47));
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input3.ToString(), new I2CSlaveAddress(45));
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input4.ToString(), new I2CSlaveAddress(46));
            _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input5.ToString(), new I2CSlaveAddress(44));

            var i2CHardwareBridge = new I2CHardwareBridge(new I2CSlaveAddress(50), _i2CBusService, _schedulerService);

            _deviceService.AddDevice(i2CHardwareBridge);

            _remoteSocketService.Adapter = new I2CHardwareBridgeLdp433MhzBridgeAdapter(i2CHardwareBridge, 10);
            var codeSequenceProvider = new DipswitchCodeProvider();

            _remoteSocketService.RegisterRemoteSocket("OFFICE_0", codeSequenceProvider.GetCodePair(DipswitchSystemCode.AllOn, DipswitchUnitCode.A));

            _containerService.GetInstance <BedroomConfiguration>().Apply();
            _containerService.GetInstance <OfficeConfiguration>().Apply();
            _containerService.GetInstance <UpperBathroomConfiguration>().Apply();
            _containerService.GetInstance <ReadingRoomConfiguration>().Apply();
            _containerService.GetInstance <ChildrensRoomRoomConfiguration>().Apply();
            _containerService.GetInstance <KitchenConfiguration>().Apply();
            _containerService.GetInstance <FloorConfiguration>().Apply();
            _containerService.GetInstance <LowerBathroomConfiguration>().Apply();
            _containerService.GetInstance <StoreroomConfiguration>().Apply();
            _containerService.GetInstance <LivingRoomConfiguration>().Apply();

            var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4), _logService);

            ioBoardsInterruptMonitor.AddCallback(_ccToolsBoardService.PollInputBoardStates);
            ioBoardsInterruptMonitor.Start();

            return(Task.FromResult(0));
        }