示例#1
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));
        }
示例#2
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));
        }
示例#3
0
            public Task ApplyAsync()
            {
                var hsrt16 = _ccToolsBoardService.RegisterHSRT16(InstalledDevice.CellarHSRT16, new I2CSlaveAddress(32));

                var garden = _areaService.CreateArea(Room.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]);
                _actuatorFactory.RegisterStateMachine(garden, Garden.StateMachine, InitializeStateMachine);

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

                garden.GetStateMachine(Garden.StateMachine).ConnectMoveNextAndToggleOffWith(garden.GetButton(Garden.Button));

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

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

                ioBoardsInterruptMonitor.InterruptDetected += (s, e) => _ccToolsBoardService.PollInputBoardStates();
                ioBoardsInterruptMonitor.Start();

                return(Task.FromResult(0));
            }
示例#4
0
        public void Apply()
        {
            var hsrel8            = _ccToolsBoardService.RegisterHSREL8(InstalledDevice.OfficeHSREL8, new I2CSlaveAddress(20));
            var hspe8             = _ccToolsBoardService.RegisterHSPE8OutputOnly(InstalledDevice.UpperFloorAndOfficeHSPE8, new I2CSlaveAddress(37));
            var input4            = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input4);
            var input5            = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input5);
            var i2CHardwareBridge = _deviceService.GetDevice <I2CHardwareBridge>();

            const int SensorPin = 2;

            var room = _areaService.CreateArea(Room.Office);

            _sensorFactory.RegisterWindow(room, Office.WindowLeft,
                                          w => w.WithLeftCasement(input4.GetInput(11)).WithRightCasement(input4.GetInput(12), input4.GetInput(10)));

            _sensorFactory.RegisterWindow(room, Office.WindowRight,
                                          w => w.WithLeftCasement(input4.GetInput(8)).WithRightCasement(input4.GetInput(9), input5.GetInput(8)));

            _sensorFactory.RegisterTemperatureSensor(room, Office.TemperatureSensor,
                                                     i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin));

            _sensorFactory.RegisterHumiditySensor(room, Office.HumiditySensor,
                                                  i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin));

            _sensorFactory.RegisterMotionDetector(room, Office.MotionDetector, input4.GetInput(13));

            _actuatorFactory.RegisterSocket(room, Office.SocketFrontLeft, hsrel8.GetOutput(0));
            _actuatorFactory.RegisterSocket(room, Office.SocketFrontRight, hsrel8.GetOutput(6));
            _actuatorFactory.RegisterSocket(room, Office.SocketWindowLeft, hsrel8.GetOutput(10).WithInvertedState());
            _actuatorFactory.RegisterSocket(room, Office.SocketWindowRight, hsrel8.GetOutput(11).WithInvertedState());
            _actuatorFactory.RegisterSocket(room, Office.SocketRearLeftEdge, hsrel8.GetOutput(7));
            _actuatorFactory.RegisterSocket(room, Office.SocketRearLeft, hsrel8.GetOutput(2));
            _actuatorFactory.RegisterSocket(room, Office.SocketRearRight, hsrel8.GetOutput(1));
            _actuatorFactory.RegisterSocket(room, Office.RemoteSocketDesk, _remoteSocketService.GetOutput(0));

            _sensorFactory.RegisterButton(room, Office.ButtonUpperLeft, input5.GetInput(0));
            _sensorFactory.RegisterButton(room, Office.ButtonLowerLeft, input5.GetInput(1));
            _sensorFactory.RegisterButton(room, Office.ButtonLowerRight, input4.GetInput(14));
            _sensorFactory.RegisterButton(room, Office.ButtonUpperRight, input4.GetInput(15));

            _actuatorFactory.RegisterStateMachine(room, Office.CombinedCeilingLights, (s, a) => SetupLight(s, hsrel8, hspe8, a));

            room.GetButton(Office.ButtonUpperLeft).GetPressedLongTrigger().Attach(() =>
            {
                room.GetStateMachine(Office.CombinedCeilingLights).TryTurnOff();
                room.GetSocket(Office.SocketRearLeftEdge).TryTurnOff();
                room.GetSocket(Office.SocketRearLeft).TryTurnOff();
                room.GetSocket(Office.SocketFrontLeft).TryTurnOff();
            });
        }
