Initial commit
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.controller.data.command.AngleCommand;
|
||||
import com.ubt.jimu.controller.data.command.MoveCommand;
|
||||
import com.ubt.jimu.controller.data.config.AccumulatorConfig;
|
||||
import com.ubt.jimu.controller.manager.CommandManager;
|
||||
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
||||
import com.ubt.jimu.controller.view.IAccumulatorSettingView;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AccumulatorSettingPresenter extends SuperControllerPresenter<IAccumulatorSettingView> {
|
||||
public AccumulatorSettingPresenter(Context context, RobotLite robotLite) {
|
||||
super(context, robotLite);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public boolean a(RobotLite robotLite) {
|
||||
IAccumulatorSettingView iAccumulatorSettingView;
|
||||
boolean a = super.a(robotLite);
|
||||
if (!a && (iAccumulatorSettingView = (IAccumulatorSettingView) b()) != null) {
|
||||
iAccumulatorSettingView.Y();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
protected void b(List<? extends Engine> list) {
|
||||
List<AccumulatorConfig> a;
|
||||
if (list == null || list.size() <= 0 || (a = MoveConfigManager.a(this.c.getApplicationContext()).a()) == null || a.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
Iterator<AccumulatorConfig> it = a.iterator();
|
||||
while (it.hasNext()) {
|
||||
int servoID = it.next().getServoID();
|
||||
for (Engine engine : list) {
|
||||
if (servoID == engine.getId()) {
|
||||
engine.setConfigged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public boolean c(RobotLite robotLite) {
|
||||
return super.c(robotLite);
|
||||
}
|
||||
|
||||
public void a(AccumulatorConfig accumulatorConfig) {
|
||||
MoveConfigManager a = MoveConfigManager.a(this.c.getApplicationContext());
|
||||
a.b(accumulatorConfig);
|
||||
a.a(true);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public String a(int i, ServoMode servoMode) {
|
||||
IAccumulatorSettingView iAccumulatorSettingView;
|
||||
String a = super.a(i, servoMode);
|
||||
if (TextUtils.isEmpty(a) || (iAccumulatorSettingView = (IAccumulatorSettingView) b()) == null) {
|
||||
return "";
|
||||
}
|
||||
iAccumulatorSettingView.d(String.format(this.c.getResources().getString(R.string.control_servo_mode_set), a));
|
||||
return "";
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite, int i, int i2) {
|
||||
if (!c(robotLite) || super.e()) {
|
||||
return;
|
||||
}
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(i), Integer.valueOf(i2 + 120));
|
||||
CommandManager.a(this.c.getApplicationContext()).a((MoveCommand) new AngleCommand(hashMap, 200, 0), false);
|
||||
}
|
||||
|
||||
public void a(final int i) {
|
||||
if (c(this.d)) {
|
||||
Observable.create(new ObservableOnSubscribe<List<ServoAngleReadInfo>>() { // from class: com.ubt.jimu.controller.presenter.AccumulatorSettingPresenter.1
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<ServoAngleReadInfo>> observableEmitter) throws Exception {
|
||||
if (AccumulatorSettingPresenter.this.d() != null) {
|
||||
long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||
List<ServoAngleReadInfo> a = AccumulatorSettingPresenter.this.d().a(i, true);
|
||||
if (a == null || a.size() <= 0) {
|
||||
observableEmitter.onError(new Throwable("read servo angle failed"));
|
||||
return;
|
||||
}
|
||||
for (ServoAngleReadInfo servoAngleReadInfo : a) {
|
||||
servoAngleReadInfo.a(servoAngleReadInfo.a() - 120.0f);
|
||||
}
|
||||
XLog.a("Controller", "readAllServoAngle cost time: %d", Long.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime));
|
||||
observableEmitter.onNext(a);
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<List<ServoAngleReadInfo>>() { // from class: com.ubt.jimu.controller.presenter.AccumulatorSettingPresenter.2
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(List<ServoAngleReadInfo> list) throws Exception {
|
||||
XLog.a("Controller", "servoAngle: %s", list.toString());
|
||||
IAccumulatorSettingView iAccumulatorSettingView = (IAccumulatorSettingView) AccumulatorSettingPresenter.this.b();
|
||||
if (iAccumulatorSettingView != null) {
|
||||
iAccumulatorSettingView.g(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.controller.data.command.AngleCommand;
|
||||
import com.ubt.jimu.controller.data.command.MoveCommand;
|
||||
import com.ubt.jimu.controller.data.config.HSliderConfig;
|
||||
import com.ubt.jimu.controller.manager.CommandManager;
|
||||
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
||||
import com.ubt.jimu.controller.view.IAngleSettingView;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.robotapi.ServoAngleReadInfo;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class AngleSettingPresenter extends SuperControllerPresenter<IAngleSettingView> {
|
||||
public AngleSettingPresenter(Context context, RobotLite robotLite) {
|
||||
super(context, robotLite);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public String a(int i, ServoMode servoMode) {
|
||||
IAngleSettingView iAngleSettingView;
|
||||
String a = super.a(i, servoMode);
|
||||
if (TextUtils.isEmpty(a) || (iAngleSettingView = (IAngleSettingView) b()) == null) {
|
||||
return "";
|
||||
}
|
||||
iAngleSettingView.d(String.format(this.c.getResources().getString(R.string.control_servo_mode_set), a));
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
void b(List<? extends Engine> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
XLog.a("woo", "servolist: %s", list.toString());
|
||||
List<HSliderConfig> c = MoveConfigManager.a(this.c.getApplicationContext()).c();
|
||||
if (c == null || c.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
Iterator<HSliderConfig> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
int servoID = it.next().getServoID();
|
||||
for (Engine engine : list) {
|
||||
if (servoID == engine.getId()) {
|
||||
engine.setConfigged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(HSliderConfig hSliderConfig) {
|
||||
MoveConfigManager a = MoveConfigManager.a(this.c.getApplicationContext());
|
||||
a.b(hSliderConfig);
|
||||
a.a(true);
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite, int i, int i2) {
|
||||
if (!c(robotLite) || super.e()) {
|
||||
return;
|
||||
}
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(i), Integer.valueOf(i2 + 120));
|
||||
CommandManager.a(this.c.getApplicationContext()).a((MoveCommand) new AngleCommand(hashMap, 200, 0), false);
|
||||
}
|
||||
|
||||
public void a(final int i) {
|
||||
if (c(this.d)) {
|
||||
Observable.create(new ObservableOnSubscribe<List<ServoAngleReadInfo>>() { // from class: com.ubt.jimu.controller.presenter.AngleSettingPresenter.1
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<ServoAngleReadInfo>> observableEmitter) throws Exception {
|
||||
if (AngleSettingPresenter.this.d() != null) {
|
||||
long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||
List<ServoAngleReadInfo> a = AngleSettingPresenter.this.d().a(i, true);
|
||||
if (a == null || a.size() <= 0) {
|
||||
observableEmitter.onError(new Throwable("read servo angle failed"));
|
||||
return;
|
||||
}
|
||||
for (ServoAngleReadInfo servoAngleReadInfo : a) {
|
||||
servoAngleReadInfo.a(servoAngleReadInfo.a() - 120.0f);
|
||||
}
|
||||
XLog.a("Controller", "readAllServoAngle cost time: %d", Long.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime));
|
||||
observableEmitter.onNext(a);
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<List<ServoAngleReadInfo>>() { // from class: com.ubt.jimu.controller.presenter.AngleSettingPresenter.2
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(List<ServoAngleReadInfo> list) throws Exception {
|
||||
XLog.a("Controller", "servoAngle: %s", list.toString());
|
||||
IAngleSettingView iAngleSettingView = (IAngleSettingView) AngleSettingPresenter.this.b();
|
||||
if (iAngleSettingView != null) {
|
||||
iAngleSettingView.g(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
28
sources/com/ubt/jimu/controller/presenter/BasePresenter.java
Normal file
28
sources/com/ubt/jimu/controller/presenter/BasePresenter.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class BasePresenter<V> {
|
||||
private WeakReference<V> a;
|
||||
|
||||
protected void a(V v) {
|
||||
this.a = new WeakReference<>(v);
|
||||
}
|
||||
|
||||
protected V b() {
|
||||
WeakReference<V> weakReference = this.a;
|
||||
if (weakReference != null) {
|
||||
return weakReference.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void a() {
|
||||
WeakReference<V> weakReference = this.a;
|
||||
if (weakReference != null) {
|
||||
weakReference.clear();
|
||||
this.a = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,704 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
import com.orhanobut.logger.Printer;
|
||||
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.cache.SharePreferenceHelper;
|
||||
import com.ubt.jimu.base.data.CtrlMotionType;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
||||
import com.ubt.jimu.base.db.diy.DiyHelper;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.http.ApiResponse;
|
||||
import com.ubt.jimu.connect.ConnectActivity;
|
||||
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.AccumulatorGear;
|
||||
import com.ubt.jimu.controller.data.command.AngleCommand;
|
||||
import com.ubt.jimu.controller.data.command.Gear;
|
||||
import com.ubt.jimu.controller.data.command.MotorCommand;
|
||||
import com.ubt.jimu.controller.data.command.MoveCommand;
|
||||
import com.ubt.jimu.controller.data.command.ShootCommand;
|
||||
import com.ubt.jimu.controller.data.command.TurnCommand;
|
||||
import com.ubt.jimu.controller.data.config.AccumulatorConfig;
|
||||
import com.ubt.jimu.controller.data.config.HSliderConfig;
|
||||
import com.ubt.jimu.controller.data.config.JockstickConfig;
|
||||
import com.ubt.jimu.controller.data.config.SliderConfig;
|
||||
import com.ubt.jimu.controller.data.config.Wheel;
|
||||
import com.ubt.jimu.controller.data.config.WidgetConfig;
|
||||
import com.ubt.jimu.controller.data.keymap.KeyMap;
|
||||
import com.ubt.jimu.controller.data.keymap.entity.Key;
|
||||
import com.ubt.jimu.controller.data.widget.ControllerData;
|
||||
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.manager.KeyMapManager;
|
||||
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
||||
import com.ubt.jimu.controller.syn.OfficialSyncExecutor;
|
||||
import com.ubt.jimu.controller.view.IControllerView;
|
||||
import com.ubt.jimu.transport3.DiyTransportServiceImpl;
|
||||
import com.ubt.jimu.transport3.bean.response.SaveOrUpdateModelBean;
|
||||
import com.ubt.jimu.transport3.dao.DiyDBModelDBHandler;
|
||||
import com.ubt.jimu.utils.LocaleUtils;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import com.ubt.jimu.utils.SystemUtils;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.bluetooth.ConnectionState;
|
||||
import com.ubtrobot.jimu.robotapi.BatteryInfo;
|
||||
import com.ubtrobot.jimu.robotapi.JimuException;
|
||||
import com.ubtrobot.jimu.robotapi.JimuManager;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ControllerPresenter extends SuperControllerPresenter<IControllerView> {
|
||||
private HandlerThread f;
|
||||
private Handler g;
|
||||
private KeyMapManager h;
|
||||
private List<KeyMap> i;
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
public ControllerPresenter(Context context, RobotLite robotLite) {
|
||||
super(context, robotLite);
|
||||
this.i = new ArrayList();
|
||||
a((ControllerPresenter) context);
|
||||
this.f = new HandlerThread("ControllerThread");
|
||||
this.f.start();
|
||||
this.g = new Handler(this.f.getLooper());
|
||||
CommandManager.a(this.c.getApplicationContext()).a(JimuApplication.l().f());
|
||||
this.h = new KeyMapManager(context);
|
||||
}
|
||||
|
||||
private void A() {
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.z();
|
||||
}
|
||||
}
|
||||
|
||||
private MoveCommand c(int i, Gear gear, int i2, Gear gear2, JockstickConfig jockstickConfig) {
|
||||
TreeMap treeMap = new TreeMap();
|
||||
List<Wheel> wheelList = jockstickConfig.getWheelList();
|
||||
if (wheelList == null || wheelList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (Wheel wheel : wheelList) {
|
||||
if (wheel != null) {
|
||||
if (wheel.getPosition() % 2 == 0) {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new TurnData(wheel.isReverse() ? -i2 : i2, gear2.getTurnSpeed()));
|
||||
} else {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new TurnData(wheel.isReverse() ? -i : i, gear.getTurnSpeed()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TurnCommand(treeMap);
|
||||
}
|
||||
|
||||
public float a(float f) {
|
||||
if (f < 0.1f) {
|
||||
return 0.0f;
|
||||
}
|
||||
if (f < 0.4f) {
|
||||
return 0.4f;
|
||||
}
|
||||
return f < 0.7f ? 0.7f : 1.0f;
|
||||
}
|
||||
|
||||
public void a(RobotLite robotLite, String str) {
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (robotLite == null || TextUtils.isEmpty(robotLite.getModelId())) {
|
||||
XLog.b("woo", "Robot is null");
|
||||
if (iControllerView != null) {
|
||||
iControllerView.j();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.d = robotLite;
|
||||
ControllerManager.a(this.c.getApplicationContext()).a(robotLite);
|
||||
ControllerData a = ControllerManager.a(this.c.getApplicationContext()).a();
|
||||
Printer a2 = ALog.a("woo");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("controllerData: ");
|
||||
sb.append(a != null ? a.toString() : "ControllerData is Null!");
|
||||
a2.d(sb.toString());
|
||||
if (this.b == null) {
|
||||
b(robotLite);
|
||||
this.b.createPeripheralConn(str);
|
||||
}
|
||||
CommandManager.a(this.c.getApplicationContext()).a(this.b);
|
||||
m();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.a(a);
|
||||
}
|
||||
}
|
||||
|
||||
public void b(ActionSequence actionSequence) {
|
||||
if (actionSequence != null) {
|
||||
CommandManager.a(this.c.getApplicationContext()).c(actionSequence);
|
||||
A();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
void b(List<? extends Engine> list) {
|
||||
}
|
||||
|
||||
public void d(RobotLite robotLite) {
|
||||
this.h.a(robotLite);
|
||||
this.h.c();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public boolean e() {
|
||||
BatteryInfo f = JimuApplication.l().f().f();
|
||||
if (f == null || !f.d()) {
|
||||
return false;
|
||||
}
|
||||
return new SharePreferenceHelper().getBoolean(SharePreferenceHelper.SP_KEY_ELECTRICITY_PROTECT, true).booleanValue();
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public void h() {
|
||||
if (r()) {
|
||||
y();
|
||||
}
|
||||
Handler handler = this.g;
|
||||
if (handler != null) {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
this.f.quit();
|
||||
this.f = null;
|
||||
}
|
||||
super.h();
|
||||
}
|
||||
|
||||
public void k() {
|
||||
ALog.a("ControllerPresenter").d("clearTmpMapList");
|
||||
this.i.clear();
|
||||
}
|
||||
|
||||
public void l() {
|
||||
if (this.d.isOfficial()) {
|
||||
Robot robotByModelName = RobotDbHandler.getRobotByModelName(this.d.getModelId());
|
||||
if (robotByModelName != null) {
|
||||
ConnectActivity.a(101, (Activity) this.c, robotByModelName.getRobotLite());
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
DiyDBModel queryForUUid = DiyHelper.getInstance().queryForUUid(this.d.getModelId());
|
||||
if (queryForUUid != null) {
|
||||
ConnectActivity.a(101, (Activity) this.c, queryForUUid.getRobotLite());
|
||||
}
|
||||
}
|
||||
|
||||
public void m() {
|
||||
List<KeyMap> o = o();
|
||||
ArrayList<KeyMap> arrayList = new ArrayList();
|
||||
for (KeyMap keyMap : o) {
|
||||
if (ActionManager.a(this.c).a(keyMap.a()) == null) {
|
||||
arrayList.add(keyMap);
|
||||
}
|
||||
}
|
||||
for (KeyMap keyMap2 : arrayList) {
|
||||
this.h.a(keyMap2);
|
||||
ALog.a("ControllerPresenter").d("Action has be deleted! delete keymap:" + keyMap2);
|
||||
}
|
||||
}
|
||||
|
||||
public void n() {
|
||||
if (this.d.isOfficial()) {
|
||||
Robot robotByModelName = RobotDbHandler.getRobotByModelName(this.d.getModelId());
|
||||
if (robotByModelName != null) {
|
||||
ConnectActivity.b(102, (Activity) this.c, robotByModelName.getRobotLite());
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
DiyDBModel queryForUUid = DiyHelper.getInstance().queryForUUid(this.d.getModelId());
|
||||
if (queryForUUid != null) {
|
||||
ConnectActivity.b(102, (Activity) this.c, queryForUUid.getRobotLite());
|
||||
}
|
||||
}
|
||||
|
||||
public List<KeyMap> o() {
|
||||
return this.h.a();
|
||||
}
|
||||
|
||||
public ArrayList<Integer> p() {
|
||||
ArrayList<Integer> arrayList = new ArrayList<>();
|
||||
for (int i : InputDevice.getDeviceIds()) {
|
||||
int sources = InputDevice.getDevice(i).getSources();
|
||||
if ((sources & 1025) == 1025 && (sources & 16777232) == 16777232 && !arrayList.contains(Integer.valueOf(i))) {
|
||||
arrayList.add(Integer.valueOf(i));
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public List<KeyMap> q() {
|
||||
return this.h.b();
|
||||
}
|
||||
|
||||
public boolean r() {
|
||||
JimuManager f = JimuApplication.l().f();
|
||||
return f != null && f.b(this.d.getModelId()) == ConnectionState.STATE_CONNECTED;
|
||||
}
|
||||
|
||||
public boolean s() {
|
||||
ArrayList<Integer> p = p();
|
||||
return (p == null || p.isEmpty()) ? false : true;
|
||||
}
|
||||
|
||||
public /* synthetic */ void t() {
|
||||
try {
|
||||
a(JimuApplication.l().f().k());
|
||||
} catch (JimuException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void u() {
|
||||
ALog.a("ControllerPresenter").d("loadTmpKeyMapList");
|
||||
k();
|
||||
c(o());
|
||||
List<KeyMap> q = q();
|
||||
if (q == null || q.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
c(q);
|
||||
}
|
||||
|
||||
public void v() {
|
||||
CommandManager.a(this.c.getApplicationContext()).b(this.b.getEngineList(Cache.getInstance().getUserId()));
|
||||
}
|
||||
|
||||
public void w() {
|
||||
this.g.post(new Runnable() { // from class: com.ubt.jimu.controller.presenter.b
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
ControllerPresenter.this.t();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void x() {
|
||||
ALog.a("ControllerPresenter").d("saveMapList");
|
||||
this.h.b(this.i);
|
||||
}
|
||||
|
||||
public void y() {
|
||||
if (this.b != null) {
|
||||
CommandManager.a(this.c.getApplicationContext()).a(this.b.getEngineList(Cache.getInstance().getUserId()));
|
||||
}
|
||||
}
|
||||
|
||||
public void z() {
|
||||
DiyDBModel queryForUUid;
|
||||
if (this.d.isOfficial() || (queryForUUid = DiyHelper.getInstance().queryForUUid(this.d.getModelId())) == null || queryForUUid.isControllerComplete()) {
|
||||
return;
|
||||
}
|
||||
queryForUUid.setControllerComplete();
|
||||
long a = SystemUtils.a();
|
||||
queryForUUid.setModifyTime(a);
|
||||
queryForUUid.setLastUploadTime(a);
|
||||
queryForUUid.setIsModify(true);
|
||||
DiyDBModelDBHandler.getInstance().insertOrUpdate(queryForUUid);
|
||||
a(queryForUUid);
|
||||
}
|
||||
|
||||
private void b(List<Integer> list, ServoMode servoMode) {
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.a(list, servoMode);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean b(int i, ServoMode servoMode) {
|
||||
EngineManager engineManager = this.b;
|
||||
if (engineManager == null || engineManager.getServoMode(i) == servoMode) {
|
||||
return true;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.add(Integer.valueOf(i));
|
||||
b(arrayList, servoMode);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void e(RobotLite robotLite) {
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.c();
|
||||
}
|
||||
this.d = robotLite;
|
||||
ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();
|
||||
OfficialSyncExecutor officialSyncExecutor = new OfficialSyncExecutor(this.d);
|
||||
officialSyncExecutor.a(new OfficialSyncExecutor.SyncCompletedListener() { // from class: com.ubt.jimu.controller.presenter.ControllerPresenter.2
|
||||
@Override // com.ubt.jimu.controller.syn.OfficialSyncExecutor.SyncCompletedListener
|
||||
public void a() {
|
||||
LogUtils.c("syncOfficialData 下载逻辑全部完成");
|
||||
ControllerPresenter controllerPresenter = ControllerPresenter.this;
|
||||
controllerPresenter.a(controllerPresenter.d, Cache.getInstance().getUserId());
|
||||
}
|
||||
});
|
||||
newSingleThreadExecutor.submit(officialSyncExecutor);
|
||||
}
|
||||
|
||||
private MoveCommand b(int i, Gear gear, int i2, Gear gear2, JockstickConfig jockstickConfig) {
|
||||
TreeMap treeMap = new TreeMap();
|
||||
List<Wheel> wheelList = jockstickConfig.getWheelList();
|
||||
if (wheelList == null || wheelList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (Wheel wheel : wheelList) {
|
||||
if (wheel != null) {
|
||||
if (wheel.getPosition() % 2 == 0) {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new MotorData(wheel.isReverse() ? -i2 : i2, gear2.getMotorSpeed(), 6553500));
|
||||
} else {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new MotorData(wheel.isReverse() ? -i : i, gear.getMotorSpeed(), 6553500));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new MotorCommand(treeMap);
|
||||
}
|
||||
|
||||
private MoveCommand c(int i, float f, int i2, float f2, JockstickConfig jockstickConfig) {
|
||||
TreeMap treeMap = new TreeMap();
|
||||
List<Wheel> wheelList = jockstickConfig.getWheelList();
|
||||
if (wheelList == null || wheelList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (Wheel wheel : wheelList) {
|
||||
if (wheel != null) {
|
||||
if (wheel.getPosition() % 2 == 0) {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new TurnData(wheel.isReverse() ? -i2 : i2, (int) (TurnData.e() * f2)));
|
||||
} else {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new TurnData(wheel.isReverse() ? -i : i, (int) (TurnData.e() * f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new TurnCommand(treeMap);
|
||||
}
|
||||
|
||||
public void a(ControllerData controllerData) {
|
||||
ControllerManager.a(this.c.getApplicationContext()).a(controllerData, true);
|
||||
}
|
||||
|
||||
public void a(DiyDBModel diyDBModel) {
|
||||
if (diyDBModel.getModelId().intValue() <= 0) {
|
||||
return;
|
||||
}
|
||||
DiyTransportServiceImpl.getInstance().updateModel(diyDBModel, new Observer<ApiResponse<SaveOrUpdateModelBean>>(this) { // from class: com.ubt.jimu.controller.presenter.ControllerPresenter.1
|
||||
@Override // io.reactivex.Observer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onNext(ApiResponse<SaveOrUpdateModelBean> apiResponse) {
|
||||
XLog.a("Controller", "updateModel onNext");
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onComplete() {
|
||||
XLog.a("Controller", "updateModel complete");
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onError(Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void a(ActionSequence actionSequence) {
|
||||
if (actionSequence != null) {
|
||||
LogUtils.c("ControllerPresenter playAction:" + actionSequence.a().get(0).c());
|
||||
String a = actionSequence.a(LocaleUtils.b());
|
||||
if (TextUtils.isEmpty(a)) {
|
||||
a = actionSequence.h();
|
||||
}
|
||||
a((String) null, a, (String) null);
|
||||
CommandManager.a(this.c.getApplicationContext()).a(actionSequence);
|
||||
}
|
||||
}
|
||||
|
||||
private MoveCommand b(int i, float f, int i2, float f2, JockstickConfig jockstickConfig) {
|
||||
TreeMap treeMap = new TreeMap();
|
||||
List<Wheel> wheelList = jockstickConfig.getWheelList();
|
||||
if (wheelList == null || wheelList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (Wheel wheel : wheelList) {
|
||||
if (wheel != null) {
|
||||
if (wheel.getPosition() % 2 == 0) {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new MotorData(wheel.isReverse() ? -i2 : i2, (int) (MotorData.e() * f2), 6553500));
|
||||
} else {
|
||||
treeMap.put(Integer.valueOf(wheel.getId()), new MotorData(wheel.isReverse() ? -i : i, (int) (MotorData.e() * f), 6553500));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new MotorCommand(treeMap);
|
||||
}
|
||||
|
||||
public void c(List<KeyMap> list) {
|
||||
ALog.a("ControllerPresenter").d("addTmpKeyMapAllList");
|
||||
for (KeyMap keyMap : list) {
|
||||
ALog.a("ControllerPresenter").d("add tmp keyMap:" + keyMap);
|
||||
}
|
||||
this.i.addAll(list);
|
||||
}
|
||||
|
||||
private void a(String str, String str2, String str3) {
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.a(str, str2, str3);
|
||||
}
|
||||
}
|
||||
|
||||
private void a(BatteryInfo batteryInfo) {
|
||||
XLog.c("woo", "BatteryInfo : %s", batteryInfo.toString());
|
||||
IControllerView iControllerView = (IControllerView) b();
|
||||
if (iControllerView != null) {
|
||||
iControllerView.a(batteryInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private Gear b(float f) {
|
||||
if (f < 0.1f) {
|
||||
return Gear.EMPTY;
|
||||
}
|
||||
if (f < 0.3f) {
|
||||
return Gear.FIRST;
|
||||
}
|
||||
if (f < 0.5f) {
|
||||
return Gear.SECOND;
|
||||
}
|
||||
if (f < 0.7f) {
|
||||
return Gear.THIRD;
|
||||
}
|
||||
if (f < 0.9f) {
|
||||
return Gear.FOURTH;
|
||||
}
|
||||
return Gear.FIFTH;
|
||||
}
|
||||
|
||||
public void a(MoveCommand moveCommand, boolean z) {
|
||||
CommandManager.a(this.c.getApplicationContext()).a(moveCommand, z);
|
||||
}
|
||||
|
||||
public void a(SliderConfig sliderConfig, Gear gear, int i) {
|
||||
MoveCommand a;
|
||||
int servoID = sliderConfig.getServoID();
|
||||
sliderConfig.getMotionType();
|
||||
if ((sliderConfig.getMotionType() != CtrlMotionType.servo || b(servoID, ServoMode.SERVO_MODE_TURN)) && (a = a(sliderConfig, gear, i, servoID)) != null) {
|
||||
a(a, gear == Gear.EMPTY || i == 0);
|
||||
}
|
||||
}
|
||||
|
||||
private MoveCommand a(SliderConfig sliderConfig, Gear gear, int i, int i2) {
|
||||
if (sliderConfig.getMotionType() == CtrlMotionType.servo) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(i2), new TurnData(i, gear.getTurnSpeed()));
|
||||
return new TurnCommand(hashMap);
|
||||
}
|
||||
if (sliderConfig.getMotionType() != CtrlMotionType.motor) {
|
||||
return null;
|
||||
}
|
||||
HashMap hashMap2 = new HashMap(1);
|
||||
hashMap2.put(Integer.valueOf(i2), new MotorData(i, gear.getMotorSpeed(), 6553500));
|
||||
return new MotorCommand(hashMap2);
|
||||
}
|
||||
|
||||
private boolean a(List<Integer> list, ServoMode servoMode) {
|
||||
boolean z = true;
|
||||
if (this.b != null && list != null && list.size() > 0) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Iterator<Integer> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
int intValue = it.next().intValue();
|
||||
if (this.b.getServoMode(intValue) != servoMode) {
|
||||
arrayList.add(Integer.valueOf(intValue));
|
||||
z = false;
|
||||
}
|
||||
}
|
||||
if (!z) {
|
||||
b(arrayList, servoMode);
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
public void a(HSliderConfig hSliderConfig, int i) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
int servoID = hSliderConfig.getServoID();
|
||||
CtrlMotionType ctrlMotionType = CtrlMotionType.servo;
|
||||
if (b(servoID, ServoMode.SERVO_MODE_ANGLE)) {
|
||||
hashMap.put(Integer.valueOf(servoID), Integer.valueOf(i + 120));
|
||||
a((MoveCommand) new AngleCommand(hashMap, 200, 0), false);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(AccumulatorConfig accumulatorConfig, int i) {
|
||||
int servoID = accumulatorConfig.getServoID();
|
||||
CtrlMotionType ctrlMotionType = CtrlMotionType.servo;
|
||||
if (b(servoID, ServoMode.SERVO_MODE_ANGLE)) {
|
||||
a((MoveCommand) new ShootCommand(accumulatorConfig, i), false);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(int i, Gear gear, int i2, Gear gear2, JockstickConfig jockstickConfig) {
|
||||
if (jockstickConfig != null) {
|
||||
MoveCommand moveCommand = null;
|
||||
jockstickConfig.getMotionType();
|
||||
if (jockstickConfig.getMotionType() == CtrlMotionType.servo) {
|
||||
if (!a(jockstickConfig.getServoList(), ServoMode.SERVO_MODE_TURN)) {
|
||||
return;
|
||||
} else {
|
||||
moveCommand = c(i, gear, i2, gear2, jockstickConfig);
|
||||
}
|
||||
} else if (jockstickConfig.getMotionType() == CtrlMotionType.motor) {
|
||||
moveCommand = b(i, gear, i2, gear2, jockstickConfig);
|
||||
}
|
||||
if (moveCommand != null) {
|
||||
a(moveCommand, (gear == Gear.EMPTY || i == 0) && (gear2 == Gear.EMPTY || i2 == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(int i, float f, int i2, float f2, JockstickConfig jockstickConfig) {
|
||||
if (jockstickConfig != null) {
|
||||
MoveCommand moveCommand = null;
|
||||
jockstickConfig.getMotionType();
|
||||
if (jockstickConfig.getMotionType() == CtrlMotionType.servo) {
|
||||
if (!a(jockstickConfig.getServoList(), ServoMode.SERVO_MODE_TURN)) {
|
||||
return;
|
||||
} else {
|
||||
moveCommand = c(i, f, i2, f2, jockstickConfig);
|
||||
}
|
||||
} else if (jockstickConfig.getMotionType() == CtrlMotionType.motor) {
|
||||
moveCommand = b(i, f, i2, f2, jockstickConfig);
|
||||
}
|
||||
if (moveCommand != null) {
|
||||
a(moveCommand, (f == 0.0f || i == 0) && (f2 == 0.0f || i2 == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(AccumulatorConfig accumulatorConfig) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(accumulatorConfig.getServoID()), Integer.valueOf(accumulatorConfig.getStartAngle() + 120));
|
||||
CommandManager.a(this.c).a((MoveCommand) new AngleCommand(hashMap, 200, 0), false);
|
||||
}
|
||||
|
||||
/* JADX WARN: Removed duplicated region for block: B:18:0x0161 */
|
||||
/* JADX WARN: Removed duplicated region for block: B:21:? A[RETURN, SYNTHETIC] */
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||||
*/
|
||||
public void a(float r33, float r34, float r35, com.ubt.jimu.controller.data.config.JockstickConfig r36) {
|
||||
/*
|
||||
Method dump skipped, instructions count: 369
|
||||
To view this dump change 'Code comments level' option to 'DEBUG'
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.controller.presenter.ControllerPresenter.a(float, float, float, com.ubt.jimu.controller.data.config.JockstickConfig):void");
|
||||
}
|
||||
|
||||
private boolean a(double d) {
|
||||
return d <= 11.25d || 360.0d - d <= 11.25d || Math.abs(d - 90.0d) <= 11.25d || Math.abs(d - 180.0d) <= 11.25d || Math.abs(d - 270.0d) <= 11.25d;
|
||||
}
|
||||
|
||||
public void a(float f, HSliderConfig hSliderConfig) {
|
||||
float f2 = (f + 100.0f) / 200.0f;
|
||||
if (f2 > 1.0f) {
|
||||
f2 = 1.0f;
|
||||
} else if (f2 < 0.0f) {
|
||||
f2 = 0.0f;
|
||||
}
|
||||
int minAngle = hSliderConfig.getMinAngle() + ((int) (f2 * (hSliderConfig.getMaxAngle() - hSliderConfig.getMinAngle())));
|
||||
a(this.c.getResources().getString(R.string.angle_min_txt) + ": " + hSliderConfig.getMinAngle() + "°", String.format(this.c.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(hSliderConfig.getServoID())) + ": " + minAngle + "°", this.c.getResources().getString(R.string.angle_max_txt) + ": " + hSliderConfig.getMaxAngle() + "°");
|
||||
a(hSliderConfig, minAngle);
|
||||
}
|
||||
|
||||
public void a(float f, SliderConfig sliderConfig) {
|
||||
int i = f > 0.0f ? 1 : f < 0.0f ? -1 : 0;
|
||||
if (sliderConfig.isDirectionDisclock()) {
|
||||
i = -i;
|
||||
}
|
||||
Gear b = b(Math.abs(f) / 100.0f);
|
||||
String format = String.format(this.c.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(sliderConfig.getServoID()));
|
||||
int turnSpeed = b.getTurnSpeed();
|
||||
if (sliderConfig.getMotionType() == CtrlMotionType.motor) {
|
||||
format = String.format(this.c.getResources().getString(R.string.control_motor_index), Integer.valueOf(sliderConfig.getServoID()));
|
||||
turnSpeed = (b.getMotorSpeed() * 360) / 60;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(format);
|
||||
sb.append(": ");
|
||||
Context context = this.c;
|
||||
sb.append(i < 0 ? context.getResources().getString(R.string.control_disclockwise) : context.getResources().getString(R.string.control_clockwise));
|
||||
sb.append(turnSpeed);
|
||||
sb.append("°/s");
|
||||
a((String) null, sb.toString(), (String) null);
|
||||
a(sliderConfig, b, i);
|
||||
}
|
||||
|
||||
public String a(Key key) {
|
||||
return this.h.a(key);
|
||||
}
|
||||
|
||||
public void a(String str) {
|
||||
WidgetConfig a = MoveConfigManager.a(this.c.getApplicationContext()).a(str);
|
||||
if (a == null) {
|
||||
Log.i("ControllerPresenter", "JoyStick Config has be deleted, delete the keymap. deleted config:" + a);
|
||||
this.h.a(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(KeyMap keyMap) {
|
||||
ALog.a("ControllerPresenter").d("addTmpKeyMap keyMap:" + keyMap);
|
||||
if (keyMap == null) {
|
||||
return;
|
||||
}
|
||||
Iterator<KeyMap> it = this.i.iterator();
|
||||
while (it.hasNext()) {
|
||||
KeyMap next = it.next();
|
||||
if (keyMap.b().equals(next.b())) {
|
||||
ALog.a("ControllerPresenter").d("remove tmp keyMap key same to add. remove keymap:" + keyMap);
|
||||
it.remove();
|
||||
} else if (keyMap.a().equals(next.a())) {
|
||||
ALog.a("ControllerPresenter").d("remove tmp keyMap actionId same to add. remove keymap:" + keyMap);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
this.i.add(keyMap);
|
||||
}
|
||||
|
||||
public void a(float f, AccumulatorConfig accumulatorConfig) {
|
||||
int a = AccumulatorGear.a(f / 100.0f, Math.abs(accumulatorConfig.getLaunchAngle() - accumulatorConfig.getStartAngle()));
|
||||
if (a > 0) {
|
||||
a(accumulatorConfig, a);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import com.ubt.jimu.base.data.CtrlMotionType;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.controller.data.action.MotorData;
|
||||
import com.ubt.jimu.controller.data.action.TurnData;
|
||||
import com.ubt.jimu.controller.data.command.Gear;
|
||||
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.manager.CommandManager;
|
||||
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
||||
import com.ubt.jimu.controller.view.JockstickSettingView;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class JockstickSettingPresenter extends SuperControllerPresenter<JockstickSettingView> {
|
||||
public JockstickSettingPresenter(Context context, RobotLite robotLite) {
|
||||
super(context, robotLite);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
void b(List<? extends Engine> list) {
|
||||
}
|
||||
|
||||
public void k() {
|
||||
if (c(this.d)) {
|
||||
return;
|
||||
}
|
||||
((JockstickSettingView) b()).b(false);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void a(MoveCommand moveCommand, boolean z) {
|
||||
CommandManager.a(this.c.getApplicationContext()).a(moveCommand, z);
|
||||
}
|
||||
|
||||
public void a(CtrlMotionType ctrlMotionType, final int i, Gear gear, int i2) {
|
||||
if (!c(this.d) || super.e()) {
|
||||
return;
|
||||
}
|
||||
if (ctrlMotionType == CtrlMotionType.servo) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(i), new TurnData(i2, gear.getTurnSpeed()));
|
||||
a(new TurnCommand(hashMap), gear == Gear.EMPTY || i2 == 0);
|
||||
Observable.timer(400L, TimeUnit.MILLISECONDS).subscribe(new Consumer<Long>() { // from class: com.ubt.jimu.controller.presenter.JockstickSettingPresenter.1
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(Long l) throws Exception {
|
||||
LogUtils.c("!!!!!!!!!!!!!!!!!!");
|
||||
HashMap hashMap2 = new HashMap(1);
|
||||
hashMap2.put(Integer.valueOf(i), new TurnData(0, 0));
|
||||
JockstickSettingPresenter.this.a((MoveCommand) new TurnCommand(hashMap2), true);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ctrlMotionType == CtrlMotionType.motor) {
|
||||
HashMap hashMap2 = new HashMap(1);
|
||||
hashMap2.put(Integer.valueOf(i), new MotorData(i2, gear.getTurnSpeed(), 400));
|
||||
a(new MotorCommand(hashMap2), gear == Gear.EMPTY || i2 == 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(JockstickConfig jockstickConfig) {
|
||||
MoveConfigManager a = MoveConfigManager.a(this.c.getApplicationContext());
|
||||
a.b(jockstickConfig);
|
||||
a.a(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import com.ubt.jimu.base.EngineManager;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.data.Servo;
|
||||
import com.ubt.jimu.base.db.diy.DiyDBModel;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.http.ApiResponse;
|
||||
import com.ubt.jimu.base.mvp.BaseRxView;
|
||||
import com.ubt.jimu.base.mvp.RxPresenter;
|
||||
import com.ubt.jimu.transport3.DiyTransportServiceImpl;
|
||||
import com.ubt.jimu.transport3.bean.response.SaveOrUpdateModelBean;
|
||||
import com.ubtech.utils.XLog;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class ServoModeSettingPresenter extends RxPresenter<ServoModeView> {
|
||||
|
||||
public interface ServoModeView extends BaseRxView {
|
||||
void c(List<Servo> list);
|
||||
}
|
||||
|
||||
public void a(EngineManager engineManager, RobotLite robotLite) {
|
||||
List<Servo> servoList = engineManager.getServoList(Cache.getInstance().getUserId());
|
||||
if (servoList == null || servoList.size() <= 0) {
|
||||
XLog.c("woo", "Has no servos!");
|
||||
} else {
|
||||
servoList.get(0).setChoose(true);
|
||||
}
|
||||
if (getView() != null) {
|
||||
getView().c(servoList);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(DiyDBModel diyDBModel) {
|
||||
DiyTransportServiceImpl.getInstance().updateModel(diyDBModel, new Observer<ApiResponse<SaveOrUpdateModelBean>>(this) { // from class: com.ubt.jimu.controller.presenter.ServoModeSettingPresenter.1
|
||||
@Override // io.reactivex.Observer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onNext(ApiResponse<SaveOrUpdateModelBean> apiResponse) {
|
||||
XLog.a("Controller", "updateModel onNext");
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onComplete() {
|
||||
XLog.a("Controller", "updateModel complete");
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onError(Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,387 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
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.cache.SharePreferenceHelper;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.Servo;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.connect.model.Component;
|
||||
import com.ubt.jimu.connect.model.ErrorType;
|
||||
import com.ubt.jimu.connect.model.MatchResultCallback;
|
||||
import com.ubt.jimu.connect.model.ModelMatchModel;
|
||||
import com.ubt.jimu.controller.presenter.SuperControllerPresenter;
|
||||
import com.ubt.jimu.controller.view.IBaseControllerView;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.bluetooth.ConnectionState;
|
||||
import com.ubtrobot.jimu.exception.BatteryException;
|
||||
import com.ubtrobot.jimu.exception.EngineProtectException;
|
||||
import com.ubtrobot.jimu.exception.RobotActiveException;
|
||||
import com.ubtrobot.jimu.robotapi.BatteryInfo;
|
||||
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
||||
import com.ubtrobot.jimu.robotapi.GlobalExceptionUtil;
|
||||
import com.ubtrobot.jimu.robotapi.IGlobalExceptionListener;
|
||||
import com.ubtrobot.jimu.robotapi.JimuException;
|
||||
import com.ubtrobot.jimu.robotapi.JimuManager;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class SuperControllerPresenter<T extends IBaseControllerView> extends BasePresenter<T> implements IGlobalExceptionListener {
|
||||
protected EngineManager b;
|
||||
protected Context c;
|
||||
protected RobotLite d;
|
||||
private JimuManager e;
|
||||
|
||||
/* renamed from: com.ubt.jimu.controller.presenter.SuperControllerPresenter$3, reason: invalid class name */
|
||||
class AnonymousClass3 implements ObservableOnSubscribe<List<Component>> {
|
||||
AnonymousClass3() {
|
||||
}
|
||||
|
||||
static /* synthetic */ void a(ObservableEmitter observableEmitter, ModelMatchModel modelMatchModel, int i, BoardInfo boardInfo) {
|
||||
if (i == -4 || i == -3) {
|
||||
ArrayList<Component> a = modelMatchModel.a();
|
||||
if (a != null) {
|
||||
observableEmitter.onNext(a);
|
||||
return;
|
||||
}
|
||||
observableEmitter.onError(new Throwable("Component list is NULL! result code: " + i));
|
||||
return;
|
||||
}
|
||||
if (i == -2 || i == -1) {
|
||||
observableEmitter.onError(new Throwable("Match result: " + i));
|
||||
return;
|
||||
}
|
||||
if (i != 0) {
|
||||
XLog.d("Controller", "Unknown match result: %d", Integer.valueOf(i));
|
||||
} else {
|
||||
observableEmitter.onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(final ObservableEmitter<List<Component>> observableEmitter) throws Exception {
|
||||
final ModelMatchModel modelMatchModel = new ModelMatchModel();
|
||||
modelMatchModel.a(SuperControllerPresenter.this.d.getModelId(), !SuperControllerPresenter.this.d.isOfficial(), new MatchResultCallback() { // from class: com.ubt.jimu.controller.presenter.c
|
||||
@Override // com.ubt.jimu.connect.model.MatchResultCallback
|
||||
public final void a(int i, BoardInfo boardInfo) {
|
||||
SuperControllerPresenter.AnonymousClass3.a(ObservableEmitter.this, modelMatchModel, i, boardInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
public SuperControllerPresenter(Context context, RobotLite robotLite) {
|
||||
this.c = context;
|
||||
a((SuperControllerPresenter<T>) context);
|
||||
this.d = robotLite;
|
||||
}
|
||||
|
||||
public List<Servo> b(boolean z) {
|
||||
RobotLite robotLite = this.d;
|
||||
if (robotLite == null) {
|
||||
return null;
|
||||
}
|
||||
EngineManager engineManager = this.b;
|
||||
if (engineManager == null) {
|
||||
b(robotLite);
|
||||
} else {
|
||||
engineManager.reloadPeripheralConn();
|
||||
}
|
||||
List<Servo> servoList = this.b.getServoList(Cache.getInstance().getUserId());
|
||||
Object[] objArr = new Object[1];
|
||||
objArr[0] = servoList != null ? servoList.toString() : "null";
|
||||
XLog.a("Controller", "servolist: %s", objArr);
|
||||
if (z) {
|
||||
b(servoList);
|
||||
}
|
||||
return servoList;
|
||||
}
|
||||
|
||||
abstract void b(List<? extends Engine> list);
|
||||
|
||||
public EngineManager c() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public JimuManager d() {
|
||||
if (this.e == null) {
|
||||
this.e = JimuApplication.l().f();
|
||||
}
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public boolean e() {
|
||||
BatteryInfo f = JimuApplication.l().f().f();
|
||||
if (f == null || !f.d()) {
|
||||
return false;
|
||||
}
|
||||
return new SharePreferenceHelper().getBoolean(SharePreferenceHelper.SP_KEY_ELECTRICITY_PROTECT, true).booleanValue();
|
||||
}
|
||||
|
||||
public void f() {
|
||||
Observable subscribeOn = Observable.create(new AnonymousClass3()).subscribeOn(Schedulers.b());
|
||||
subscribeOn.observeOn(AndroidSchedulers.a()).subscribe(new Observer<List<Component>>() { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.4
|
||||
@Override // io.reactivex.Observer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onNext(List<Component> list) {
|
||||
if (list != null) {
|
||||
XLog.a("woo", "boardInfo : %s", list.toString());
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(false);
|
||||
iBaseControllerView.b(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onComplete() {
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onError(Throwable th) {
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(th);
|
||||
iBaseControllerView.a(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // io.reactivex.Observer
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) SuperControllerPresenter.this.b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void g() {
|
||||
if (d() != null) {
|
||||
d().a(this);
|
||||
}
|
||||
EventBus.b().c(this);
|
||||
}
|
||||
|
||||
public void h() {
|
||||
this.b = null;
|
||||
this.e = null;
|
||||
a();
|
||||
}
|
||||
|
||||
public void i() {
|
||||
EngineManager engineManager = this.b;
|
||||
if (engineManager != null) {
|
||||
engineManager.reloadPeripheralConn();
|
||||
}
|
||||
}
|
||||
|
||||
public void j() {
|
||||
JimuManager f = JimuApplication.l().f();
|
||||
if (f != null) {
|
||||
f.b(this);
|
||||
}
|
||||
EventBus.b().d(this);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.jimu.robotapi.IGlobalExceptionListener
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onGlobalException(RobotActiveException robotActiveException) {
|
||||
LogUtils.c("onGlobalException~01");
|
||||
a(robotActiveException);
|
||||
}
|
||||
|
||||
public List<Engine> a(boolean z) {
|
||||
EngineManager engineManager = this.b;
|
||||
if (engineManager == null) {
|
||||
b(this.d);
|
||||
} else {
|
||||
engineManager.reloadPeripheralConn();
|
||||
}
|
||||
List<Engine> engineList = this.b.getEngineList(Cache.getInstance().getUserId());
|
||||
Object[] objArr = new Object[1];
|
||||
objArr[0] = engineList != null ? engineList.toString() : "null";
|
||||
XLog.a("Controller", "engineList: %s", objArr);
|
||||
if (z) {
|
||||
b(engineList);
|
||||
}
|
||||
return engineList;
|
||||
}
|
||||
|
||||
public boolean c(RobotLite robotLite) {
|
||||
return d() != null && d().b(robotLite.getModelId()) == ConnectionState.STATE_CONNECTED;
|
||||
}
|
||||
|
||||
private void c(List<Component> list) {
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(list);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean a(RobotLite robotLite) {
|
||||
List<Servo> b = b(true);
|
||||
for (int i = 0; i < b.size(); i++) {
|
||||
if (!b.get(i).isConfigged()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void b(RobotLite robotLite) {
|
||||
this.b = new EngineManager(this.c, robotLite);
|
||||
}
|
||||
|
||||
private void a(final int i) {
|
||||
Observable.create(new ObservableOnSubscribe<Boolean>() { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.2
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<Boolean> observableEmitter) throws Exception {
|
||||
try {
|
||||
if (SuperControllerPresenter.this.e == null) {
|
||||
observableEmitter.onNext(false);
|
||||
return;
|
||||
}
|
||||
if (i == 10) {
|
||||
SuperControllerPresenter.this.e.q();
|
||||
} else {
|
||||
SuperControllerPresenter.this.e.r();
|
||||
}
|
||||
observableEmitter.onNext(true);
|
||||
} catch (JimuException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<Boolean>(this) { // from class: com.ubt.jimu.controller.presenter.SuperControllerPresenter.1
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(Boolean bool) throws Exception {
|
||||
LogUtils.c("解除保护成功:" + bool);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void a(RobotActiveException robotActiveException, List<Integer> list) {
|
||||
XLog.a("woo", "exception: %s", robotActiveException.toString());
|
||||
if (robotActiveException instanceof EngineProtectException) {
|
||||
EngineProtectException engineProtectException = (EngineProtectException) robotActiveException;
|
||||
if (engineProtectException.canUnlock()) {
|
||||
a(engineProtectException.getEngineType());
|
||||
LogUtils.c("解除异常:canUnlock");
|
||||
} else if (engineProtectException.needHandUp()) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void a(RobotActiveException robotActiveException) {
|
||||
if (robotActiveException != null) {
|
||||
LogUtils.c("异常:" + robotActiveException.getMessage());
|
||||
GlobalExceptionUtil.a(this.c, robotActiveException, new GlobalExceptionUtil.ExceptionCallback() { // from class: com.ubt.jimu.controller.presenter.a
|
||||
@Override // com.ubtrobot.jimu.robotapi.GlobalExceptionUtil.ExceptionCallback
|
||||
public final void a(String str, RobotActiveException robotActiveException2, List list) {
|
||||
SuperControllerPresenter.this.a(str, robotActiveException2, list);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void a(String str, RobotActiveException robotActiveException, List<Integer> list) {
|
||||
boolean z;
|
||||
if (robotActiveException instanceof EngineProtectException) {
|
||||
z = ((EngineProtectException) robotActiveException).needHandUp();
|
||||
} else {
|
||||
boolean z2 = robotActiveException instanceof BatteryException;
|
||||
z = false;
|
||||
}
|
||||
IBaseControllerView iBaseControllerView = (IBaseControllerView) b();
|
||||
if (iBaseControllerView != null) {
|
||||
iBaseControllerView.a(str, robotActiveException, list, z);
|
||||
}
|
||||
}
|
||||
|
||||
public String a(int i, ServoMode servoMode) {
|
||||
if (this.b == null) {
|
||||
b(this.d);
|
||||
}
|
||||
if (this.b.getServoMode(i) != servoMode) {
|
||||
return String.format(this.c.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(i));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void a(List<Component> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
XLog.a("woo", "Component list: %s", list.toString());
|
||||
ArrayList arrayList = new ArrayList();
|
||||
ArrayList arrayList2 = new ArrayList();
|
||||
ArrayList arrayList3 = new ArrayList();
|
||||
for (Component component : list) {
|
||||
if (component.d() == 10 || component.d() == 128) {
|
||||
if (component.b() == ErrorType.ID_DUPLICATION) {
|
||||
arrayList.add(component);
|
||||
} else if (component.b() == ErrorType.LACK) {
|
||||
arrayList2.add(component);
|
||||
} else if (component.b() == ErrorType.EXTRA) {
|
||||
arrayList3.add(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arrayList.size() > 0) {
|
||||
c(arrayList);
|
||||
return;
|
||||
}
|
||||
if (arrayList2.size() > 0) {
|
||||
c(arrayList2);
|
||||
} else if (arrayList3.size() > 0) {
|
||||
c(arrayList3);
|
||||
} else {
|
||||
XLog.c("Controller", "Everything is ok, do nothing.");
|
||||
}
|
||||
}
|
||||
|
||||
public String a(Context context, List<Component> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ErrorType b = list.get(0).b();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Component component = list.get(i);
|
||||
if (component.d() == 128) {
|
||||
sb.append(String.format(context.getResources().getString(R.string.servo_mode_servo_index), Integer.valueOf(component.c())));
|
||||
} else {
|
||||
sb.append(String.format(context.getResources().getString(R.string.control_motor_index), Integer.valueOf(component.c())));
|
||||
}
|
||||
if (i < list.size() - 1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
return b == ErrorType.ID_DUPLICATION ? String.format(context.getResources().getString(R.string.control_duplicate_tips), sb.toString()) : b == ErrorType.LACK ? String.format(context.getResources().getString(R.string.control_lack_tips), sb.toString()) : b == ErrorType.EXTRA ? String.format(context.getResources().getString(R.string.control_extra_tips), sb.toString()) : "";
|
||||
}
|
||||
}
|
106
sources/com/ubt/jimu/controller/presenter/VSliderPresenter.java
Normal file
106
sources/com/ubt/jimu/controller/presenter/VSliderPresenter.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.ubt.jimu.controller.presenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.R;
|
||||
import com.ubt.jimu.base.data.CtrlMotionType;
|
||||
import com.ubt.jimu.base.data.Engine;
|
||||
import com.ubt.jimu.base.data.ServoMode;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.controller.data.action.MotorData;
|
||||
import com.ubt.jimu.controller.data.action.TurnData;
|
||||
import com.ubt.jimu.controller.data.command.Gear;
|
||||
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.SliderConfig;
|
||||
import com.ubt.jimu.controller.manager.CommandManager;
|
||||
import com.ubt.jimu.controller.manager.MoveConfigManager;
|
||||
import com.ubt.jimu.controller.view.IVSliderView;
|
||||
import com.ubtech.utils.XLog;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class VSliderPresenter extends SuperControllerPresenter<IVSliderView> {
|
||||
public VSliderPresenter(Context context, RobotLite robotLite) {
|
||||
super(context, robotLite);
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
void b(List<? extends Engine> list) {
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
XLog.a("woo", "servolist: %s", list.toString());
|
||||
List<SliderConfig> f = MoveConfigManager.a(this.c.getApplicationContext()).f();
|
||||
if (f == null || f.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
for (SliderConfig sliderConfig : f) {
|
||||
int servoID = sliderConfig.getServoID();
|
||||
for (Engine engine : list) {
|
||||
if (servoID == engine.getId() && sliderConfig.getMotionType() == engine.getMotionType()) {
|
||||
engine.setConfigged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubt.jimu.controller.presenter.SuperControllerPresenter
|
||||
public String a(int i, ServoMode servoMode) {
|
||||
IVSliderView iVSliderView;
|
||||
String a = super.a(i, servoMode);
|
||||
if (TextUtils.isEmpty(a) || (iVSliderView = (IVSliderView) b()) == null) {
|
||||
return "";
|
||||
}
|
||||
iVSliderView.d(String.format(this.c.getResources().getString(R.string.control_servo_mode_set), a));
|
||||
return "";
|
||||
}
|
||||
|
||||
public void a(SliderConfig sliderConfig) {
|
||||
MoveConfigManager a = MoveConfigManager.a(this.c.getApplicationContext());
|
||||
a.b(sliderConfig);
|
||||
a.a(true);
|
||||
}
|
||||
|
||||
public void a(CtrlMotionType ctrlMotionType, final int i, Gear gear, int i2) {
|
||||
if (!c(this.d) || e() || i <= 0) {
|
||||
return;
|
||||
}
|
||||
if (ctrlMotionType == CtrlMotionType.servo) {
|
||||
HashMap hashMap = new HashMap(1);
|
||||
hashMap.put(Integer.valueOf(i), new TurnData(i2, gear.getTurnSpeed()));
|
||||
a(new TurnCommand(hashMap), gear == Gear.EMPTY || i2 == 0);
|
||||
Observable.timer(400L, TimeUnit.MILLISECONDS).subscribe(new Consumer<Long>() { // from class: com.ubt.jimu.controller.presenter.VSliderPresenter.1
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(Long l) throws Exception {
|
||||
HashMap hashMap2 = new HashMap(1);
|
||||
hashMap2.put(Integer.valueOf(i), new TurnData(0, 0));
|
||||
VSliderPresenter.this.a((MoveCommand) new TurnCommand(hashMap2), true);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ctrlMotionType == CtrlMotionType.motor) {
|
||||
HashMap hashMap2 = new HashMap(1);
|
||||
hashMap2.put(Integer.valueOf(i), new MotorData(i2, gear.getTurnSpeed(), 400));
|
||||
a(new MotorCommand(hashMap2), gear == Gear.EMPTY || i2 == 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void b(SliderConfig sliderConfig) {
|
||||
MoveConfigManager a = MoveConfigManager.a(this.c.getApplicationContext());
|
||||
a.a(sliderConfig);
|
||||
a.a(true);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void a(MoveCommand moveCommand, boolean z) {
|
||||
CommandManager.a(this.c.getApplicationContext()).a(moveCommand, z);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user