Exemple #1
0
        private RemoteSocketController SetupRemoteSwitchController()
        {
            const int LDP433MhzSenderPin = 10;

            var i2cHardwareBridge = GetDevice <I2CHardwareBridge>();
            var brennenstuhl      = new BrennenstuhlCodeSequenceProvider();
            var ldp433MHzSender   = new LPD433MHzSignalSender(i2cHardwareBridge, LDP433MhzSenderPin, ApiController);

            var remoteSwitchController = new RemoteSocketController(ldp433MHzSender, Timer)
                                         .WithRemoteSocket(0, brennenstuhl.GetSequencePair(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A));

            return(remoteSwitchController);
        }
Exemple #2
0
        private RemoteSocketController SetupRemoteSwitchController()
        {
            const int LDP433MhzSenderPin = 10;

            var i2cHardwareBridge = Device <I2CHardwareBridge>();
            var bc = new BrennenstuhlCodeSequenceProvider();
            var ldp433MHzSender = new LPD433MHzSignalSender(i2cHardwareBridge, LDP433MhzSenderPin, HttpApiController);

            var remoteSwitchController = new RemoteSocketController(new DeviceId("RemoteSocketController"), ldp433MHzSender, Timer)
                                         .WithRemoteSocket(0, bc.GetSequence(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A, RemoteSocketCommand.TurnOn), bc.GetSequence(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A, RemoteSocketCommand.TurnOff));

            return(remoteSwitchController);
        }
        private void SetupRoom()
        {
            var ccToolsBoardController = GetDevice <CCToolsBoardController>();

            var hspe16 = ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.HSPE16, new I2CSlaveAddress(41));
            var hsrel8 = ccToolsBoardController.CreateHSREL8(InstalledDevice.HSRel8, new I2CSlaveAddress(40));
            var hsrel5 = ccToolsBoardController.CreateHSREL5(InstalledDevice.HSRel5, new I2CSlaveAddress(56));

            var i2CHardwareBridge  = GetDevice <I2CHardwareBridge>();
            var remoteSwitchSender = new LPD433MHzSignalSender(i2CHardwareBridge, I2CHardwareBridge433MHzSenderPin, ApiController);

            var intertechno  = new IntertechnoCodeSequenceProvider();
            var brennenstuhl = new BrennenstuhlCodeSequenceProvider();

            var remoteSwitchController = new RemoteSocketController(remoteSwitchSender, Timer)
                                         .WithRemoteSocket(0, intertechno.GetSequencePair(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1))
                                         .WithRemoteSocket(1, intertechno.GetSequencePair(IntertechnoSystemCode.B, IntertechnoUnitCode.Unit1))
                                         .WithRemoteSocket(2, brennenstuhl.GetSequencePair(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.B))
                                         .WithRemoteSocket(3, brennenstuhl.GetSequencePair(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.C));

            const int SensorPin = 5;

            var area = this.CreateArea(Room.ExampleRoom)
                       .WithTemperatureSensor(ExampleRoom.TemperatureSensor, i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin))
                       .WithHumiditySensor(ExampleRoom.HumiditySensor, i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin))
                       .WithMotionDetector(ExampleRoom.MotionDetector, hspe16[HSPE16Pin.GPIO8])

                       .WithLamp(ExampleRoom.Lamp1, remoteSwitchController.GetOutput(0))
                       .WithLamp(ExampleRoom.Lamp2, remoteSwitchController.GetOutput(1))

                       .WithSocket(ExampleRoom.Socket1, hsrel5[HSREL5Pin.Relay0])
                       .WithSocket(ExampleRoom.Socket2, hsrel5[HSREL5Pin.Relay4])
                       .WithSocket(ExampleRoom.BathroomFan, hsrel5[HSREL5Pin.Relay3])
                       .WithLamp(ExampleRoom.Lamp3, hsrel8[HSREL8Pin.Relay0])
                       .WithLamp(ExampleRoom.Lamp4, hsrel8[HSREL8Pin.Relay1])
                       .WithLamp(ExampleRoom.Lamp5, hsrel8[HSREL8Pin.Relay2])
                       .WithLamp(ExampleRoom.Lamp6, hsrel8[HSREL8Pin.Relay3])
                       .WithLamp(ExampleRoom.Lamp7, remoteSwitchController.GetOutput(2))
                       .WithLamp(ExampleRoom.Lamp8, remoteSwitchController.GetOutput(3))

                       .WithRollerShutter(ExampleRoom.RollerShutter, hsrel8[HSREL8Pin.Relay4], hsrel8[HSREL8Pin.Relay5])

                       .WithButton(ExampleRoom.Button1, hspe16[HSPE16Pin.GPIO1])
                       .WithButton(ExampleRoom.Button2, hspe16[HSPE16Pin.GPIO2])

                       .WithStateMachine(ExampleRoom.CeilingFan, (sm, r) => SetupCeilingFan(sm))
                       .WithWindow(ExampleRoom.Window, w => w.WithCenterCasement(hspe16[HSPE16Pin.GPIO0]));

            area.GetButton(ExampleRoom.Button1).GetPressedShortlyTrigger().Attach(area.GetLamp(ExampleRoom.Lamp5).GetSetNextStateAction());
            area.GetButton(ExampleRoom.Button1).ConnectToggleActionWith(area.GetLamp(ExampleRoom.Lamp6), ButtonPressedDuration.Long);

            area.GetStateMachine(ExampleRoom.CeilingFan).ConnectMoveNextAndToggleOffWith(area.GetButton(ExampleRoom.Button2));

            SetupHumidityDependingLamp(area.GetHumiditySensor(ExampleRoom.HumiditySensor), area.GetLamp(ExampleRoom.Lamp7));

            area.SetupTurnOnAndOffAutomation()
            .WithTrigger(area.GetMotionDetector(ExampleRoom.MotionDetector))
            .WithTarget(area.GetStateMachine(ExampleRoom.BathroomFan))
            //.WithTarget(area.GetLamp(ExampleRoom.Lamp2))
            .WithOnDuration(TimeSpan.FromSeconds(10));

            SetupLEDStripRemote(i2CHardwareBridge, area);

            RegisterSynonyms();
        }
