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); }
private void StartMove(RollerShutterState state) { foreach (var rollerShutter in _rollerShutters) { _actuatorController.Actuator <IRollerShutter>(rollerShutter).SetState(state); } }
private async Task StartMove(RollerShutterState newState) { if (_state != RollerShutterState.Stopped) { StopInternal(); // Ensure that the relay is completely fallen off before switching the direction. await Task.Delay(50); } BinaryState binaryState; if (newState == RollerShutterState.MovingDown) { binaryState = BinaryState.High; } else if (newState == RollerShutterState.MovingUp) { binaryState = BinaryState.Low; } else { throw new InvalidOperationException(); } _directionGpioPin.Write(binaryState, false); Start(); }
public void SetState(RollerShutterState state) { var oldState = GetState(); _state = state; StateChanged?.Invoke(this, new RollerShutterStateChangedEventArgs(oldState, _state)); }
public void StartMoveDown() { _movingDuration.Restart(); StopInternal(); _directionGpioPin.Write(BinaryState.High, false); Start(); State = RollerShutterState.MovingDown; NotificationHandler.PublishFrom(this, NotificationType.Info, "'{0}' started moving down.", Id); }
private void OnStateChanged(RollerShutterState oldState, RollerShutterState newState) { StateChanged?.Invoke(this, new RollerShutterStateChangedEventArgs(oldState, newState)); Logger.Info(Id + ": " + oldState + "->" + newState); }
public void Stop() { _movingDuration.Stop(); StopInternal(); _directionGpioPin.Write(BinaryState.Low); if (State != RollerShutterState.Stopped) { State = RollerShutterState.Stopped; NotificationHandler.PublishFrom(this, NotificationType.Info, "'{0}' stopped moving (Duration: {1}ms).", Id, _movingDuration.ElapsedMilliseconds); } }