Browse Source

Merge commit '1985c0fd02a34506881a39ea2e6171828ef48534' into new_dev

newdev_shunjiawei
lxm 1 year ago
parent
commit
a2aac8e428
  1. 9
      lib/data/services/ble_manager.dart
  2. 9
      lib/data/services/network/api.dart
  3. 24
      lib/modules/devices/controllers/devices_controller.dart
  4. 14
      lib/modules/pairing/controllers/pairing_controller.dart
  5. 7
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt
  6. 6
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleServicePlugin.kt
  7. 10
      local_plugins/ble_service/lib/ble_service.dart
  8. 2
      local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicManager.kt

9
lib/data/services/ble_manager.dart

@ -1002,6 +1002,15 @@ class BleManager extends GetxService {
}
}
/// 启动设备关联
Future<void> connect() async {
try {
await _bleService.connect();
} catch (e) {
Logger.error('连接设备失败: ${e.toString()}');
}
}
/// 注册后台扫描
Future<bool> registerBackgroundScan({String? macAddress}) async {
try {

9
lib/data/services/network/api.dart

@ -154,6 +154,15 @@ class Api {
);
}
// 获取验证码
static getdevices([params]) {
return DioManager().request(
NWMethod.post,
'/api/home/user_getdevices',
params: params,
);
}
//绑定设备
static bindauthcode([params]) {
return DioManager().request(

24
lib/modules/devices/controllers/devices_controller.dart

@ -1,5 +1,7 @@
import 'dart:ffi';
import 'package:voitrans/data/models/appconfig_model.dart';
import '/core/utils/logger.dart';
import '/data/models/user_Info.dart';
import '/data/services/ble_manager.dart';
@ -29,8 +31,16 @@ class DevicesController extends GetxController {
}
// 加载设备数据
void _loadDevices() {
void _loadDevices() async {
devices.clear();
final response = await Api.getdevices();
if (response != null) {
var devices = (response['devices'] as List<dynamic>)
.map((e) => UserDevice.fromJson(e as Map<String, dynamic>))
.toList();
User.instance.devices = devices;
}
for (var device in User.instance.devices) {
if (!devices.containsKey(device.devicetype)) {
devices[device.devicetype] = [];
@ -54,11 +64,13 @@ class DevicesController extends GetxController {
devices[device.devicetype]?.remove(device);
devices.refresh(); // 触发UI更新
User.instance.removeUserDevice(device.id);
_bleManager.clearPairedDevices();
_bleManager.disconnect();
await Future.delayed(const Duration(seconds: 1));
Get.toNamed(Routes.pairing);
if (device.devicemac == _bleManager.deviceInfo.value?.address) {
User.instance.removeUserDevice(device.id);
_bleManager.clearPairedDevices();
_bleManager.disconnect();
await Future.delayed(const Duration(seconds: 1));
Get.toNamed(Routes.pairing);
}
return;
} else {
return;

14
lib/modules/pairing/controllers/pairing_controller.dart

@ -710,12 +710,13 @@ class PairingController extends GetxController with WidgetsBindingObserver {
// 注册后台扫描以开始BLE配对
if (_verifiedDeviceAddress != null) {
final success = await _bleManager.registerBackgroundScan(
macAddress: _verifiedDeviceAddress);
if (!success && _currentState.value == PairingState.waitingBle) {
_setError(
ErrorType.bleTimeout, 'blePairingStartupFailed'.tr); //BLE配对启动失败
}
await _bleManager.connect();
// final success = await _bleManager.registerBackgroundScan(
// macAddress: _verifiedDeviceAddress);
// if (!success && _currentState.value == PairingState.waitingBle) {
// _setError(
// ErrorType.bleTimeout, 'blePairingStartupFailed'.tr); //BLE配对启动失败
// }
}
} catch (e) {
Logger.e(_tag, 'BLE连接失败: $e');
@ -1034,6 +1035,7 @@ class PairingController extends GetxController with WidgetsBindingObserver {
try {
Logger.i(_tag, '启动AgentService服务');
await _bleManager.startAgentService();
_bleManager.registerBackgroundScan(macAddress: _verifiedDeviceAddress);
} catch (e) {
Logger.e(_tag, '启动AgentService失败: $e');
}

7
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

@ -308,7 +308,7 @@ object BleService {
// Log.i(TAG, "liwei---------startScan 5")
val filter = ScanFilter.Builder()
// .setServiceUuid(ParcelUuid(BleConst.PRIMARY_SERVICE_UUID))
// .setManufacturerData(0xEFAB, byteArrayOf(0xA0.toByte(), 0x01))
// .setServiceUuid(ParcelUuid(java.util.UUID.fromString("00000201-0000-1000-8000-00805f9b34fb")))
.build()
// val filters = uuids.mapNotNull { uuidStr ->
// try {
@ -333,7 +333,7 @@ object BleService {
// }
// }
val settings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // 推荐:不会触发权限问题
.setReportDelay(0)
.build()
@ -627,7 +627,7 @@ object BleService {
when {
status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED -> {
updateConnectionState(BleConst.STATE_CONNECTED)
Log.d(TAG, "成功连接Ble蓝牙设备:${g.device.name}")
// 设置PHY值为2M以提高传输速度
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
@ -1446,7 +1446,6 @@ startBytesStatistics()
Log.e(TAG, "音频发送线程异常: ${e.message}", e)
}
}
Log.i(TAG, "音频发送线程已停止")
}.apply {
name = "AudioSendThread"

6
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleServicePlugin.kt

@ -189,7 +189,7 @@ class BleServicePlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
val success = BleService.getDeviceVersion()
result.success(success)
}
"getProductId" -> {
"getProductId" -> {
val success = BleService.getProductId()
result.success(success)
}
@ -322,6 +322,10 @@ class BleServicePlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
Log.d(TAG, "getDeviceList $infos")
result.success(infos)
}
"connect" -> {
BleService.connect();
result.success(null)
}
"disconnect" -> {
BleService.disconnect();
result.success(null)

10
local_plugins/ble_service/lib/ble_service.dart

@ -295,6 +295,16 @@ class BleService {
}
}
/// 停止TTS播放
Future<void> connect() async {
try {
await _methodChannel.invokeMethod<String>('connect');
} catch (e) {
print('连接设备失败: $e');
return;
}
}
/// 断开连接
Future<void> disconnect() async {
try {

2
local_plugins/qq_music/android/src/main/kotlin/com/yunqiinnovation/qq_music/QQMusicManager.kt

@ -706,8 +706,6 @@ class QQMusicManager(private val context: Context) {
}
}
/**
* 获取当前平台对应的QQ音乐包名
*/

Loading…
Cancel
Save