public LEDStripRemote(I2CHardwareBridge i2CHardwareBridge, byte pin)
        {
            if (i2CHardwareBridge == null) throw new ArgumentNullException(nameof(i2CHardwareBridge));

            _i2CHardwareBridge = i2CHardwareBridge;
            _pin = pin;
        }
        public DHT22Accessor(I2CHardwareBridge i2CHardwareBridge, ISchedulerService schedulerService)
        {
            if (i2CHardwareBridge == null) throw new ArgumentNullException(nameof(i2CHardwareBridge));
            if (schedulerService == null) throw new ArgumentNullException(nameof(schedulerService));

            _i2CHardwareBridge = i2CHardwareBridge;
            schedulerService.RegisterSchedule("DHT22Updater", TimeSpan.FromSeconds(10), FetchValues);
        }
        public DHT22Accessor(I2CHardwareBridge.I2CHardwareBridge i2CHardwareBridge, IHomeAutomationTimer timer)
        {
            if (i2CHardwareBridge == null) throw new ArgumentNullException(nameof(i2CHardwareBridge));
            if (timer == null) throw new ArgumentNullException(nameof(timer));

            _i2CHardwareBridge = i2CHardwareBridge;
            timer.Every(TimeSpan.FromSeconds(10)).Do(FetchValues);
        }
        public LPD433MHzSignalSender(I2CHardwareBridge.I2CHardwareBridge i2CHardwareBridge, byte pin, IHttpRequestController httpApiController)
        {
            if (i2CHardwareBridge == null) throw new ArgumentNullException(nameof(i2CHardwareBridge));
            if (httpApiController == null) throw new ArgumentNullException(nameof(httpApiController));

            _i2CHardwareBridge = i2CHardwareBridge;
            _pin = pin;
            httpApiController.Handle(HttpMethod.Post, "433MHz").WithRequiredJsonBody().Using(ApiPost);
        }
        public LPD433MHzSignalSender(I2CHardwareBridge.I2CHardwareBridge i2CHardwareBridge, byte pin, IApiService apiController)
        {
            if (i2CHardwareBridge == null) throw new ArgumentNullException(nameof(i2CHardwareBridge));
            if (apiController == null) throw new ArgumentNullException(nameof(apiController));

            _i2CHardwareBridge = i2CHardwareBridge;
            _pin = pin;

            apiController.Route("433MHz", ApiPost);
        }
Exemple #6
0
        public DHT22Accessor(I2CHardwareBridge i2CHardwareBridge, ISchedulerService schedulerService)
        {
            if (i2CHardwareBridge == null)
            {
                throw new ArgumentNullException(nameof(i2CHardwareBridge));
            }
            if (schedulerService == null)
            {
                throw new ArgumentNullException(nameof(schedulerService));
            }

            _i2CHardwareBridge = i2CHardwareBridge;
            schedulerService.RegisterSchedule("DHT22Updater", TimeSpan.FromSeconds(10), FetchValues);
        }
        protected override void Initialize()
        {
            InitializeHealthMonitor(22);

            var pi2PortController = new Pi2PortController();
            
            var i2CBus = new I2cBusAccessor(NotificationHandler);

            IWeatherStation weatherStation = CreateWeatherStation();

            var i2CHardwareBridge = new I2CHardwareBridge(50, i2CBus);
            var sensorBridgeDriver = new DHT22Accessor(i2CHardwareBridge, Timer);

            var ioBoardManager = new IOBoardManager(HttpApiController, NotificationHandler);
            var ccToolsBoardController = new CCToolsBoardController(i2CBus, ioBoardManager, NotificationHandler);

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

            RemoteSwitchController remoteSwitchController = SetupRemoteSwitchController(i2CHardwareBridge);

            var home = new Home(Timer, HealthMonitor, weatherStation, HttpApiController, NotificationHandler);

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

            home.PublishStatisticsNotification();

            AttachAzureEventHubPublisher(home);

            var localCsvFileWriter = new LocalCsvFileWriter(NotificationHandler);
            localCsvFileWriter.ConnectActuators(home);

            var ioBoardsInterruptMonitor = new InterruptMonitor(pi2PortController.GetInput(4));
            Timer.Tick += (s, e) => ioBoardsInterruptMonitor.Poll();
            ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ioBoardManager.PollInputBoardStates();
        }
        private RemoteSwitchController SetupRemoteSwitchController(I2CHardwareBridge i2CHardwareBridge)
        {
            const int LDP433MhzSenderPin = 10;

            var ldp433MHzSender = new LPD433MHzSignalSender(i2CHardwareBridge, LDP433MhzSenderPin, HttpApiController);
            var remoteSwitchController = new RemoteSwitchController(ldp433MHzSender, Timer);
            
            var brennenstuhlCodes = new BrennenstuhlCodeSequenceProvider();
            remoteSwitchController.Register(
                0,
                brennenstuhlCodes.GetSequence(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A, RemoteSwitchCommand.TurnOn),
                brennenstuhlCodes.GetSequence(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A, RemoteSwitchCommand.TurnOff));

            return remoteSwitchController;
        }
            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);
            }