public RollerShutter(
            string id, 
            IBinaryOutput powerOutput, 
            IBinaryOutput directionOutput, 
            TimeSpan autoOffTimeout,
            int maxPosition,
            IHttpRequestController httpApiController,
            INotificationHandler notificationHandler, 
            IHomeAutomationTimer timer)
            : base(id, httpApiController, notificationHandler)
        {
            if (id == null) throw new ArgumentNullException(nameof(id));
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            _powerGpioPin = powerOutput;
            _directionGpioPin = directionOutput;
            _autoOffTimeout = autoOffTimeout;
            _positionMax = maxPosition;
            _timer = timer;

            //TODO: StartMoveUp();

            timer.Tick += (s, e) => UpdatePosition(e);
        }
        public LogicalBinaryOutput WithOutput(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _outputs.Add(output);
            return this;
        }
示例#3
0
        public HealthService(
            ControllerOptions controllerOptions,
            IPi2GpioService pi2GpioService,
            ITimerService timerService,
            ISystemInformationService systemInformationService)
        {
            if (controllerOptions == null)
            {
                throw new ArgumentNullException(nameof(controllerOptions));
            }
            if (timerService == null)
            {
                throw new ArgumentNullException(nameof(timerService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            _systemInformationService = systemInformationService;

            if (controllerOptions.StatusLedNumber.HasValue)
            {
                _led = pi2GpioService.GetOutput(controllerOptions.StatusLedNumber.Value);
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timerService.Tick += Tick;
        }
        public BinaryOutputWithState(IBinaryOutput output, BinaryState state)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            Output = output;
            State = state;
        }
        public static IArea WithRollerShutter(this IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                ComponentIdFactory.Create(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                area.Controller.Timer,
                area.Controller.ServiceLocator.GetService <ISchedulerService>());

            area.AddComponent(rollerShutter);
            return(area);
        }
示例#6
0
        public RollerShutter(
            ActuatorId id,
            IBinaryOutput powerOutput,
            IBinaryOutput directionOutput,
            IHttpRequestController httpApiController,
            ILogger logger,
            IHomeAutomationTimer timer)
            : base(id, httpApiController, logger)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            _powerGpioPin     = powerOutput;
            _directionGpioPin = directionOutput;
            _timer            = timer;

            timer.Tick += (s, e) => UpdatePosition(e);

            base.Settings = new RollerShutterSettings(id, logger);
        }
        public StateMachineState WithPort(IBinaryOutput output, BinaryState state)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _outputs.Add(new Tuple<IBinaryOutput, BinaryState>(output, state));
            return this;
        }
示例#8
0
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                _timerService,
                _schedulerService,
                _settingsService);

            area.AddComponent(rollerShutter);

            return(rollerShutter);
        }
示例#9
0
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                $"{area.Id}.{id}",
                new PortBasedRollerShutterAdapter(powerOutput, directionOutput),
                _timerService,
                _settingsService);

            area.RegisterComponent(rollerShutter);

            return(rollerShutter);
        }
        public BinaryStateOutputActuator(string id, IBinaryOutput output, IHttpRequestController httpRequestController,
            INotificationHandler notificationHandler) : base(id, httpRequestController, notificationHandler)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _output = output;
            SetStateInternal(BinaryActuatorState.Off, new ForceUpdateStateParameter());
        }
示例#11
0
        private IComponent ParseCustomBinaryStateOutputActuator(XElement element)
        {
            IBinaryOutput output = Parser.ParseBinaryOutput(element.GetMandatorySingleChildElementOrFromContainer("Output"));

            return(new CustomBinaryStateActuator(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedBinaryStateEndpoint(output)));
        }
        public PortBasedRollerShutterEndpoint(IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            _powerOutput = powerOutput;
            _directionOutput = directionOutput;
        }
示例#13
0
        public StateMachineState WithHighOutput(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(WithOutput(output, BinaryState.High));
        }
        public PortBasedBinaryStateEndpoint(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _output = output;
        }
示例#15
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public BinaryOutputItem(IBinaryOutput entity, IBinaryOutputState state, ItemContext context, bool interactive)
     : base(entity, false, context)
 {
     this.state = state;
     if (interactive)
     {
         MouseHandler = new ClickHandler(null, state);
     }
 }
示例#16
0
        public static IBinaryOutput WithInvertedState(this IBinaryOutput binaryOutput)
        {
            if (binaryOutput == null)
            {
                throw new ArgumentNullException(nameof(binaryOutput));
            }

            return(new InvertedBinarOutput(binaryOutput));
        }
        public BinaryOutputWithState(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            Output = output;
            State  = state;
        }
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (output == null) throw new ArgumentNullException(nameof(output));

            var socket = new Socket(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));
            area.AddComponent(socket);

            return socket;
        }
        protected BinaryStateOutputActuator(ActuatorId id, IBinaryOutput output, IHttpRequestController httpApiController, ILogger logger)
            : base(id, httpApiController, logger)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _output = output;
        }
示例#20
0
        private IActuator ParseCustomBinaryStateOutputActuator(XElement element)
        {
            IBinaryOutput output = Parser.ParseBinaryOutput(element.GetMandatorySingleChildElementOrFromContainer("Output"));

            return(new CustomBinaryStateOutputActuator(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       output,
                       Controller.HttpApiController,
                       Controller.Logger));
        }
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (output == null) throw new ArgumentNullException(nameof(output));

            var lamp = new Lamp(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));
            area.AddComponent(lamp);

            return lamp;
        }
