Skip to content

Commit

Permalink
fixed bug in vehicle control on starting auto mode
Browse files Browse the repository at this point in the history
  • Loading branch information
isha382 committed Nov 11, 2024
1 parent 1417476 commit a924c5a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ public void onNothingSelected(AdapterView<?> parent) {
binding.usbToggle.setChecked(vehicle.isUsbConnected());
Navigation.findNavController(requireView()).navigate(R.id.open_usb_fragment);
});

binding.bleToggle.setOnClickListener(
v -> {
binding.bleToggle.setChecked(vehicle.bleConnected());
Navigation.findNavController(requireView()).navigate(R.id.open_bluetooth_fragment);
});
binding.bleToggle.setOnClickListener(
v -> {
binding.bleToggle.setChecked(vehicle.bleConnected());
Expand Down Expand Up @@ -388,6 +382,16 @@ private void setNetworkEnabled(boolean b) {
binding.controllerContainer.driveMode.setAlpha(b ? 0.5f : 1f);
binding.controllerContainer.speedMode.setAlpha(b ? 0.5f : 1f);

if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) != null) {
if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) == Enums.DriveMode.DUAL && Enums.ControlMode.getByID(preferencesManager.getControlMode()) == Enums.ControlMode.PHONE) {
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
} else if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) == Enums.DriveMode.GAME && Enums.ControlMode.getByID(preferencesManager.getControlMode()) == Enums.ControlMode.WEBSERVER) {
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
}
}

if (!b) {
setSpeedMode(Enums.SpeedMode.getByID(preferencesManager.getSpeedMode()));
handler.postDelayed(() -> vehicle.setControl(0, 0), 500);
Expand Down Expand Up @@ -458,12 +462,10 @@ protected Model getModel() {

private void connectWebController() {
phoneController.connectWebServer();
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.GAME);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

protected void setModel(Model model) {
Expand Down Expand Up @@ -574,12 +576,10 @@ protected void setDriveMode(Enums.DriveMode driveMode) {

private void connectPhoneController() {
phoneController.connect(requireContext());
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.DUAL);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void disconnectPhoneController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,22 +585,18 @@ protected void setDriveMode(Enums.DriveMode driveMode) {

private void connectPhoneController() {
phoneController.connect(requireContext());
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.DUAL);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void connectWebController() {
phoneController.connectWebServer();
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.GAME);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void disconnectPhoneController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ private void setNetworkEnabled(boolean b) {
binding.controllerContainer.driveMode.setAlpha(b ? 0.5f : 1f);
binding.controllerContainer.speedMode.setAlpha(b ? 0.5f : 1f);

if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) != null) {
if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) == Enums.DriveMode.DUAL && Enums.ControlMode.getByID(preferencesManager.getControlMode()) == Enums.ControlMode.PHONE) {
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
}
else if (Enums.DriveMode.getByID(preferencesManager.getDriveMode()) == Enums.DriveMode.GAME && Enums.ControlMode.getByID(preferencesManager.getControlMode()) == Enums.ControlMode.WEBSERVER) {
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
}
}

resetFpsUi();
if (!b) handler.postDelayed(() -> vehicle.setControl(0, 0), Math.max(lastProcessingTimeMs, 50));
}
Expand Down Expand Up @@ -652,22 +663,18 @@ protected void setDriveMode(Enums.DriveMode driveMode) {

private void connectPhoneController() {
phoneController.connect(requireContext());
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.DUAL);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void connectWebController() {
phoneController.connectWebServer();
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.GAME);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void disconnectPhoneController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ private void connectPhoneController() {
// Currently only dual drive mode supported
setDriveMode(DriveMode.DUAL);
driveModeSpinner.setAlpha(0.5f);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void connectWebController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,18 @@ protected void setDriveMode(DriveMode driveMode) {

private void connectPhoneController() {
phoneController.connect(requireContext());
DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(DriveMode.DUAL);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void connectWebController() {
phoneController.connectWebServer();
Enums.DriveMode oldDriveMode = currentDriveMode;
// Currently only dual drive mode supported
setDriveMode(Enums.DriveMode.GAME);
binding.controllerContainer.driveMode.setAlpha(0.5f);
binding.controllerContainer.driveMode.setEnabled(false);
preferencesManager.setDriveMode(oldDriveMode.getValue());
}

private void disconnectPhoneController() {
Expand Down

0 comments on commit a924c5a

Please sign in to comment.