Exemple #4
0
        protected override void Initialize()
        {
            // Setup the health monitor which tracks the average time and let an LED blink if everything is healthy.
            InitializeHealthMonitor(LedGpio);

            // Setup the controller which provides ports from the GPIOs of the Pi2.
            var pi2PortController = new Pi2PortController();

            // Setup the wrapper for I2C bus access.
            var i2CBus = new BuiltInI2CBus(Logger);

            // Setup the controller which creates ports for IO boards from CCTools (or based on PCF8574/MAX7311/PCA9555D).
            var ccToolsBoardController = new CCToolsBoardController(this, i2CBus, HttpApiController, Logger);
            var hspe16 = ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.HSPE16, new I2CSlaveAddress(41));
            var hsrel8 = ccToolsBoardController.CreateHSREL8(InstalledDevice.HSRel8, new I2CSlaveAddress(40));
            var hsrel5 = ccToolsBoardController.CreateHSREL5(InstalledDevice.HSRel5, new I2CSlaveAddress(56));

            // Setup the remote switch 433Mhz sender which is attached to the I2C bus (Arduino Nano).
            var i2CHardwareBridge  = new I2CHardwareBridge(new DeviceId("HB"), new I2CSlaveAddress(50), i2CBus, Timer);
            var remoteSwitchSender = new LPD433MHzSignalSender(i2CHardwareBridge, I2CHardwareBridge433MHzSenderPin, HttpApiController);

            // Setup the controller which creates ports for wireless sockets (433Mhz).
            var ic = new IntertechnoCodeSequenceProvider();
            var remoteSwitchController = new RemoteSocketController(new DeviceId("RemoteSocketController"), remoteSwitchSender, Timer)
                                         .WithRemoteSocket(0, ic.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSocketCommand.TurnOn), ic.GetSequence(IntertechnoSystemCode.A, IntertechnoUnitCode.Unit1, RemoteSocketCommand.TurnOff));

            // Setup the weather station which provides sunrise and sunset information.
            AddDevice(new OpenWeatherMapWeatherStation(OpenWeatherMapWeatherStation.DefaultDeviceId, Timer, HttpApiController, Logger));

            // Add the example area with the example actuators.
            var area = this.CreateArea(Room.ExampleRoom)
                       .WithTemperatureSensor(ExampleRoom.TemperatureSensor, i2CHardwareBridge.DHT22Accessor.GetTemperatureSensor(5))
                       .WithHumiditySensor(ExampleRoom.HumiditySensor, i2CHardwareBridge.DHT22Accessor.GetHumiditySensor(5))
                       .WithMotionDetector(ExampleRoom.MotionDetector, hspe16.GetInput(8))
                       .WithWindow(ExampleRoom.Window, w => w.WithCenterCasement(hspe16.GetInput(0)))
                       .WithLamp(ExampleRoom.Lamp1, remoteSwitchController.GetOutput(0))
                       .WithSocket(ExampleRoom.Socket1, hsrel5.GetOutput(0))
                       .WithSocket(ExampleRoom.Socket2, hsrel5.GetOutput(4))
                       .WithSocket(ExampleRoom.BathroomFan, hsrel5.GetOutput(3))
                       .WithLamp(ExampleRoom.Lamp2, hsrel8.GetOutput(0))
                       .WithLamp(ExampleRoom.Lamp3, hsrel8.GetOutput(1))
                       .WithLamp(ExampleRoom.Lamp4, hsrel8.GetOutput(2))
                       .WithLamp(ExampleRoom.Lamp5, hsrel8.GetOutput(3))
                       .WithLamp(ExampleRoom.Lamp6, hsrel8.GetOutput(4))
                       .WithButton(ExampleRoom.Button1, hspe16.GetInput(1))
                       .WithButton(ExampleRoom.Button2, hspe16.GetInput(2))
                       .WithVirtualButtonGroup(ExampleRoom.LedStripRemote, g => SetupLEDStripRemote(i2CHardwareBridge, g))
                       .WithStateMachine(ExampleRoom.CeilingFan, (sm, r) => SetupCeilingFan(sm));

            area.Lamp(ExampleRoom.Lamp5).ConnectToggleActionWith(area.Button(ExampleRoom.Button1));
            area.Lamp(ExampleRoom.Lamp6).ConnectToggleActionWith(area.Button(ExampleRoom.Button1), ButtonPressedDuration.Long);
            area.StateMachine(ExampleRoom.CeilingFan).ConnectMoveNextAndToggleOffWith(area.Button(ExampleRoom.Button2));

            SetupHumidityDependingOutput(area.HumiditySensor(ExampleRoom.HumiditySensor), hsrel8.GetOutput(5));

            area.SetupTurnOnAndOffAutomation()
            .WithTrigger(area.MotionDetector(ExampleRoom.MotionDetector))
            .WithTarget(area.BinaryStateOutput(ExampleRoom.BathroomFan))
            .WithTarget(area.BinaryStateOutput(ExampleRoom.Lamp2))
            .WithOnDuration(TimeSpan.FromSeconds(10));

            Timer.Tick += (s, e) =>
            {
                pi2PortController.PollOpenInputPorts();
                ccToolsBoardController.PollInputBoardStates();
            };
        }