Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On stopping auto mode in autopilot, the drive mode gets enable for phone controller i.e dual drive #436

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/robot/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id 'com.android.application'
id 'io.github.reactivecircus.app-versioning' version "1.1.2"
id 'com.google.gms.google-services'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openbot.utils.Enums;
import org.openbot.utils.PermissionUtils;
import org.openbot.vehicle.Control;

import timber.log.Timber;

public class AutopilotFragment extends CameraFragment {
Expand Down Expand Up @@ -75,6 +76,7 @@ public View onCreateView(
@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentAutopilotBinding.inflate(inflater, container, false);

return inflateFragment(binding, inflater, container);
}

Expand All @@ -99,6 +101,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
getModelNames(f -> f.type.equals(Model.TYPE.CMDNAV) && f.pathType != Model.PATH_TYPE.URL);
initModelSpinner(binding.modelSpinner, models, preferencesManager.getAutopilotModel());
initServerSpinner(binding.serverSpinner);

setAnalyserResolution(Enums.Preview.HD.getValue());
binding.deviceSpinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
Expand Down Expand Up @@ -144,11 +147,6 @@ public void onNothingSelected(AdapterView<?> parent) {
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 @@ -179,9 +177,9 @@ public void onNothingSelected(AdapterView<?> parent) {
}

private void updateCropImageInfo() {
// Timber.i("%s x %s",getPreviewSize().getWidth(), getPreviewSize().getHeight());
// Timber.i("%s x %s",getMaxAnalyseImageSize().getWidth(),
// getMaxAnalyseImageSize().getHeight());
// Timber.i("%s x %s",getPreviewSize().getWidth(), getPreviewSize().getHeight());
// Timber.i("%s x %s",getMaxAnalyseImageSize().getWidth(),
// getMaxAnalyseImageSize().getHeight());
frameToCropTransform = null;

sensorOrientation = 90 - ImageUtils.getScreenOrientation(requireActivity());
Expand Down Expand Up @@ -383,11 +381,20 @@ private void setNetworkEnabled(boolean b) {
binding.controllerContainer.controlMode.setEnabled(!b);
binding.controllerContainer.driveMode.setEnabled(!b);
binding.controllerContainer.speedMode.setEnabled(!b);

binding.controllerContainer.controlMode.setAlpha(b ? 0.5f : 1f);
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 +465,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 +579,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 All @@ -589,4 +592,3 @@ private void disconnectPhoneController() {
binding.controllerContainer.driveMode.setAlpha(1.0f);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,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 connectWebController() {
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