protected void InitializeHealthMonitor(int pi2GpioPinWithLed)
        {
            var pi2PortController = new Pi2PortController();
            var ledPin            = pi2PortController.GetOutput(pi2GpioPinWithLed);

            _healthMonitor = new HealthMonitor(ledPin, Timer, HttpApiController);
        }
        protected override void Initialize()
        {
            InitializeHealthMonitor(LedGpio);

            AddDevice(new BuiltInI2CBus());

            var piPortController = new Pi2PortController();

            AddDevice(piPortController);

            var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>());

            AddDevice(ccToolsBoardController);

            // Setup the remote switch 433Mhz sender which is attached to the I2C bus (Arduino Nano).
            AddDevice(new I2CHardwareBridge(new I2CSlaveAddress(50), GetDevice <II2CBus>(), Timer));

            RegisterService(new SynonymService());
            RegisterService(new OpenWeatherMapWeatherService(Timer, ApiController));

            SetupRoom();

            GetService <SynonymService>().TryLoadPersistedSynonyms();
            GetService <SynonymService>().RegisterDefaultComponentStateSynonyms(this);

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

            SetupDemo();
        }
        protected override void Initialize()
        {
            InitializeHealthMonitor(22);

            var pi2PortController = new Pi2PortController();

            AddDevice(new BuiltInI2CBus(Logger));
            AddDevice(new OpenWeatherMapWeatherStation(OpenWeatherMapWeatherStation.DefaultDeviceId, Timer, HttpApiController, Logger));

            var ccToolsFactory = new CCToolsBoardController(this, Device <II2CBus>(), HttpApiController, Logger);
            var hsrt16         = ccToolsFactory.CreateHSRT16(Device.CellarHSRT16, new I2CSlaveAddress(32));

            var garden = this.CreateArea(RoomId.Garden)
                         .WithLamp(Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15])
                         .WithLamp(Garden.LampGarage, hsrt16[HSRT16Pin.Relay14])
                         .WithLamp(Garden.LampTap, hsrt16[HSRT16Pin.Relay13])
                         .WithLamp(Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12])
                         .WithLamp(Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11])
                         .WithSocket(Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10])
                         // 9 = free
                         .WithLamp(Garden.LampParkingLot, new LogicalBinaryOutput().WithOutput(hsrt16[HSRT16Pin.Relay8]).WithOutput(hsrt16[HSRT16Pin.Relay6]).WithOutput(hsrt16[HSRT16Pin.Relay7]))
                         .WithButton(Garden.Button, pi2PortController.GetInput(4).WithInvertedState())
                         .WithStateMachine(Garden.StateMachine, SetupStateMachine);

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

            garden.SetupConditionalOnAutomation()
            .WithActuator(garden.Lamp(Garden.LampParkingLot))
            .WithOnAtNightRange(Device <IWeatherStation>())
            .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00"));

            Timer.Tick += (s, e) => { pi2PortController.PollOpenInputPorts(); };
        }
Beispiel #4
0
        protected override async Task ConfigureAsync()
        {
            AddDevice(new BuiltInI2CBus());

            var pi2PortController      = new Pi2PortController();
            var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>());

            AddDevice(pi2PortController);
            AddDevice(ccToolsBoardController);

            ServiceLocator.RegisterService(
                typeof(OpenWeatherMapWeatherService),
                new OpenWeatherMapService(ApiController,
                                          ServiceLocator.GetService <IDateTimeService>(),
                                          ServiceLocator.GetService <ISchedulerService>(),
                                          ServiceLocator.GetService <ISystemInformationService>()));

            var configurationParser = new ConfigurationParser(this);

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

            InitializeAzureCloudApiEndpoint();

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

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

            await base.ConfigureAsync();
        }
        protected override void Initialize()
        {
            InitializeHealthMonitor(LedGpio);

            var pi2PortController      = new Pi2PortController();
            var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>());

            AddDevice(new BuiltInI2CBus());
            AddDevice(pi2PortController);
            AddDevice(ccToolsBoardController);

            RegisterService(new OpenWeatherMapWeatherService(Timer, ApiController));

            var configurationParser = new ConfigurationParser(this);

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

            InitializeAzureCloudApiEndpoint();

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

            ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates();
            ioBoardsInterruptMonitor.StartPollingAsync();
        }
