/// <summary>
        /// Transforms the input values from controller to left and right speed
        /// values for the motors
        /// </summary>
        /// <param name="controller"></param>
        /// <returns>A Tuple(int, int) with left and right speed values</int></returns>
        private Tuple <int, int> CalculateSpeedValues(XBoxController controller)
        {
            controller.Update();
            float  rightTrigger = controller.RightTrigger;
            float  leftTrigger  = controller.LeftTrigger;
            double rightThumbX  = controller.RightThumb.X;
            int    leftspeed    = 0;
            int    rightspeed   = 0;


            // calculate speed based on left and right triggers (right trigger forward, left trigger backward)
            int tempSpeed = (int)((rightTrigger - leftTrigger));// / 255 * 100);

            if (rightThumbX > 0)
            {
                double multiplier = rightThumbX / 100;
                leftspeed  = (int)(tempSpeed + multiplier * 255);
                rightspeed = (int)(tempSpeed - multiplier * 255);
            }
            else if (rightThumbX < 0)
            {
                double multiplier = rightThumbX / -100;
                leftspeed  = (int)(tempSpeed - multiplier * 255);
                rightspeed = (int)(tempSpeed + multiplier * 255);
            }
            else
            {
                rightspeed = leftspeed = tempSpeed;
            }

            return(Tuple.Create(leftspeed, rightspeed));
        }
 /// <summary>
 /// Log the Contorller values.
 /// </summary>
 /// <param name="controller"></param>
 /// <returns></returns>
 private bool TestConrollerOutputs(XBoxController controller)
 {
     OnIsRunngingChanged(true);
     while (!_shouldStop)
     {
         Thread.Sleep(200); // give console some time after each iteration
         controller.Update();
         Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => {
             log.Info("\nLeft Thumb X: " + controller.LeftThumb.X + " " + "\nLeft Thumb Y: " + controller.LeftThumb.Y + "\n" +
                      "A?: " + controller.Buttons.Equals(GamepadButtonFlags.A) + "\n" +
                      "Rigth Thumb X: " + controller.RightThumb.X + "\n" +
                      "Rigth Thumb Y: " + controller.RightThumb.Y + "\n" +
                      "Left Trigger: " + controller.LeftTrigger + "\n" +
                      "Right Trigger: " + controller.RightTrigger);
         }));
         //Console.WriteLine(controller.leftThumb + " " + controller.rightThumb + " " + controller.leftTrigger + " " + controller.rightTrigger);
     }
     log.Info("Controller test ended");
     OnIsRunngingChanged(false);
     return(true);
 }
        /// <summary>
        /// Start the ControllerTest
        /// runs synchronously until it hits an “await” (or throws an exception).
        /// </summary>
        /// <param name="info"></param>
        public override async void Start(ControllerTestInfo info)
        {
            Stop();
            _shouldStop = false;
            controller.Update();

            switch (info.Case)
            {
            case ControllerTestInfo.TestCase.MotorOutput:
                await Task.Run(() => TestMotorControl(controller, true));

                break;

            case ControllerTestInfo.TestCase.ControllerOutput:
                await Task.Run(() => TestConrollerOutputs(controller));

                break;

            default:
                await Task.Run(() => TestMotorControl(controller));

                break;
            }
        }