示例#5
0
        public void Apply()
        {
            var hsrel5            = _ccToolsBoardService.RegisterHSREL5(InstalledDevice.UpperBathroomHSREL5, new I2CSlaveAddress(61));
            var input5            = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input5);
            var i2CHardwareBridge = _deviceService.GetDevice <I2CHardwareBridge>();

            const int SensorPin = 4;

            var room = _areaService.CreateArea(Room.UpperBathroom);

            _actuatorFactory.RegisterStateMachine(room, UpperBathroom.Fan, (s, r) => SetupFan(s, hsrel5));

            _sensorFactory.RegisterTemperatureSensor(room, UpperBathroom.TemperatureSensor,
                                                     i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin));

            _sensorFactory.RegisterHumiditySensor(room, UpperBathroom.HumiditySensor,
                                                  i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin));

            _sensorFactory.RegisterMotionDetector(room, UpperBathroom.MotionDetector, input5.GetInput(15));

            _actuatorFactory.RegisterLamp(room, UpperBathroom.LightCeilingDoor, hsrel5.GetOutput(0));
            _actuatorFactory.RegisterLamp(room, UpperBathroom.LightCeilingEdge, hsrel5.GetOutput(1));
            _actuatorFactory.RegisterLamp(room, UpperBathroom.LightCeilingMirrorCabinet, hsrel5.GetOutput(2));
            _actuatorFactory.RegisterLamp(room, UpperBathroom.LampMirrorCabinet, hsrel5.GetOutput(3));

            var combinedLights =
                _actuatorFactory.RegisterLogicalActuator(room, UpperBathroom.CombinedCeilingLights)
                .WithActuator(room.GetLamp(UpperBathroom.LightCeilingDoor))
                .WithActuator(room.GetLamp(UpperBathroom.LightCeilingEdge))
                .WithActuator(room.GetLamp(UpperBathroom.LightCeilingMirrorCabinet))
                .WithActuator(room.GetLamp(UpperBathroom.LampMirrorCabinet));

            _automationFactory.RegisterTurnOnAndOffAutomation(room, UpperBathroom.CombinedCeilingLightsAutomation)
            .WithTrigger(room.GetMotionDetector(UpperBathroom.MotionDetector))
            .WithTarget(combinedLights);

            new BathroomFanAutomation(AutomationIdGenerator.Generate(room, UpperBathroom.FanAutomation), _schedulerService, _settingsService)
            .WithTrigger(room.GetMotionDetector(UpperBathroom.MotionDetector))
            .WithActuator(room.GetStateMachine(UpperBathroom.Fan));

            _synonymService.AddSynonymsForArea(Room.UpperBathroom, "BadOben", "UpperBathroom");
        }
