505 lines
20 KiB
Java
505 lines
20 KiB
Java
package com.ubt.jimu.test;
|
|
|
|
import android.app.Activity;
|
|
import android.bluetooth.BluetoothDevice;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Toast;
|
|
import com.alibaba.android.arouter.facade.Postcard;
|
|
import com.alibaba.android.arouter.launcher.ARouter;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.EngineManager;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.data.CtrlMotionType;
|
|
import com.ubt.jimu.base.data.Engine;
|
|
import com.ubt.jimu.base.data.Servo;
|
|
import com.ubt.jimu.base.entities.Robot;
|
|
import com.ubt.jimu.controller.data.action.ActionSequence;
|
|
import com.ubt.jimu.controller.data.action.MotorData;
|
|
import com.ubt.jimu.controller.data.action.TurnData;
|
|
import com.ubt.jimu.controller.data.command.MotorCommand;
|
|
import com.ubt.jimu.controller.data.command.MoveCommand;
|
|
import com.ubt.jimu.controller.data.command.TurnCommand;
|
|
import com.ubt.jimu.controller.data.config.JockstickConfig;
|
|
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
|
import com.ubt.jimu.controller.data.widget.AccumulatorData;
|
|
import com.ubt.jimu.controller.data.widget.ActionWidgetData;
|
|
import com.ubt.jimu.controller.data.widget.ControllerData;
|
|
import com.ubt.jimu.controller.data.widget.HSliderWidgetData;
|
|
import com.ubt.jimu.controller.data.widget.JockstickData;
|
|
import com.ubt.jimu.controller.data.widget.SliderWidgetData;
|
|
import com.ubt.jimu.controller.manager.ActionManager;
|
|
import com.ubt.jimu.controller.manager.CommandManager;
|
|
import com.ubt.jimu.controller.manager.ControllerManager;
|
|
import com.ubt.jimu.controller.util.IDGenerator;
|
|
import com.ubt.jimu.controller.util.PermissionUtils;
|
|
import com.ubtech.utils.XLog;
|
|
import com.ubtech.view.widget.ToastView;
|
|
import com.ubtrobot.jimu.bluetooth.Cancellable;
|
|
import com.ubtrobot.jimu.bluetooth.ConnectCallback;
|
|
import com.ubtrobot.jimu.bluetooth.base.discover.ScanResult;
|
|
import com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter;
|
|
import com.ubtrobot.jimu.robotapi.JimuManager;
|
|
import com.ubtrobot.jimu.robotapi.JimuScanner;
|
|
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class ControllerTestActivity extends Activity {
|
|
private JimuManager a;
|
|
private BluetoothDevice b;
|
|
private Cancellable c;
|
|
private EditText d;
|
|
private EditText e;
|
|
private EditText f;
|
|
private EditText g;
|
|
private EditText h;
|
|
private EditText i;
|
|
|
|
private void f() {
|
|
((Button) findViewById(R.id.parse_actions)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.a
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.a(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.execute_action)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.m
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.b(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.stop_action)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.q
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.k(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.stop_all)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.d
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.l(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.control_generate)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.r
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.m(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.enter_control)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.l
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.n(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.ble_connect)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.g
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.o(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.ble_scan)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.n
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.p(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.test_power_down)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.j
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.q(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.move_left)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.f
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.r(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.move_right)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.p
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.c(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.move_forward)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.k
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.d(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.move_backward)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.o
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.e(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.move_stop)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.c
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.f(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.servo_mode)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.h
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.g(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.btn_engine_list)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.i
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.h(view);
|
|
}
|
|
});
|
|
((Button) findViewById(R.id.btn_servo_list)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.e
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.i(view);
|
|
}
|
|
});
|
|
this.d = (EditText) findViewById(R.id.et_left_ids);
|
|
this.e = (EditText) findViewById(R.id.et_right_ids);
|
|
this.f = (EditText) findViewById(R.id.et_direct);
|
|
this.g = (EditText) findViewById(R.id.et_high_speed);
|
|
this.h = (EditText) findViewById(R.id.et_high_duration);
|
|
this.i = (EditText) findViewById(R.id.et_run_speed);
|
|
((Button) findViewById(R.id.btn_run)).setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.test.b
|
|
@Override // android.view.View.OnClickListener
|
|
public final void onClick(View view) {
|
|
ControllerTestActivity.this.j(view);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void s() {
|
|
String obj = this.d.getText().toString();
|
|
String[] split = !TextUtils.isEmpty(obj) ? obj.split(";") : null;
|
|
String[] split2 = TextUtils.isEmpty(obj) ? null : this.e.getText().toString().split(";");
|
|
String obj2 = this.f.getText().toString();
|
|
int intValue = TextUtils.isEmpty(obj2) ? 0 : Integer.valueOf(obj2).intValue();
|
|
String obj3 = this.g.getText().toString();
|
|
int intValue2 = !TextUtils.isEmpty(obj3) ? Integer.valueOf(obj3).intValue() : 0;
|
|
String obj4 = this.h.getText().toString();
|
|
int intValue3 = !TextUtils.isEmpty(obj4) ? Integer.valueOf(obj4).intValue() : 0;
|
|
String obj5 = this.i.getText().toString();
|
|
int intValue4 = !TextUtils.isEmpty(obj5) ? Integer.valueOf(obj5).intValue() : 0;
|
|
e().a((MoveCommand) new MotorCommand(a(split, split2, intValue, intValue2, intValue3 + 1000)), false);
|
|
try {
|
|
Thread.sleep(intValue3);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
e().a((MoveCommand) new MotorCommand(a(split, split2, intValue, intValue4, 5000)), false);
|
|
}
|
|
|
|
private void t() {
|
|
ActionManager a = ActionManager.a(this);
|
|
Robot robot = Cache.getInstance().getRobot();
|
|
if (robot != null) {
|
|
a.a(robot.getRobotLite());
|
|
}
|
|
List<ActionWidgetData> a2 = a.a();
|
|
Object[] objArr = new Object[1];
|
|
objArr[0] = a2 != null ? a2.toString() : "null";
|
|
XLog.a("woo", "actionData: %s", objArr);
|
|
}
|
|
|
|
private void u() {
|
|
t();
|
|
}
|
|
|
|
private void v() {
|
|
ControllerData controllerData = new ControllerData("robot_6b73ae94-5aeb-4f54-ba72-748a7ad5d755");
|
|
ActionWidgetData actionWidgetData = new ActionWidgetData();
|
|
actionWidgetData.setActionID("actions_636252715835204660");
|
|
actionWidgetData.setActionNm("待命");
|
|
actionWidgetData.setCurrentPos(100.0f, 100.0f);
|
|
controllerData.addActionData(actionWidgetData);
|
|
ActionWidgetData actionWidgetData2 = new ActionWidgetData(String.valueOf(System.currentTimeMillis()));
|
|
actionWidgetData2.setActionNm("huanhu");
|
|
actionWidgetData2.setActionID("actions_6365560445275619713");
|
|
actionWidgetData2.setCurrentX(400.0f);
|
|
actionWidgetData2.setCurrentY(540.0f);
|
|
controllerData.addActionData(actionWidgetData2);
|
|
controllerData.addSliderData(new SliderWidgetData("131716138616736069", CtrlMotionType.motor, (byte) 1, false, 357.45593f, 6.8648224f));
|
|
controllerData.addHsliderData(new HSliderWidgetData("131756933887463852", (byte) 1, WidgetConfig.MIN_ANGLE, 118, -13.876572f, -279.57144f));
|
|
JockstickData jockstickData = new JockstickData("131699800539070353");
|
|
jockstickData.setCurrentPos(0.0f, 0.0f);
|
|
jockstickData.setConfig(new JockstickConfig());
|
|
controllerData.addJockstickData(jockstickData);
|
|
controllerData.addAccumulatorData(new AccumulatorData(IDGenerator.a(System.currentTimeMillis()), (byte) 1, 10, 160, 200.0f, 300.0f));
|
|
ControllerManager.a(getApplicationContext()).a(Cache.getInstance().getRobot().getRobotLite());
|
|
ControllerManager.a(getApplicationContext()).a(controllerData, false);
|
|
}
|
|
|
|
public /* synthetic */ void b(View view) {
|
|
l();
|
|
}
|
|
|
|
public /* synthetic */ void c(View view) {
|
|
j();
|
|
}
|
|
|
|
public /* synthetic */ void d(View view) {
|
|
h();
|
|
}
|
|
|
|
public /* synthetic */ void e(View view) {
|
|
g();
|
|
}
|
|
|
|
public /* synthetic */ void g(View view) {
|
|
c();
|
|
}
|
|
|
|
public /* synthetic */ void h(View view) {
|
|
o();
|
|
}
|
|
|
|
public /* synthetic */ void i(View view) {
|
|
p();
|
|
}
|
|
|
|
public /* synthetic */ void j(View view) {
|
|
s();
|
|
}
|
|
|
|
public /* synthetic */ void k(View view) {
|
|
q();
|
|
}
|
|
|
|
public /* synthetic */ void l(View view) {
|
|
r();
|
|
}
|
|
|
|
public /* synthetic */ void m(View view) {
|
|
v();
|
|
}
|
|
|
|
public /* synthetic */ void n(View view) {
|
|
b();
|
|
}
|
|
|
|
public /* synthetic */ void o(View view) {
|
|
a(this.b);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
ARouter.a(getApplication());
|
|
setContentView(R.layout.test_controller);
|
|
a();
|
|
f();
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
|
|
if (i == 1 && !PermissionUtils.a(strArr, iArr)) {
|
|
finish();
|
|
}
|
|
super.onRequestPermissionsResult(i, strArr, iArr);
|
|
}
|
|
|
|
public /* synthetic */ void p(View view) {
|
|
n();
|
|
}
|
|
|
|
public /* synthetic */ void q(View view) {
|
|
m();
|
|
}
|
|
|
|
public /* synthetic */ void r(View view) {
|
|
i();
|
|
}
|
|
|
|
private void b() {
|
|
Postcard a = ARouter.b().a("/controller/control");
|
|
a.a("robotLite", Cache.getInstance().getRobot().getRobotLite());
|
|
a.t();
|
|
}
|
|
|
|
private void c() {
|
|
Postcard a = ARouter.b().a("/controller/servosettings");
|
|
a.a("robotLite", Cache.getInstance().getRobot().getRobotLite());
|
|
a.t();
|
|
}
|
|
|
|
private ActionSequence d() {
|
|
ActionManager a = ActionManager.a(this);
|
|
Robot robot = Cache.getInstance().getRobot();
|
|
if (robot != null) {
|
|
a.a(robot.getRobotLite());
|
|
}
|
|
return a.a("actions_95d4b4b7-1ce5-44d9-b0df-fc5823aa7f1f");
|
|
}
|
|
|
|
private CommandManager e() {
|
|
CommandManager a = CommandManager.a(getApplicationContext());
|
|
JimuManager jimuManager = this.a;
|
|
if (jimuManager != null) {
|
|
a.a(jimuManager);
|
|
}
|
|
return a;
|
|
}
|
|
|
|
private void g() {
|
|
TreeMap treeMap = new TreeMap();
|
|
treeMap.put(1, new TurnData(1, 658));
|
|
treeMap.put(2, new TurnData(2, 658));
|
|
e().a((MoveCommand) new TurnCommand(treeMap), false);
|
|
}
|
|
|
|
private void h() {
|
|
TreeMap treeMap = new TreeMap();
|
|
treeMap.put(1, new TurnData(2, 658));
|
|
treeMap.put(2, new TurnData(1, 658));
|
|
e().a((MoveCommand) new TurnCommand(treeMap), false);
|
|
}
|
|
|
|
private void i() {
|
|
TreeMap treeMap = new TreeMap();
|
|
treeMap.put(1, new TurnData(2, PeripheralType.SERVO));
|
|
treeMap.put(2, new TurnData(1, 658));
|
|
e().a((MoveCommand) new TurnCommand(treeMap), false);
|
|
}
|
|
|
|
private void j() {
|
|
TreeMap treeMap = new TreeMap();
|
|
treeMap.put(1, new TurnData(2, 658));
|
|
treeMap.put(2, new TurnData(1, PeripheralType.SERVO));
|
|
e().a((MoveCommand) new TurnCommand(treeMap), false);
|
|
}
|
|
|
|
private void k() {
|
|
TreeMap treeMap = new TreeMap();
|
|
treeMap.put(1, new TurnData(0, PeripheralType.SERVO));
|
|
treeMap.put(2, new TurnData(0, 658));
|
|
e().a((MoveCommand) new TurnCommand(treeMap), true);
|
|
}
|
|
|
|
private void l() {
|
|
ActionSequence d = d();
|
|
if (d != null) {
|
|
e().a(d);
|
|
}
|
|
}
|
|
|
|
private void m() {
|
|
e().b(new EngineManager(this, Cache.getInstance().getRobot().getRobotLite()).getEngineList(Cache.getInstance().getUserId()));
|
|
}
|
|
|
|
private void n() {
|
|
this.c = new JimuScanner(getApplicationContext()).a(new ScannedHubEmitter() { // from class: com.ubt.jimu.test.ControllerTestActivity.2
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
|
public void a(ScanResult scanResult) {
|
|
BluetoothDevice a = scanResult.a();
|
|
XLog.a("woo", "Scaned device:" + a.getName() + " mac:" + a.getAddress());
|
|
if (a.getName().contains("1C40")) {
|
|
XLog.a("woo", "Discoverd jimu %s", a.getName());
|
|
Toast.makeText(ControllerTestActivity.this, "find robot success " + a.getName(), 0).show();
|
|
ControllerTestActivity.this.b = a;
|
|
}
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
|
public void a(int i, String str) {
|
|
XLog.a("woo", "Discover onFail! errCode:" + str + " errMsg:" + str);
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.base.discover.ScannedHubEmitter
|
|
public void a() {
|
|
XLog.a("woo", "Discover onTimeup");
|
|
}
|
|
}, 5000);
|
|
}
|
|
|
|
private void o() {
|
|
List<Engine> engineList = new EngineManager(this, Cache.getInstance().getRobot().getRobotLite()).getEngineList(Cache.getInstance().getUserId());
|
|
if (engineList == null || engineList.size() <= 0) {
|
|
return;
|
|
}
|
|
XLog.a("woo", "engineList: %s", engineList.toString());
|
|
}
|
|
|
|
private void p() {
|
|
List<Servo> servoList = new EngineManager(this, Cache.getInstance().getRobot().getRobotLite()).getServoList(Cache.getInstance().getUserId());
|
|
if (servoList == null || servoList.size() <= 0) {
|
|
return;
|
|
}
|
|
XLog.a("woo", "servolist: %s", servoList.toString());
|
|
}
|
|
|
|
private void q() {
|
|
e().b(d());
|
|
}
|
|
|
|
private void r() {
|
|
e().a(new EngineManager(this, Cache.getInstance().getRobot().getRobotLite()).getEngineList(Cache.getInstance().getUserId()));
|
|
}
|
|
|
|
public /* synthetic */ void a(View view) {
|
|
u();
|
|
}
|
|
|
|
private Map<Integer, MotorData> a(String[] strArr, String[] strArr2, int i, int i2, int i3) {
|
|
TreeMap treeMap = new TreeMap();
|
|
if (strArr != null && strArr.length > 0) {
|
|
int i4 = i == -1 ? 1 : -1;
|
|
for (String str : strArr) {
|
|
treeMap.put(Integer.valueOf(str), new MotorData(i4, i2, i3));
|
|
}
|
|
}
|
|
if (strArr2 != null && strArr2.length > 0) {
|
|
int i5 = i != 1 ? 1 : -1;
|
|
for (String str2 : strArr2) {
|
|
treeMap.put(Integer.valueOf(str2), new MotorData(i5, i2, i3));
|
|
}
|
|
}
|
|
return treeMap;
|
|
}
|
|
|
|
private void a(BluetoothDevice bluetoothDevice) {
|
|
if (bluetoothDevice == null) {
|
|
return;
|
|
}
|
|
Cancellable cancellable = this.c;
|
|
if (cancellable != null && !cancellable.isCancelled()) {
|
|
this.c.cancel();
|
|
}
|
|
if (this.a == null) {
|
|
this.a = JimuApplication.l().f();
|
|
}
|
|
this.a.a(bluetoothDevice.getAddress(), new ConnectCallback() { // from class: com.ubt.jimu.test.ControllerTestActivity.1
|
|
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
|
|
public void a(int i, String str) {
|
|
XLog.b("woo", "Conncet fail! errMsg:" + str);
|
|
}
|
|
|
|
@Override // com.ubtrobot.jimu.bluetooth.ConnectCallback
|
|
public void onSuccess() {
|
|
XLog.a("woo", "Connect success");
|
|
ToastView.a(ControllerTestActivity.this, "connect robot success").a();
|
|
CommandManager.a(ControllerTestActivity.this.getApplicationContext()).a(ControllerTestActivity.this.a);
|
|
}
|
|
});
|
|
}
|
|
|
|
private boolean a() {
|
|
return PermissionUtils.a(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"}, 1);
|
|
}
|
|
|
|
public /* synthetic */ void f(View view) {
|
|
k();
|
|
}
|
|
}
|