705 lines
27 KiB
Java
705 lines
27 KiB
Java
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);
|
|
}
|
|
}
|
|
}
|