Beispiel #6
0
        private void InitializeHealthMonitor()
        {
            IBinaryOutput ledPin = null;

            if (_statusLedNumber.HasValue)
            {
                var pi2PortController = new Pi2PortController();
                ledPin = pi2PortController.GetOutput(_statusLedNumber.Value);
            }

            ServiceLocator.RegisterService(typeof(HealthService), new HealthService(ledPin, Timer, ServiceLocator.GetService <ISystemInformationService>()));
        }
Beispiel #7
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();
        }
Beispiel #8
0
        protected override async Task ConfigureAsync()
        {
            var pi2PortController = new Pi2PortController();

            AddDevice(new BuiltInI2CBus());

            ServiceLocator.RegisterService(typeof(OpenWeatherMapWeatherService),
                                           new OpenWeatherMapService(ApiController,
                                                                     ServiceLocator.GetService <IDateTimeService>(),
                                                                     ServiceLocator.GetService <ISchedulerService>(),
                                                                     ServiceLocator.GetService <ISystemInformationService>()));

            var ccToolsFactory = new CCToolsBoardController(this, GetDevice <II2CBus>());
            var hsrt16         = ccToolsFactory.CreateHSRT16(Device.CellarHSRT16, new I2CSlaveAddress(32));

            var garden = this.CreateArea(RoomId.Garden)
                         .WithLamp(Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15])
                         .WithLamp(Garden.LampGarage, hsrt16[HSRT16Pin.Relay14])
                         .WithLamp(Garden.LampTap, hsrt16[HSRT16Pin.Relay13])
                         .WithLamp(Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12])
                         .WithLamp(Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11])
                         .WithSocket(Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10])
                         // 9 = free
                         .WithLamp(Garden.LampParkingLot, new LogicalBinaryOutput().WithOutput(hsrt16[HSRT16Pin.Relay8]).WithOutput(hsrt16[HSRT16Pin.Relay6]).WithOutput(hsrt16[HSRT16Pin.Relay7]))
                         .WithButton(Garden.Button, pi2PortController.GetInput(4).WithInvertedState())
                         .WithStateMachine(Garden.StateMachine, SetupStateMachine);

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

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

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

            await base.ConfigureAsync();
        }
Beispiel #9
0
        protected override async Task ConfigureAsync()
        {
            AddDevice(new BuiltInI2CBus());

            var piPortController = new Pi2PortController();

            AddDevice(piPortController);

            var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>());

            AddDevice(ccToolsBoardController);

            // Setup the remote switch 433Mhz sender which is attached to the I2C bus (Arduino Nano).
            AddDevice(new I2CHardwareBridge(new I2CSlaveAddress(50), GetDevice <II2CBus>(), ServiceLocator.GetService <ISchedulerService>()));

            ServiceLocator.RegisterService(typeof(SynonymService), new SynonymService());
            ServiceLocator.RegisterService(typeof(OpenWeatherMapService),
                                           new OpenWeatherMapService(ApiController,
                                                                     ServiceLocator.GetService <IDateTimeService>(),
                                                                     ServiceLocator.GetService <ISchedulerService>(),
                                                                     ServiceLocator.GetService <ISystemInformationService>()));

            SetupRoom();

            ServiceLocator.GetService <SynonymService>().TryLoadPersistedSynonyms();
            ServiceLocator.GetService <SynonymService>().RegisterDefaultComponentStateSynonyms(this);

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

            SetupDemo();

            await base.ConfigureAsync();
        }
Beispiel #10
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();
            };
        }