Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        protected override void Initialize()
        {
            InitializeHealthMonitor(22);

            var pi2PortController = new Pi2PortController();

            AddDevice(new BuiltInI2CBus(Logger));
            AddDevice(new I2CHardwareBridge(new DeviceId("HB"), new I2CSlaveAddress(50), Device <II2CBus>(), Timer));
            AddDevice(new OpenWeatherMapWeatherStation(OpenWeatherMapWeatherStation.DefaultDeviceId, Timer, HttpApiController, Logger));

            var ccToolsBoardController = new CCToolsBoardController(this, Device <II2CBus>(), HttpApiController, Logger);

            var configurationParser = new ConfigurationParser(this);

            configurationParser.RegisterConfigurationExtender(new CCToolsConfigurationExtender(configurationParser, this));
            configurationParser.ParseConfiguration();

            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input0, new I2CSlaveAddress(42));
            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input1, new I2CSlaveAddress(43));
            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input2, new I2CSlaveAddress(47));
            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input3, new I2CSlaveAddress(45));
            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input4, new I2CSlaveAddress(46));
            ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input5, new I2CSlaveAddress(44));

            RemoteSocketController remoteSwitchController = SetupRemoteSwitchController();

            new BedroomConfiguration(this, ccToolsBoardController).Setup();
            new OfficeConfiguration().Setup(this, ccToolsBoardController, remoteSwitchController);
            new UpperBathroomConfiguration(this, ccToolsBoardController).Setup();
            new ReadingRoomConfiguration().Setup(this, ccToolsBoardController);
            new ChildrensRoomRoomConfiguration().Setup(this, ccToolsBoardController);
            new KitchenConfiguration().Setup(this, ccToolsBoardController);
            new FloorConfiguration().Setup(this, ccToolsBoardController);
            new LowerBathroomConfiguration().Setup(this);
            new StoreroomConfiguration().Setup(this, ccToolsBoardController);
            new LivingRoomConfiguration().Setup(this, ccToolsBoardController);

            //AttachAzureEventHubPublisher(home);

            var localCsvFileWriter = new CsvHistory(Logger, HttpApiController);

            localCsvFileWriter.ConnectActuators(this);
            localCsvFileWriter.ExposeToApi(HttpApiController);

            var ioBoardsInterruptMonitor = new InterruptMonitor(pi2PortController.GetInput(4), Logger);

            ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates();
            ioBoardsInterruptMonitor.StartPollingAsync();
        }
Пример #4
0
        public override void Setup()
        {
            var hsrel8 = CCToolsBoardController.CreateHSREL8(InstalledDevice.OfficeHSREL8, new I2CSlaveAddress(20));
            var hspe8  = CCToolsBoardController.CreateHSPE8OutputOnly(InstalledDevice.UpperFloorAndOfficeHSPE8, new I2CSlaveAddress(37));
            var input4 = Controller.Device <HSPE16InputOnly>(InstalledDevice.Input4);
            var input5 = Controller.Device <HSPE16InputOnly>(InstalledDevice.Input5);

            const int SensorPin = 2;

            var i2cHardwareBridge = Controller.GetDevice <I2CHardwareBridge>();

            var room = Controller.CreateArea(Room.Office)
                       .WithMotionDetector(Office.MotionDetector, input4.GetInput(13))
                       .WithTemperatureSensor(Office.TemperatureSensor, i2cHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin))
                       .WithHumiditySensor(Office.HumiditySensor, i2cHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin))
                       .WithSocket(Office.SocketFrontLeft, hsrel8.GetOutput(0))
                       .WithSocket(Office.SocketFrontRight, hsrel8.GetOutput(6))
                       .WithSocket(Office.SocketWindowLeft, hsrel8.GetOutput(10).WithInvertedState())
                       .WithSocket(Office.SocketWindowRight, hsrel8.GetOutput(11).WithInvertedState())
                       .WithSocket(Office.SocketRearLeftEdge, hsrel8.GetOutput(7))
                       .WithSocket(Office.SocketRearLeft, hsrel8.GetOutput(2))
                       .WithSocket(Office.SocketRearRight, hsrel8.GetOutput(1))
                       .WithButton(Office.ButtonUpperLeft, input5.GetInput(0))
                       .WithButton(Office.ButtonLowerLeft, input5.GetInput(1))
                       .WithButton(Office.ButtonLowerRight, input4.GetInput(14))
                       .WithButton(Office.ButtonUpperRight, input4.GetInput(15))
                       .WithWindow(Office.WindowLeft, w => w.WithLeftCasement(input4.GetInput(11)).WithRightCasement(input4.GetInput(12), input4.GetInput(10)))
                       .WithWindow(Office.WindowRight, w => w.WithLeftCasement(input4.GetInput(8)).WithRightCasement(input4.GetInput(9), input5.GetInput(8)))
                       .WithSocket(Office.RemoteSocketDesk, RemoteSocketController.GetOutput(0))
                       .WithStateMachine(Office.CombinedCeilingLights, (s, a) => SetupLight(s, hsrel8, hspe8, a));

            room.GetButton(Office.ButtonUpperLeft).GetPressedLongTrigger().Attach(() =>
            {
                room.GetStateMachine(Office.CombinedCeilingLights).TryTurnOff();
                room.Socket(Office.SocketRearLeftEdge).TryTurnOff();
                room.Socket(Office.SocketRearLeft).TryTurnOff();
                room.Socket(Office.SocketFrontLeft).TryTurnOff();
            });
        }
