public static async Task ToggleTimedColor(this ILEDService ledService, Color color, TimeSpan timeSpan, CancellationToken cancellationToken = default)
        {
            try
            {
                await ledService.SetColorAsync(color);

                await Task.Delay(timeSpan, cancellationToken);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                await ledService.ToggleOff();
            }
        }
Exemplo n.º 2
0
            public async Task <AlarmStateDto> Handle(ArmCommand request, CancellationToken cancellationToken)
            {
                if (!_state.Armed)
                {
                    var lockState = await _mediator.Send(new LockCommand());

                    _state.Armed = true;

                    await _ledService.SetColorAsync(Color.Purple);

                    _logger.LogInformation("Armed");

                    await _serviceEventClient.PublishEvent(new AlarmEvent(AlarmState.Armed));

                    await Task.Delay(2000);

                    await _ledService.ToggleOff();
                }

                return(await _mediator.Send(new GetAlarmStateQuery()));
            }
        public static Task Blink(this ILEDService ledService, int times, Color color, TimeSpan delay, Action callback = null, CancellationToken cancellationToken = default)
        {
            return(Task.Run(async() =>
            {
                for (int i = 0; i < times; i++)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    await ledService.SetColorAsync(color);

                    callback?.Invoke();

                    await Task.Delay(delay);

                    await ledService.ToggleOff();

                    await Task.Delay(delay);
                }
            }));
        }
Exemplo n.º 4
0
            public async Task Handle(MotionDetectedNotification notification, CancellationToken cancellationToken)
            {
                _logger.LogInformation("Motion detected");

                await _ledService.SetColorAsync(Color.Orange);
            }
 public static async Task ToggleOff(this ILEDService ledService)
 {
     await ledService.SetColorAsync(0, 0, 0);
 }
 public static async Task ToggleBlueLedOn(this ILEDService ledService)
 {
     await ledService.SetColorAsync(Color.Blue);
 }
 public static async Task ToggleGreenLedOn(this ILEDService ledService)
 {
     await ledService.SetColorAsync(Color.Green);
 }
 public static async Task ToggleRedLedOn(this ILEDService ledService)
 {
     await ledService.SetColorAsync(Color.Red);
 }