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

Firmware config message #253

Merged
merged 9 commits into from Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -289,7 +289,7 @@ protected void processUSBData(String data) {
getString(
R.string.speedInfo,
String.format(
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRPM(), vehicle.getRightWheelRPM())));
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRpm(), vehicle.getRightWheelRpm())));
}

@Override
Expand Down
27 changes: 25 additions & 2 deletions android/app/src/main/java/org/openbot/common/ControlsFragment.java
Expand Up @@ -111,9 +111,31 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
String body = data.substring(1);

switch (header) {
case 'f':
vehicle.processVehicleConfig(body);
break;
case 'v':
if (FormatUtils.isNumeric(body)) {
vehicle.setBatteryVoltage(Float.parseFloat(body));
} else {
String[] msgParts = body.split(":");
switch (msgParts[0]) {
case "min":
vehicle.setMinMotorVoltage(Float.parseFloat(msgParts[1]));
case "low":
vehicle.setLowBatteryVoltage(Float.parseFloat(msgParts[1]));
break;
case "max":
vehicle.setMaxBatteryVoltage(Float.parseFloat(msgParts[1]));
break;
default:
Toast.makeText(
requireContext().getApplicationContext(),
"Invalid voltage message received!",
Toast.LENGTH_SHORT)
.show();
break;
}
}
break;
case 's':
Expand All @@ -126,8 +148,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
if (itemList.length == 2
&& FormatUtils.isNumeric(itemList[0])
&& FormatUtils.isNumeric(itemList[1])) {
vehicle.setLeftWheelTicks(Float.parseFloat(itemList[0]));
vehicle.setRightWheelTicks(Float.parseFloat(itemList[1]));
vehicle.setLeftWheelRpm(Float.parseFloat(itemList[0]));
vehicle.setRightWheelRpm(Float.parseFloat(itemList[1]));
}
break;
case 'b':
Expand All @@ -139,6 +161,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
});

handlePhoneControllerEvents();
vehicle.requestVehicleConfig();
}

private void processKeyEvent(KeyEvent keyCode) {
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.openbot.utils.ConnectionUtils;
import org.openbot.utils.Constants;
import org.openbot.utils.Enums;
import org.openbot.utils.FormatUtils;
import org.openbot.utils.PermissionUtils;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
Expand Down Expand Up @@ -350,10 +351,14 @@ protected void processUSBData(String data) {

switch (header) {
case 'v':
type = SensorService.MSG_VOLTAGE;
if (FormatUtils.isNumeric(body)) {
type = SensorService.MSG_VOLTAGE;
}
break;
case 's':
type = SensorService.MSG_SONAR;
if (FormatUtils.isNumeric(body)) {
type = SensorService.MSG_SONAR;
}
break;
case 'w':
type = SensorService.MSG_WHEELS;
Expand All @@ -363,8 +368,8 @@ protected void processUSBData(String data) {
String.format(
Locale.US,
"%3.0f,%3.0f",
vehicle.getLeftWheelRPM(),
vehicle.getRightWheelRPM())));
vehicle.getLeftWheelRpm(),
vehicle.getRightWheelRpm())));
break;
case 'b':
type = SensorService.MSG_BUMPER;
Expand Down
Expand Up @@ -338,7 +338,7 @@ protected void processUSBData(String data) {
getString(
R.string.speedInfo,
String.format(
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRPM(), vehicle.getRightWheelRPM())));
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRpm(), vehicle.getRightWheelRpm())));
}

@Override
Expand Down
33 changes: 28 additions & 5 deletions android/app/src/main/java/org/openbot/original/CameraActivity.java
Expand Up @@ -367,8 +367,10 @@ public void onReceive(Context context, Intent intent) {
char header = data.charAt(0);
String body = data.substring(1);
int type = -1;

switch (header) {
case 'f':
vehicle.processVehicleConfig(body);
break;
case 'v':
if (FormatUtils.isNumeric(body)) {
type = SensorService.MSG_VOLTAGE;
Expand All @@ -378,6 +380,26 @@ public void onReceive(Context context, Intent intent) {
voltageTextView.setText(
String.format(Locale.US, "%2.1f V", vehicle.getBatteryVoltage()));
});
} else {
String[] msgParts = body.split(":");
switch (msgParts[0]) {
case "min":
vehicle.setMinMotorVoltage(Float.parseFloat(msgParts[1]));
break;
case "low":
vehicle.setLowBatteryVoltage(Float.parseFloat(msgParts[1]));
break;
case "max":
vehicle.setMaxBatteryVoltage(Float.parseFloat(msgParts[1]));
break;
default:
Toast.makeText(
getApplicationContext(),
"Invalid voltage message received!",
Toast.LENGTH_SHORT)
.show();
break;
}
}
break;
case 's':
Expand All @@ -397,16 +419,16 @@ public void onReceive(Context context, Intent intent) {
&& FormatUtils.isNumeric(itemList[0])
&& FormatUtils.isNumeric(itemList[1])) {
type = SensorService.MSG_WHEELS;
vehicle.setLeftWheelTicks(Float.parseFloat(itemList[0]));
vehicle.setRightWheelTicks(Float.parseFloat(itemList[1]));
vehicle.setLeftWheelRpm(Float.parseFloat(itemList[0]));
vehicle.setRightWheelRpm(Float.parseFloat(itemList[1]));
runOnUiThread(
() -> {
speedTextView.setText(
String.format(
Locale.US,
"%3.0f,%3.0f rpm",
vehicle.getLeftWheelRPM(),
vehicle.getRightWheelRPM()));
vehicle.getLeftWheelRpm(),
vehicle.getRightWheelRpm()));
});
}
break;
Expand All @@ -426,6 +448,7 @@ public void onReceive(Context context, Intent intent) {
localIntentFilter.addAction(Constants.USB_ACTION_DATA_RECEIVED);
localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.registerReceiver(localBroadcastReceiver, localIntentFilter);
vehicle.requestVehicleConfig();
}

@SuppressLint("SetTextI18n")
Expand Down
Expand Up @@ -106,7 +106,7 @@ protected void processUSBData(String data) {
getString(
R.string.speedInfo,
String.format(
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRPM(), vehicle.getRightWheelRPM())));
Locale.US, "%3.0f,%3.0f", vehicle.getLeftWheelRpm(), vehicle.getRightWheelRpm())));

binding.voltageInfo.setText(
getString(
Expand Down