Пример #5
0
        public void Setup(Controller controller, CCToolsBoardController ccToolsController, RemoteSocketController remoteSwitchController)
        {
            var hsrel8 = ccToolsController.CreateHSREL8(Device.OfficeHSREL8, new I2CSlaveAddress(20));
            var hspe8  = ccToolsController.CreateHSPE8OutputOnly(Device.UpperFloorAndOfficeHSPE8, new I2CSlaveAddress(37));
            var input4 = controller.Device <HSPE16InputOnly>(Device.Input4);
            var input5 = controller.Device <HSPE16InputOnly>(Device.Input5);

            const int SensorPin = 2;

            var i2cHardwareBridge = controller.Device <I2CHardwareBridge>();

            var office = controller.CreateArea(Room.Office)
                         .WithMotionDetector(Office.MotionDetector, input4.GetInput(13))
                         .WithTemperatureSensor(Office.TemperatureSensor, i2cHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin))
                         .WithHumiditySensor(Office.HumiditySensor, i2cHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin))
                         .WithLamp(Office.LightCeilingFrontRight, hsrel8.GetOutput(8).WithInvertedState())
                         .WithLamp(Office.LightCeilingFrontMiddle, hspe8.GetOutput(2).WithInvertedState())
                         .WithLamp(Office.LightCeilingFrontLeft, hspe8.GetOutput(0).WithInvertedState())
                         .WithLamp(Office.LightCeilingMiddleRight, hsrel8.GetOutput(9).WithInvertedState())
                         .WithLamp(Office.LightCeilingMiddleMiddle, hspe8.GetOutput(3).WithInvertedState())
                         .WithLamp(Office.LightCeilingMiddleLeft, hspe8.GetOutput(1).WithInvertedState())
                         .WithLamp(Office.LightCeilingRearRight, hsrel8.GetOutput(12).WithInvertedState())
                         .WithLamp(Office.LightCeilingRearLeft, hsrel8.GetOutput(13).WithInvertedState())
                         .WithSocket(Office.SocketFrontLeft, hsrel8.GetOutput(0))
                         .WithSocket(Office.SocketFrontRight, hsrel8.GetOutput(6))
                         .WithSocket(Office.SocketWindowLeft, hsrel8.GetOutput(10).WithInvertedState())
                         .WithSocket(Office.SocketWindowRight, hsrel8.GetOutput(11).WithInvertedState())
                         .WithSocket(Office.SocketRearLeftEdge, hsrel8.GetOutput(7))
                         .WithSocket(Office.SocketRearLeft, hsrel8.GetOutput(2))
                         .WithSocket(Office.SocketRearRight, hsrel8.GetOutput(1))
                         .WithButton(Office.ButtonUpperLeft, input5.GetInput(0))
                         .WithButton(Office.ButtonLowerLeft, input5.GetInput(1))
                         .WithButton(Office.ButtonLowerRight, input4.GetInput(14))
                         .WithButton(Office.ButtonUpperRight, input4.GetInput(15))
                         .WithWindow(Office.WindowLeft, w => w.WithLeftCasement(input4.GetInput(11)).WithRightCasement(input4.GetInput(12), input4.GetInput(10)))
                         .WithWindow(Office.WindowRight, w => w.WithLeftCasement(input4.GetInput(8)).WithRightCasement(input4.GetInput(9), input5.GetInput(8)))
                         .WithSocket(Office.RemoteSocketDesk, remoteSwitchController.GetOutput(0))
                         .WithStateMachine(Office.CombinedCeilingLights, SetupLight);

            office.Button(Office.ButtonUpperLeft).WithLongAction(() =>
            {
                office.StateMachine(Office.CombinedCeilingLights).TurnOff();
                office.Socket(Office.SocketRearLeftEdge).TurnOff();
                office.Socket(Office.SocketRearLeft).TurnOff();
                office.Socket(Office.SocketFrontLeft).TurnOff();
            });
        }
Пример #6
0
        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();
        }
Пример #7
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();
            };
        }