fixed conflict
This commit is contained in:
@@ -432,7 +432,7 @@ class MoGoAutopilotProvider :
|
||||
* 向左变道
|
||||
*/
|
||||
override fun sendOperatorChangeLaneLeft() {
|
||||
Log.d("liyz", "MoGoAutopilotProvider sendOperatorChangeLaneLeft -------> ")
|
||||
// Log.d("liyz", "MoGoAutopilotProvider sendOperatorChangeLaneLeft -------> ")
|
||||
AdasManager.getInstance().sendOperatorCmdChangeLaneLeft()
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ class MoGoAutopilotProvider :
|
||||
* 向右变道
|
||||
*/
|
||||
override fun sendOperatorChangeLaneRight() {
|
||||
Log.d("liyz", "MoGoAutopilotProvider sendOperatorChangeLaneRight -------> ")
|
||||
// Log.d("liyz", "MoGoAutopilotProvider sendOperatorChangeLaneRight -------> ")
|
||||
AdasManager.getInstance().sendOperatorCmdChangeLaneRight()
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ class MoGoAutopilotProvider :
|
||||
* 发送设置加速度 acc>0加速 acc<0减速 acc=0复位
|
||||
*/
|
||||
override fun sendOperatorSetAcceleratedSpeed(cc: Double) {
|
||||
Log.d("liyz", "MoGoAutopilotProvider sendOperatorSetAcceleratedSpeed cc $cc ")
|
||||
// Log.d("liyz", "MoGoAutopilotProvider sendOperatorSetAcceleratedSpeed cc $cc ")
|
||||
AdasManager.getInstance().sendOperatorCmdSetAcceleratedSpeed(cc)
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ class MoGoAutopilotProvider :
|
||||
* 鸣笛 value 1: honk 2: stop honking
|
||||
*/
|
||||
override fun sendOperatorSetHorn(value: Double) {
|
||||
Log.d("liyz", "MoGoAutopilotProvider sendOperatorSetHorn value $value ")
|
||||
// Log.d("liyz", "MoGoAutopilotProvider sendOperatorSetHorn value $value ")
|
||||
AdasManager.getInstance().sendOperatorCmdSetHorn(value)
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +261,6 @@ class DebugSettingView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
btnOpenAllGestures.setOnClickListener {
|
||||
MogoMapUIController.getInstance().setAllGesturesEnabled(true)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_ALIAS_CODE
|
||||
import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_LINK_INIT;
|
||||
import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_LINK_LOG_CONNECT_STATUS;
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_HMI;
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAP;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
@@ -31,6 +32,7 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotManager;
|
||||
import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager;
|
||||
import com.mogo.eagle.core.function.hmi.R;
|
||||
import com.mogo.eagle.core.function.main.moujie.BluetoothMonitorReceiver;
|
||||
import com.mogo.eagle.core.function.main.moujie.ConnectBluetoothEvent;
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
|
||||
@@ -45,9 +47,11 @@ import com.zhjt.service.chain.TracingConstants;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
@@ -69,6 +73,8 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
private Timer timerAcc;
|
||||
|
||||
private BluetoothMonitorReceiver mBluetoothReceiver = null;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private List<BluetoothDevice> mAreadlyConnectedList = new ArrayList<>();//已连接设备集合
|
||||
|
||||
|
||||
@Override
|
||||
@@ -78,12 +84,22 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
EventBus.getDefault().register(this);
|
||||
CallerLogger.INSTANCE.i(M_HMI + TAG, "onCreate");
|
||||
|
||||
SharedPrefsMgr.getInstance(getContext()).putBoolean("BLUETOOTH", false);
|
||||
|
||||
// initBluetooth();
|
||||
// mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
initBluetooth();
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
mBluetoothAdapter.enable();
|
||||
}
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
|
||||
showBondedDevice(mBluetoothAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
@@ -190,28 +206,24 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { //向上长按 开启自动驾驶
|
||||
setMapControl();
|
||||
long currentTime = System.currentTimeMillis() / (1000);
|
||||
long oldTime = SharedPrefsMgr.getInstance(getContext()).getLong("old_time_up", 0);
|
||||
// Log.d("liyz", "time = " + (currentTime - oldTime));
|
||||
if (currentTime - oldTime > 8) {
|
||||
if (currentTime - oldTime > 6) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putLong("old_time_up", System.currentTimeMillis() / 1000);
|
||||
// ToastUtils.showShort("长按 ↑↑↑ 开启自动驾驶");
|
||||
CallerAutoPilotManager.INSTANCE.setControlAutopilotCarAuto(true);
|
||||
}
|
||||
recoverMapControl();
|
||||
|
||||
return true;
|
||||
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { //下和中间键盘长按,减速为-2
|
||||
setMapControl();
|
||||
long currentTime = System.currentTimeMillis() / (1000);
|
||||
long oldTime = SharedPrefsMgr.getInstance(getContext()).getLong("old_time_down", 0);
|
||||
if (currentTime - oldTime > 8) {
|
||||
if (currentTime - oldTime > 6) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putLong("old_time_down", System.currentTimeMillis() / 1000);
|
||||
// ToastUtils.showShort("长按 ↓↓↓ 减速 -2 ");
|
||||
sendAcc(true, -2);
|
||||
}
|
||||
recoverMapControl();
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
@@ -221,16 +233,12 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
public boolean dispatchTouchEvent(MotionEvent event) {
|
||||
// Log.d("liyz", "dispatchTouchEvent event.getX() = " + event.getX() + "--event.getY() = " + event.getY() + "--action = " + event.getAction());
|
||||
if (event.getX() == -1469.6875 && event.getY() == 530.0) { //向左变道
|
||||
setMapControl();
|
||||
// ToastUtils.showShort("← 向左变道");
|
||||
// MogoMapUIController.getInstance().setLockMode( true );
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneLeft();
|
||||
|
||||
recoverMapControl();
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 132.5) { //鸣笛
|
||||
setMapControl();
|
||||
// ToastUtils.showShort("↑ 鸣笛 ");
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorSetHorn(1);
|
||||
|
||||
@@ -245,29 +253,20 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
}
|
||||
}, 500);
|
||||
|
||||
recoverMapControl();
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -863.4375 && event.getY() == 690.0) { //向右变道
|
||||
setMapControl();
|
||||
CallerAutoPilotManager.INSTANCE.sendOperatorChangeLaneRight();
|
||||
// ToastUtils.showShort("→ 向右变道");
|
||||
recoverMapControl();
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 1099.0) { // -1减速
|
||||
setMapControl();
|
||||
sendAcc(true, -1);
|
||||
// ToastUtils.showShort("↓ 减速 -1 ");
|
||||
recoverMapControl();
|
||||
|
||||
return true;
|
||||
} else if (event.getX() == -1096.25 && event.getY() == 690.0) { //复原
|
||||
setMapControl();
|
||||
|
||||
// ToastUtils.showShort("O 复原 ");
|
||||
sendAcc(false, 0.0);
|
||||
|
||||
recoverMapControl();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -340,20 +339,6 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
}
|
||||
}
|
||||
|
||||
private void setMapControl() {
|
||||
// UiThreadHandler.removeCallbacks(delayRunnable);
|
||||
// MogoMapUIController.getInstance().setScrollGesturesEnable(false);
|
||||
}
|
||||
|
||||
private void recoverMapControl() {
|
||||
// UiThreadHandler.postDelayed(delayRunnable, 5_00L);
|
||||
}
|
||||
|
||||
private Runnable delayRunnable = () -> {
|
||||
MogoMapUIController.getInstance().setScrollGesturesEnable(true);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 初始化蓝牙广播
|
||||
*/
|
||||
@@ -371,19 +356,31 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
registerReceiver(this.mBluetoothReceiver, intentFilter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查找蓝牙连接过的蓝牙设备
|
||||
*
|
||||
* @param bluetoothAdapter
|
||||
*/
|
||||
private void showBondedDevice(BluetoothAdapter bluetoothAdapter) {
|
||||
mAreadlyConnectedList.clear();
|
||||
Set<BluetoothDevice> deviceList = bluetoothAdapter.getBondedDevices();
|
||||
for (BluetoothDevice device : deviceList) {
|
||||
Log.d("liyz", "Name:" + device.getName() + " Mac:" + device.getAddress());
|
||||
try {
|
||||
//使用反射调用获取设备连接状态方法
|
||||
Method isConnectedMethod = BluetoothDevice.class.getDeclaredMethod("isConnected", (Class[]) null);
|
||||
isConnectedMethod.setAccessible(true);
|
||||
boolean isConnected = (boolean) isConnectedMethod.invoke(device, (Object[]) null);
|
||||
Log.d("liyz", "isConnected:" + isConnected);
|
||||
isConnected = (boolean) isConnectedMethod.invoke(device, (Object[]) null);
|
||||
Log.e("liyz", "showBondedDevice Name:" + device.getName() + " Mac:" + device.getAddress() + "---isConnected = " + isConnected);
|
||||
// Log.e("liyz", "showBondedDevice Name:" + device.getName() + " Mac:" + device.getAddress() + "---isConnected = " + isConnected);
|
||||
mAreadlyConnectedList.add(device);
|
||||
if (device.getName().equals("JX-05")) {
|
||||
SharedPrefsMgr.getInstance(getContext()).putString("BT_MAC", device.getAddress());
|
||||
}
|
||||
if (!isConnected) {
|
||||
UiThreadHandler.postDelayed(() -> {
|
||||
connectBluetooth(); //主动连接一次
|
||||
}, 4000L);
|
||||
}
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -394,6 +391,41 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onAutoConnection(ConnectBluetoothEvent event) {
|
||||
connectBluetooth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动连接最近的一次连接
|
||||
*/
|
||||
private void connectBluetooth() {
|
||||
// Log.d("liyz", "connectBluetooth ----> size() = " + mAreadlyConnectedList.size());
|
||||
if (mAreadlyConnectedList.size() > 0) {
|
||||
try {
|
||||
Method method = BluetoothDevice.class.getMethod("createBond");
|
||||
String macAddress = SharedPrefsMgr.getInstance(getContext()).getString("BT_MAC");
|
||||
int pos = -1;
|
||||
for (int i = 0; i < mAreadlyConnectedList.size(); i++) {
|
||||
if (macAddress.equals(mAreadlyConnectedList.get(i).getAddress())) {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
// Log.d("liyz", "connectBluetooth macAddress = " + macAddress + "---pos = " + pos);
|
||||
method.invoke(mAreadlyConnectedList.get(pos));
|
||||
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,13 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description
|
||||
@@ -29,6 +32,7 @@ public class BluetoothMonitorReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
// Toast.makeText(context, "蓝牙已经打开", Toast.LENGTH_SHORT).show();
|
||||
EventBus.getDefault().post(new ConnectBluetoothEvent());
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
// Toast.makeText(context, "蓝牙正在关闭", Toast.LENGTH_SHORT).show();
|
||||
@@ -41,12 +45,15 @@ public class BluetoothMonitorReceiver extends BroadcastReceiver {
|
||||
|
||||
case BluetoothDevice.ACTION_ACL_CONNECTED:
|
||||
// Toast.makeText(context, "蓝牙设备已连接", Toast.LENGTH_SHORT).show();
|
||||
SharedPrefsMgr.getInstance(context).putBoolean("BLUETOOTH", true);
|
||||
// Log.d("liyz", "蓝牙设备已连接 ----> ");
|
||||
// SharedPrefsMgr.getInstance(context).putBoolean("BLUETOOTH", true);
|
||||
break;
|
||||
|
||||
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
|
||||
SharedPrefsMgr.getInstance(context).putBoolean("BLUETOOTH", false);
|
||||
// SharedPrefsMgr.getInstance(context).putBoolean("BLUETOOTH", false);
|
||||
// Log.d("liyz", "蓝牙设备已断开 ----> ");
|
||||
// Toast.makeText(context, "蓝牙设备已断开", Toast.LENGTH_SHORT).show();
|
||||
EventBus.getDefault().post(new ConnectBluetoothEvent());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.mogo.eagle.core.function.main.moujie;
|
||||
|
||||
/**
|
||||
* @author lixiaopeng
|
||||
* @description 连接蓝牙事件
|
||||
* @since 2022/8/16
|
||||
*/
|
||||
public class ConnectBluetoothEvent {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user