Exemple #1
0
        private async void DoWork(object sender, DoWorkEventArgs e)
        {
            while (_worker != null && !_worker.CancellationPending)
            {
                var result = await ServiceBusHelper.ReceiveAndDeleteMessage();

                switch (result)
                {
                case "SMR":
                    await _uln2003Driver.TurnAsync(90, TurnDirection.Right);

                    break;

                case "SML":
                    await _uln2003Driver.TurnAsync(90, TurnDirection.Left);

                    break;

                case "F":
                    _twoMotorsDriver.MoveForward();
                    isMovingForward = true;
                    break;

                case "S":
                    _twoMotorsDriver.Stop();
                    isMovingForward = false;
                    break;

                case "R":
                    await _twoMotorsDriver.TurnRightAsync();

                    isMovingForward = false;
                    break;

                case "L":
                    await _twoMotorsDriver.TurnLeftAsync();

                    isMovingForward = false;
                    break;

                case "B":
                    _twoMotorsDriver.MoveBackward();
                    isMovingForward = false;
                    break;

                case "TR":
                    await _twoMotorsDriver.TurnRightAsync(45);

                    isMovingForward = false;
                    break;

                case "TL":
                    await _twoMotorsDriver.TurnLeftAsync(45);

                    isMovingForward = false;
                    break;

                case "BR":
                    await _twoMotorsDriver.TurnRightAsync(100);

                    isMovingForward = false;
                    break;

                case "BL":
                    await _twoMotorsDriver.TurnLeftAsync(100);

                    isMovingForward = false;
                    break;
                }

                await Task.Delay(1000);
            }
        }