示例#22
0
        private IComponent ParseRollerShutter(XElement element)
        {
            IBinaryOutput powerOutput     = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Power"));
            IBinaryOutput directionOutput = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Direction"));

            return(new RollerShutter(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                       Controller.Timer));
        }
示例#23
0
        public StateMachineState WithOutput(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _pendingBinaryOutputStates.Add(new Tuple <IBinaryOutput, BinaryState>(output, state));
            return(this);
        }
示例#24
0
        public LogicalBinaryOutput WithOutput(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _outputs.Add(output);
            return(this);
        }
示例#25
0
        public StateMachineState WithBinaryOutput(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _binaryOutputs.Add(new PendingBinaryOutputState {
                BinaryOutput = output, State = state
            });
            return(this);
        }
示例#26
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>()));
        }
示例#27
0
        private IActuator ParseRollerShutter(XElement element)
        {
            IBinaryOutput powerOutput     = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Power"));
            IBinaryOutput directionOutput = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Direction"));

            return(new RollerShutter(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       powerOutput,
                       directionOutput,
                       Controller.HttpApiController,
                       Controller.Logger,
                       Controller.Timer));
        }
示例#28
0
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(RegisterLamp(area, id, new PortBasedBinaryOutputAdapter(output)));
        }
        public PortBasedRollerShutterEndpoint(IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            _powerOutput     = powerOutput;
            _directionOutput = directionOutput;
        }
示例#30
0
 private void SetupHumidityDependingOutput(IHumiditySensor sensor, IBinaryOutput output)
 {
     sensor.ValueChanged += (s, e) =>
     {
         if (e.NewValue > 80.0F)
         {
             output.Write(BinaryState.High);
         }
         else
         {
             output.Write(BinaryState.Low);
         }
     };
 }
示例#31
0
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(lamp);

            return(lamp);
        }
示例#32
0
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var socket = new Socket($"{area.Id}.{id}", new PortBasedBinaryOutputAdapter(output));

            area.RegisterComponent(socket);

            return(socket);
        }
示例#33
0
        public static IArea WithLamp(this IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ComponentIdFactory.Create(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(lamp);

            return(area);
        }
示例#34
0
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var socket = new Socket(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(socket);

            return(socket);
        }
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            var rollerShutter = new RollerShutter(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                _timerService,
                _schedulerService,
                _settingsService);

            area.AddComponent(rollerShutter);

            return rollerShutter;
        }
        public static IArea WithLamp(this IArea room, Enum id, IBinaryOutput output)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ActuatorIdFactory.Create(room, id), output, room.Controller.HttpApiController, room.Controller.Logger);

            lamp.SetInitialState();

            room.AddActuator(lamp);
            return(room);
        }
示例#37
0
        public HealthService(
            ControllerOptions controllerOptions, 
            IPi2GpioService pi2GpioService,
            ITimerService timerService, 
            ISystemInformationService systemInformationService)
        {
            if (controllerOptions == null) throw new ArgumentNullException(nameof(controllerOptions));
            if (timerService == null) throw new ArgumentNullException(nameof(timerService));
            if (systemInformationService == null) throw new ArgumentNullException(nameof(systemInformationService));

            _systemInformationService = systemInformationService;

            if (controllerOptions.StatusLedNumber.HasValue)
            {
                _led = pi2GpioService.GetOutput(controllerOptions.StatusLedNumber.Value);
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timerService.Tick += Tick;
        }
示例#38
0
        public HealthService(IBinaryOutput statusLed, IHomeAutomationTimer timer, ISystemInformationService systemInformationService)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            _statusLed = statusLed;
            _systemInformationService = systemInformationService;

            if (statusLed != null)
            {
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timer.Tick += Tick;
        }
示例#39
0
        public static IArea WithRollerShutter(this IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(ActuatorIdFactory.Create(area, id), powerOutput, directionOutput,
                                                  area.Controller.HttpApiController, area.Controller.Logger, area.Controller.Timer);

            area.AddActuator(rollerShutter);
            return(area);
        }
示例#40
0
        public HealthMonitor(IBinaryOutput statusLed, IHomeAutomationTimer timer, IApiController apiController)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }
            if (apiController == null)
            {
                throw new ArgumentNullException(nameof(apiController));
            }

            _statusLed   = statusLed;
            _timer       = timer;
            _startedDate = _timer.CurrentDateTime;

            if (statusLed != null)
            {
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timer.Tick += Tick;
            apiController.RouteRequest("health", HandleApiGet);
            apiController.RouteCommand("health/reset", c => ResetStatistics());
        }
 public StateMachineState WithLowPort(IBinaryOutput output)
 {
     return WithPort(output, BinaryState.Low);
 }
 public StateMachineState WithHighPort(IBinaryOutput output)
 {
     return WithPort(output, BinaryState.High);
 }
        public StateMachineState WithLowOutput(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            return WithOutput(output, BinaryState.Low);
        }
示例#44
0
 public Lamp(string id, IBinaryOutput output, IHttpRequestController httpRequestController, INotificationHandler notificationHandler)
     : base(id, output, httpRequestController, notificationHandler)
 {
 }
        public PortBasedBinaryStateEndpoint(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _output = output;
        }