示例#6
0
        public void Apply()
        {
            var hsrel5            = _ccToolsBoardService.RegisterHSREL5(InstalledDevice.BedroomHSREL5, new I2CSlaveAddress(38));
            var hsrel8            = _ccToolsBoardService.RegisterHSREL8(InstalledDevice.BedroomHSREL8, new I2CSlaveAddress(21));
            var input5            = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input5);
            var input4            = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input4);
            var i2CHardwareBridge = _deviceService.GetDevice <I2CHardwareBridge>();

            const int SensorPin = 6;

            var room = _areaService.CreateArea(Room.Bedroom);

            _sensorFactory.RegisterWindow(room, Bedroom.WindowLeft, w => w.WithCenterCasement(input5.GetInput(2)));
            _sensorFactory.RegisterWindow(room, Bedroom.WindowRight, w => w.WithCenterCasement(input5.GetInput(3)));

            _sensorFactory.RegisterTemperatureSensor(room, Bedroom.TemperatureSensor,
                                                     i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin));

            _sensorFactory.RegisterHumiditySensor(room, Bedroom.HumiditySensor,
                                                  i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin));

            _sensorFactory.RegisterMotionDetector(room, Bedroom.MotionDetector, input5.GetInput(12));

            _sensorFactory.RegisterButton(room, Bedroom.ButtonWindowUpper, input5.GetInput(10));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonWindowLower, input5.GetInput(13));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonBedLeftInner, input4.GetInput(2));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonBedLeftOuter, input4.GetInput(0));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonBedRightInner, input4.GetInput(1));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonBedRightOuter, input4.GetInput(3));
            _sensorFactory.RegisterButton(room, Bedroom.ButtonDoor, input5.GetInput(11));

            _sensorFactory.RegisterRollerShutterButtons(room, Bedroom.RollerShutterButtonsUpperUp, input5.GetInput(6),
                                                        Bedroom.RollerShutterButtonsUpperDown, input5.GetInput(7));

            _sensorFactory.RegisterRollerShutterButtons(room, Bedroom.RollerShutterButtonsLowerUp, input5.GetInput(4),
                                                        Bedroom.RollerShutterButtonsLowerDown, input5.GetInput(5));

            _actuatorFactory.RegisterLamp(room, Bedroom.LightCeiling, hsrel5.GetOutput(5).WithInvertedState());
            _actuatorFactory.RegisterLamp(room, Bedroom.LightCeilingWindow, hsrel5.GetOutput(6).WithInvertedState());
            _actuatorFactory.RegisterLamp(room, Bedroom.LightCeilingWall, hsrel5.GetOutput(7).WithInvertedState());
            _actuatorFactory.RegisterLamp(room, Bedroom.LampBedLeft, hsrel5.GetOutput(4));
            _actuatorFactory.RegisterLamp(room, Bedroom.LampBedRight, hsrel8.GetOutput(8).WithInvertedState());

            _actuatorFactory.RegisterSocket(room, Bedroom.SocketWindowLeft, hsrel5[HSREL5Pin.Relay0]);
            _actuatorFactory.RegisterSocket(room, Bedroom.SocketWindowRight, hsrel5[HSREL5Pin.Relay1]);
            _actuatorFactory.RegisterSocket(room, Bedroom.SocketWall, hsrel5[HSREL5Pin.Relay2]);
            _actuatorFactory.RegisterSocket(room, Bedroom.SocketWallEdge, hsrel5[HSREL5Pin.Relay3]);
            _actuatorFactory.RegisterSocket(room, Bedroom.SocketBedLeft, hsrel8.GetOutput(7));
            _actuatorFactory.RegisterSocket(room, Bedroom.SocketBedRight, hsrel8.GetOutput(9));

            _actuatorFactory.RegisterRollerShutter(room, Bedroom.RollerShutterLeft, hsrel8[HSREL8Pin.Relay6], hsrel8[HSREL8Pin.Relay5]);
            _actuatorFactory.RegisterRollerShutter(room, Bedroom.RollerShutterRight, hsrel8[HSREL8Pin.Relay3], hsrel8[HSREL8Pin.Relay4]);

            room.GetRollerShutter(Bedroom.RollerShutterLeft)
            .ConnectWith(room.GetButton(Bedroom.RollerShutterButtonsUpperUp), room.GetButton(Bedroom.RollerShutterButtonsUpperDown));

            room.GetRollerShutter(Bedroom.RollerShutterRight)
            .ConnectWith(room.GetButton(Bedroom.RollerShutterButtonsLowerUp), room.GetButton(Bedroom.RollerShutterButtonsLowerDown));

            _actuatorFactory.RegisterLogicalActuator(room, Bedroom.CombinedCeilingLights)
            .WithActuator(room.GetLamp(Bedroom.LightCeilingWall))
            .WithActuator(room.GetLamp(Bedroom.LightCeilingWindow))
            .ConnectToggleActionWith(room.GetButton(Bedroom.ButtonDoor))
            .ConnectToggleActionWith(room.GetButton(Bedroom.ButtonWindowUpper));

            room.GetButton(Bedroom.ButtonDoor).GetPressedLongTrigger().Attach(() =>
            {
                room.GetStateMachine(Bedroom.LampBedLeft).TryTurnOff();
                room.GetStateMachine(Bedroom.LampBedRight).TryTurnOff();
                room.GetStateMachine(Bedroom.CombinedCeilingLights).TryTurnOff();
            });

            _automationFactory.RegisterRollerShutterAutomation(room, Bedroom.RollerShuttersAutomation)
            .WithRollerShutters(room.GetRollerShutters())
            .WithDoNotOpenBefore(TimeSpan.FromHours(7).Add(TimeSpan.FromMinutes(15)))
            .WithCloseIfOutsideTemperatureIsGreaterThan(24)
            .WithDoNotOpenIfOutsideTemperatureIsBelowThan(3);

            _automationFactory.RegisterTurnOnAndOffAutomation(room, Bedroom.LightCeilingAutomation)
            .WithTrigger(room.GetMotionDetector(Bedroom.MotionDetector))
            .WithTarget(room.GetStateMachine(Bedroom.LightCeiling))
            .WithTurnOnIfAllRollerShuttersClosed(room.GetRollerShutter(Bedroom.RollerShutterLeft), room.GetRollerShutter(Bedroom.RollerShutterRight))
            .WithEnabledAtNight()
            .WithSkipIfAnyActuatorIsAlreadyOn(room.GetLamp(Bedroom.LampBedLeft), room.GetLamp(Bedroom.LampBedRight));

            _actuatorFactory.RegisterStateMachine(room, Bedroom.Fan, (s, r) => SetupFan(s, r, hsrel8));

            room.GetButton(Bedroom.ButtonBedLeftInner).WithPressedShortlyAction(() => room.GetLamp(Bedroom.LampBedLeft).SetNextState());
            room.GetButton(Bedroom.ButtonBedLeftInner).WithPressedLongAction(() => room.GetStateMachine(Bedroom.CombinedCeilingLights).SetNextState());
            room.GetButton(Bedroom.ButtonBedLeftOuter).WithPressedShortlyAction(() => room.GetStateMachine(Bedroom.Fan).SetNextState());
            room.GetButton(Bedroom.ButtonBedLeftOuter).WithPressedLongAction(() => room.GetStateMachine(Bedroom.Fan).TryTurnOff());

            room.GetButton(Bedroom.ButtonBedRightInner).WithPressedShortlyAction(() => room.GetLamp(Bedroom.LampBedRight).SetNextState());
            room.GetButton(Bedroom.ButtonBedRightInner).WithPressedLongAction(() => room.GetStateMachine(Bedroom.CombinedCeilingLights).SetNextState());
            room.GetButton(Bedroom.ButtonBedRightOuter).WithPressedShortlyAction(() => room.GetStateMachine(Bedroom.Fan).SetNextState());
            room.GetButton(Bedroom.ButtonBedRightOuter).WithPressedLongAction(() => room.GetStateMachine(Bedroom.Fan).TryTurnOff());

            _synonymService.AddSynonymsForArea(Room.Bedroom, "Schlafzimmer", "Bedroom");
        }
