public void SetState(RollerShutterState newState) { var oldState = _state; if (newState == RollerShutterState.MovingUp || newState == RollerShutterState.MovingDown) { StartMove(newState).Wait(); } else { _movingDuration.Stop(); StopInternal(); // Ensure that the direction relay is not wasting energy. _directionGpioPin.Write(BinaryState.Low); if (oldState != RollerShutterState.Stopped) { Logger.Info(Id + ": Stopped (Duration: " + _movingDuration.ElapsedMilliseconds + "ms)"); } } _state = newState; OnStateChanged(oldState, newState); }
public void SetState(int level, params IHardwareParameter[] parameters) { switch (level) { case 0: { _relay1.Write(BinaryState.Low); _relay2.Write(BinaryState.Low); break; } case 1: { _relay1.Write(BinaryState.High); _relay2.Write(BinaryState.Low); break; } case 2: { _relay1.Write(BinaryState.High); _relay2.Write(BinaryState.High); break; } default: { throw new NotSupportedException(); } } }
public void Stop(params IHardwareParameter[] parameters) { _powerOutput.Write(BinaryState.Low); // Ensure that the direction relay is not wasting energy. _directionOutput.Write(BinaryState.Low); }
public void TurnOn(params IHardwareParameter[] parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } bool commit = !parameters.Any(p => p is IsPartOfPartialUpdateParameter); _output.Write(BinaryState.High, commit); }
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); } }; }
private void ToggleStatusLed() { if (_ledState) { _statusLed.Write(BinaryState.High); _ledTimeout.Start(TimeSpan.FromSeconds(5)); } else { _statusLed.Write(BinaryState.Low); _ledTimeout.Start(TimeSpan.FromMilliseconds(200)); } _ledState = !_ledState; }
public void Update() { if (!_isOn && _stopwatch.ElapsedMilliseconds > 2000) { _output.Write(BinaryState.High); _isOn = true; _stopwatch.Restart(); } else if (_isOn && _stopwatch.ElapsedMilliseconds > 200) { _output.Write(BinaryState.Low); _isOn = false; _stopwatch.Restart(); } }
public void SetState(AdapterRollerShutterState state, params IHardwareParameter[] parameters) { if (state == AdapterRollerShutterState.MoveUp) { StopAndWait(); _directionOutput.Write(BinaryState.Low); Start(); } else if (state == AdapterRollerShutterState.MoveDown) { StopAndWait(); _directionOutput.Write(BinaryState.High); Start(); } else { _powerOutput.Write(BinaryState.Low); // Ensure that the direction relay is not wasting energy. _directionOutput.Write(BinaryState.Low); } }
public void SetState(AdapterPowerState powerState, params IHardwareParameter[] parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } var commit = !parameters.Any(p => p is IsPartOfPartialUpdateParameter); lock (_output) { _output.Write(powerState == AdapterPowerState.On ? BinaryState.High : BinaryState.Low, commit ? WriteBinaryStateMode.Commit : WriteBinaryStateMode.NoCommit); } }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { BinaryActuatorState oldState = GetState(); bool stateHasChanged = newState != oldState; bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); _output.Write(newState == BinaryActuatorState.On ? BinaryState.High : BinaryState.Low, commit); bool forceUpdate = parameters.Any(p => p is ForceUpdateStateParameter); if (forceUpdate || stateHasChanged) { Logger.Info(Id + ": " + oldState + "->" + newState); OnStateChanged(oldState, newState); } }
private void StopInternal() { _powerGpioPin.Write(BinaryState.Low); }
public void StartMoveUp(params IHardwareParameter[] parameters) { StopAndWait(); _directionOutput.Write(BinaryState.Low); Start(); }
public StatusLed(IBinaryOutput output) { _output = output ?? throw new ArgumentNullException(nameof(output)); _output.Write(BinaryState.Low); }
public void Write(BinaryState state, WriteBinaryStateMode mode = WriteBinaryStateMode.Commit) { _binaryOutput.Write(CoerceState(state), mode); }