Beispiel #1
0
        public LEDStripRemote(I2CHardwareBridge i2CHardwareBridge, byte pin)
        {
            if (i2CHardwareBridge == null)
            {
                throw new ArgumentNullException(nameof(i2CHardwareBridge));
            }

            _i2CHardwareBridge = i2CHardwareBridge;
            _pin = pin;
        }
Beispiel #2
0
        private void SetupLEDStripRemote(I2CHardwareBridge i2CHardwareBridge, VirtualButtonGroup group)
        {
            var ledStripRemote = new LEDStripRemote(i2CHardwareBridge, 4);

            group.WithButton(new ActuatorId("on"), b => b.WithShortAction(() => ledStripRemote.TurnOn()))
            .WithButton(new ActuatorId("off"), b => b.WithShortAction(() => ledStripRemote.TurnOff()))
            .WithButton(new ActuatorId("white"), b => b.WithShortAction(() => ledStripRemote.TurnWhite()))

            .WithButton(new ActuatorId("red1"), b => b.WithShortAction(() => ledStripRemote.TurnRed1()))
            .WithButton(new ActuatorId("green1"), b => b.WithShortAction(() => ledStripRemote.TurnGreen1()))
            .WithButton(new ActuatorId("blue1"), b => b.WithShortAction(() => ledStripRemote.TurnBlue1()));
        }
        private void SetupLEDStripRemote(I2CHardwareBridge i2CHardwareBridge, IArea area)
        {
            const int SenderPin = 4;

            var ledStripRemote = new LEDStripRemote(i2CHardwareBridge, SenderPin);

            area.WithVirtualButton(ExampleRoom.ButtonStripOn, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnOn()))
            .WithVirtualButton(ExampleRoom.ButtonStripOff, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnOff()))
            .WithVirtualButton(ExampleRoom.ButtonStripWhite, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnWhite()))

            .WithVirtualButton(ExampleRoom.ButtonStripRed, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnRed1()))
            .WithVirtualButton(ExampleRoom.ButtonStripGreen, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnGreen1()))
            .WithVirtualButton(ExampleRoom.ButtonStripBlue, b => b.WithPressedShortlyAction(() => ledStripRemote.TurnBlue1()));
        }
Beispiel #4
0
            public Task ApplyAsync()
            {
                _synonymService.TryLoadPersistedSynonyms();

                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input0, new I2CSlaveAddress(42));
                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input1, new I2CSlaveAddress(43));
                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input2, new I2CSlaveAddress(47));
                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input3, new I2CSlaveAddress(45));
                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input4, new I2CSlaveAddress(46));
                _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input5, new I2CSlaveAddress(44));

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

                _deviceService.AddDevice(i2CHardwareBridge);

                _remoteSocketService.Sender = new LPD433MHzSignalSender(i2CHardwareBridge, LDP433MhzSenderPin, _apiService);
                var brennenstuhl = new BrennenstuhlCodeSequenceProvider();

                _remoteSocketService.RegisterRemoteSocket(0, brennenstuhl.GetSequencePair(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.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();

                _synonymService.RegisterDefaultComponentStateSynonyms();

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

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

                return(Task.FromResult(0));
            }
Beispiel #5
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));
        }
 public I2CHardwareBridgeLdp433MhzBridgeAdapter(I2CHardwareBridge i2CHardwareBridge, byte pin)
 {
     _i2CHardwareBridge = i2CHardwareBridge ?? throw new ArgumentNullException(nameof(i2CHardwareBridge));
     _pin = pin;
 }
Beispiel #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();
            };
        }