public void onServoDrop(ServoDragHandler dragHandler) { var servoUIControls = dragHandler.draggedItem; int insertAt = dragHandler.placeholder.transform.GetSiblingIndex(); foreach (var pair in WindowManager._servoUIControls) { if (pair.Value == servoUIControls) { var s = pair.Key; var oldGroupIndex = ServoController.Instance.ServoGroups.FindIndex(g => g.Servos.Contains(s)); if (oldGroupIndex < 0) { //error return; } var newGroupIndex = dragHandler.dropZone.parent.GetSiblingIndex(); ServoController.MoveServo(ServoController.Instance.ServoGroups[oldGroupIndex], ServoController.Instance.ServoGroups[newGroupIndex], s); WindowManager.guiRebuildPending = true; break; } } }
private void CarMoveCommand(CarControlCommand carControlCommand) { var now = DateTime.Now; if (now.Subtract(_moveCarLastAction) >= TimeSpan.FromMilliseconds(MOVE_CAR_PERIOD_ACTION_MILLISECONDS) || (!carControlCommand.DirectionControlUp && !carControlCommand.DirectionControlLeft && !carControlCommand.DirectionControlRight && !carControlCommand.DirectionControlDown && !carControlCommand.SpeedControlForward && !carControlCommand.SpeedControlBackward)) { _motorController.MoveCar(carControlCommand, null); _servoController.MoveServo(carControlCommand); _moveCarLastAction = now; Task.Run(async() => { await CarControlCommandTimeout(now); }); } }
private async Task StartGamepadReading(Gamepad gamepad) { _isGamepadReadingStopped = false; var buttonDownTimeMiddle = TimeSpan.FromSeconds(2); var buttonDownTimeLong = TimeSpan.FromSeconds(5); var viewButton = new GamepadButtonDown(TimeSpan.Zero, GamepadButtons.View); var menuButton = new GamepadButtonDown(TimeSpan.Zero, GamepadButtons.Menu); var dPadUpButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.DPadUp); var dPadDownButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.DPadDown); var dPadLeftButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.DPadLeft); var dPadRightButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.DPadRight); var yButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.Y); var bButton = new GamepadButtonDown(buttonDownTimeMiddle, GamepadButtons.B); var xRightShoulderButton = new GamepadButtonDown(buttonDownTimeLong, GamepadButtons.X, GamepadButtons.RightShoulder); var aRightShoulderButton = new GamepadButtonDown(buttonDownTimeLong, GamepadButtons.A, GamepadButtons.RightShoulder); var xRightShoulderButtonNotClickableButtons = new List <GamepadButtons> { GamepadButtons.Y }; var aRightShoulderButtonNotClickableButtons = new List <GamepadButtons> { GamepadButtons.X }; var dPadUpNotClickableButtons = new List <GamepadButtons> { GamepadButtons.DPadDown, GamepadButtons.DPadLeft, GamepadButtons.DPadRight }; var dPadDownNotClickableButtons = new List <GamepadButtons> { GamepadButtons.DPadUp, GamepadButtons.DPadLeft, GamepadButtons.DPadRight }; var dPadLeftNotClickableButtons = new List <GamepadButtons> { GamepadButtons.DPadUp, GamepadButtons.DPadDown, GamepadButtons.DPadRight }; var dPadRightNotClickableButtons = new List <GamepadButtons> { GamepadButtons.DPadUp, GamepadButtons.DPadDown, GamepadButtons.DPadLeft }; while (_gamepad == gamepad) { //gamepad variable could be null var gamepadReadingTry = gamepad?.GetCurrentReading(); if (!gamepadReadingTry.HasValue) { break; } var gamepadReading = gamepadReadingTry.Value; var carMoveCommand = new CarMoveCommand(gamepadReading); var carControlCommand = new CarControlCommand(gamepadReading); //Move car and servo if is new command available if (!(_carStopped && carMoveCommand.Speed == 0.0 && !carControlCommand.DirectionControlUp && !carControlCommand.DirectionControlDown)) { _carStopped = false; _motorController.MoveCar(null, carMoveCommand); _servoController.MoveServo(carControlCommand); } //Car and servo not moving if (carMoveCommand.Speed == 0.0 && !carControlCommand.DirectionControlUp && !carControlCommand.DirectionControlDown) { _carStopped = true; } // Enable/ disable gamepad vibration var viewButtonResult = viewButton.UpdateGamepadButtonState(gamepadReading); if (viewButtonResult.ButtonClicked) { _gamepadShouldVibrate = !_gamepadShouldVibrate; if (_gamepadShouldVibrate) { await AudioPlayerController.Play(AudioName.GamepadVibrationOn); } else { await AudioPlayerController.Play(AudioName.GamepadVibrationOff); } } //Automatic drive toggle var menuButtonResult = menuButton.UpdateGamepadButtonState(gamepadReading); if (menuButtonResult.ButtonClicked) { await _automaticDrive.StartStopToggle(); } var dPadUpButtonResult = dPadUpButton.UpdateGamepadButtonState(gamepadReading, dPadUpNotClickableButtons); var dPadDownButtonResult = dPadDownButton.UpdateGamepadButtonState(gamepadReading, dPadDownNotClickableButtons); var dPadLeftButtonResult = dPadLeftButton.UpdateGamepadButtonState(gamepadReading, dPadLeftNotClickableButtons); var dPadRightButtonResult = dPadRightButton.UpdateGamepadButtonState(gamepadReading, dPadRightNotClickableButtons); //All speaker on if (dPadUpButtonResult.ButtonClicked) { await AudioPlayerController.SetAllSpeakerOnOff(true); } //All speaker off if (dPadDownButtonResult.ButtonClicked) { await AudioPlayerController.SetAllSpeakerOnOff(false); } //Car speaker on/off toggle if (dPadLeftButtonResult.ButtonClicked) { await AudioPlayerController.SetCarSpeakerOnOffToggle(); } //Headset speaker on/off toggle if (dPadRightButtonResult.ButtonClicked) { await AudioPlayerController.SetHeadsetSpeakerOnOffToggle(); } //Sound mode on/off toggle var yButtonResult = yButton.UpdateGamepadButtonState(gamepadReading); if (yButtonResult.ButtonClicked) { await AudioPlayerController.SetSoundModeOnOffToggle(); } //Speak current speaker and sound mode state var bButtonResult = bButton.UpdateGamepadButtonState(gamepadReading); if (bButtonResult.ButtonClicked) { await AudioPlayerController.PlaySpeakerOnOffSoundMode(); } //Shutdown var xRightShoulderButtonResult = xRightShoulderButton.UpdateGamepadButtonState(gamepadReading, xRightShoulderButtonNotClickableButtons); if (xRightShoulderButtonResult.ButtonClicked) { _isGamepadReadingStopped = true; await SystemController.Shutdown(); } //Restart var aRightShoulderButtonResult = aRightShoulderButton.UpdateGamepadButtonState(gamepadReading, aRightShoulderButtonNotClickableButtons); if (aRightShoulderButtonResult.ButtonClicked) { _isGamepadReadingStopped = true; await SystemController.Restart(); } await Task.Delay(25); } _isGamepadReadingStopped = true; }