示例#7
0
        public void Apply()
        {
            var input4 = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input4.ToString());
            var input5 = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input5.ToString());

            var hsrel8 = _deviceService.GetDevice <HSREL8>(InstalledDevice.OfficeHSREL8.ToString());
            var hspe8  = _deviceService.GetDevice <HSPE8OutputOnly>(InstalledDevice.UpperFloorAndOfficeHSPE8.ToString());

            //var hsrel8 = (HSREL8)_ccToolsBoardService.RegisterDevice(CCToolsDeviceType.HSRel8, InstalledDevice.OfficeHSREL8.ToString(), 20);
            //var hspe8 = (HSPE8OutputOnly)_ccToolsBoardService.RegisterDevice(CCToolsDeviceType.HSPE8_OutputOnly, InstalledDevice.UpperFloorAndOfficeHSPE8.ToString(), 37);


            var area = _areaService.RegisterArea(Room.Office);

            //var i2CHardwareBridge = _deviceService.GetDevice<I2CHardwareBridge>();
            //const int SensorPin = 6; // ID from MQTT
            //_sensorFactory.RegisterTemperatureSensor(area, Office.TemperatureSensor, i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin));
            //_sensorFactory.RegisterHumiditySensor(area, Office.HumiditySensor, i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin));

            _sensorFactory.RegisterWindow(area, Office.WindowLeftL, input4.GetInput(11));
            _sensorFactory.RegisterWindow(area, Office.WindowLeftR, input4.GetInput(12), input4.GetInput(10));
            _sensorFactory.RegisterWindow(area, Office.WindowRightL, input4.GetInput(8));
            _sensorFactory.RegisterWindow(area, Office.WindowRightR, input4.GetInput(9), input5.GetInput(8));

            _sensorFactory.RegisterMotionDetector(area, Office.MotionDetector, input4.GetInput(13));

            _sensorFactory.RegisterTemperatureSensor(area, Office.TemperatureSensor, new MqttBasedNumericSensorAdapter("sensors-office/temperature", _deviceMessageBroker, _logService));
            _sensorFactory.RegisterHumiditySensor(area, Office.HumiditySensor, new MqttBasedNumericSensorAdapter("sensors-office/humidity", _deviceMessageBroker, _logService));

            _actuatorFactory.RegisterLamp(area, Office.RgbLight, new RgbDeviceAdapter("kitchen-rgb/$patch/rgb", _deviceMessageBroker));

            _actuatorFactory.RegisterSocket(area, Office.SocketFrontLeft, hsrel8.GetOutput(0));
            _actuatorFactory.RegisterSocket(area, Office.SocketFrontRight, hsrel8.GetOutput(6));
            _actuatorFactory.RegisterSocket(area, Office.SocketWindowLeft, hsrel8.GetOutput(10).WithInvertedState());
            _actuatorFactory.RegisterSocket(area, Office.SocketWindowRight, hsrel8.GetOutput(11).WithInvertedState());
            _actuatorFactory.RegisterSocket(area, Office.SocketRearLeftEdge, hsrel8.GetOutput(7));
            _actuatorFactory.RegisterSocket(area, Office.SocketRearLeft, hsrel8.GetOutput(2));
            _actuatorFactory.RegisterSocket(area, Office.SocketRearRight, hsrel8.GetOutput(1));
            _actuatorFactory.RegisterSocket(area, Office.RemoteSocketDesk, _remoteSocketService.GetRemoteSocket("OFFICE_0"));

            _sensorFactory.RegisterButton(area, Office.ButtonUpperLeft, input5.GetInput(0));
            _sensorFactory.RegisterButton(area, Office.ButtonUpperRight, input4.GetInput(15));
            _sensorFactory.RegisterButton(area, Office.ButtonLowerLeft, input5.GetInput(1));
            _sensorFactory.RegisterButton(area, Office.ButtonLowerRight, input4.GetInput(14));

            _sensorFactory.RegisterButton(area, Office.ButtonEdgeLeft, new DeviceBinaryInput("office/edge/button-left", _deviceMessageBroker));
            _sensorFactory.RegisterButton(area, Office.ButtonEdgeRight, new DeviceBinaryInput("office/edge/button-right", _deviceMessageBroker));

            var stateMachine = _actuatorFactory.RegisterStateMachine(area, Office.CombinedCeilingLights, (s, a) => SetupLight(s, hsrel8, hspe8));

            stateMachine.AlternativeStateId = StateMachineStateExtensions.OffStateId;
            stateMachine.ResetStateId       = StateMachineStateExtensions.OffStateId;

            area.GetButton(Office.ButtonUpperLeft)
            .CreatePressedShortTrigger(_messageBroker)
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState(StateMachineStateExtensions.OnStateId));

            area.GetButton(Office.ButtonUpperLeft).CreatePressedLongTrigger(_messageBroker).Attach(() =>
            {
                area.GetComponent(Office.CombinedCeilingLights).TryTurnOff();
                area.GetComponent(Office.SocketRearLeftEdge).TryTurnOff();
                area.GetComponent(Office.SocketRearLeft).TryTurnOff();
                area.GetComponent(Office.SocketFrontLeft).TryTurnOff();
            });

            area.GetButton(Office.ButtonLowerLeft)
            .CreatePressedShortTrigger(_messageBroker)
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState("DeskOnly"));

            area.GetButton(Office.ButtonLowerRight)
            .CreatePressedShortTrigger(_messageBroker)
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState("CouchOnly"));

            area.GetButton(Office.ButtonEdgeRight)
            .CreatePressedShortTrigger(_messageBroker)
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState(StateMachineStateExtensions.OnStateId));

            area.GetButton(Office.ButtonEdgeLeft)
            .CreatePressedShortTrigger(_messageBroker)
            .Attach(() => area.GetComponent(Office.SocketRearRight).TryTogglePowerState());
        }
示例#8
0
        public void Apply()
        {
            var input4 = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input4.ToString());
            var input5 = _deviceService.GetDevice <HSPE16InputOnly>(InstalledDevice.Input5.ToString());

            var hsrel8 = _ccToolsBoardService.RegisterHSREL8(InstalledDevice.OfficeHSREL8.ToString(), new I2CSlaveAddress(20));
            var hspe8  = _ccToolsBoardService.RegisterHSPE8OutputOnly(InstalledDevice.UpperFloorAndOfficeHSPE8.ToString(), new I2CSlaveAddress(37));

            var i2CHardwareBridge = _deviceService.GetDevice <I2CHardwareBridge>();

            const int SensorPin = 2;

            var area = _areaService.RegisterArea(Room.Office);

            _sensorFactory.RegisterWindow(area, Office.WindowLeftL, input4.GetInput(11));
            _sensorFactory.RegisterWindow(area, Office.WindowLeftR, input4.GetInput(12), input4.GetInput(10));
            _sensorFactory.RegisterWindow(area, Office.WindowRightL, input4.GetInput(8));
            _sensorFactory.RegisterWindow(area, Office.WindowRightR, input4.GetInput(9), input5.GetInput(8));

            _sensorFactory.RegisterTemperatureSensor(area, Office.TemperatureSensor, i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin));

            _sensorFactory.RegisterHumiditySensor(area, Office.HumiditySensor,
                                                  i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin));

            _sensorFactory.RegisterMotionDetector(area, Office.MotionDetector, input4.GetInput(13));

            _actuatorFactory.RegisterSocket(area, Office.SocketFrontLeft, hsrel8.GetOutput(0));
            _actuatorFactory.RegisterSocket(area, Office.SocketFrontRight, hsrel8.GetOutput(6));
            _actuatorFactory.RegisterSocket(area, Office.SocketWindowLeft, hsrel8.GetOutput(10).WithInvertedState());
            _actuatorFactory.RegisterSocket(area, Office.SocketWindowRight, hsrel8.GetOutput(11).WithInvertedState());
            _actuatorFactory.RegisterSocket(area, Office.SocketRearLeftEdge, hsrel8.GetOutput(7));
            _actuatorFactory.RegisterSocket(area, Office.SocketRearLeft, hsrel8.GetOutput(2));
            _actuatorFactory.RegisterSocket(area, Office.SocketRearRight, hsrel8.GetOutput(1));
            _actuatorFactory.RegisterSocket(area, Office.RemoteSocketDesk, _remoteSocketService.GetRemoteSocket("OFFICE_0"));

            _sensorFactory.RegisterButton(area, Office.ButtonUpperLeft, input5.GetInput(0));
            _sensorFactory.RegisterButton(area, Office.ButtonUpperRight, input4.GetInput(15));
            _sensorFactory.RegisterButton(area, Office.ButtonLowerLeft, input5.GetInput(1));
            _sensorFactory.RegisterButton(area, Office.ButtonLowerRight, input4.GetInput(14));

            var stateMachine = _actuatorFactory.RegisterStateMachine(area, Office.CombinedCeilingLights, (s, a) => SetupLight(s, hsrel8, hspe8));

            stateMachine.AlternativeStateId = StateMachineStateExtensions.OffStateId;
            stateMachine.ResetStateId       = StateMachineStateExtensions.OffStateId;

            area.GetButton(Office.ButtonUpperLeft)
            .PressedShortTrigger
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState(StateMachineStateExtensions.OnStateId));

            area.GetButton(Office.ButtonUpperLeft).PressedLongTrigger.Attach(() =>
            {
                area.GetComponent(Office.CombinedCeilingLights).TryTurnOff();
                area.GetComponent(Office.SocketRearLeftEdge).TryTurnOff();
                area.GetComponent(Office.SocketRearLeft).TryTurnOff();
                area.GetComponent(Office.SocketFrontLeft).TryTurnOff();
            });

            area.GetButton(Office.ButtonLowerLeft)
            .PressedShortTrigger
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState("DeskOnly"));

            area.GetButton(Office.ButtonLowerRight)
            .PressedShortTrigger
            .Attach(() => area.GetComponent(Office.CombinedCeilingLights).TrySetState("CouchOnly"));
        }