|
|
|
@ -472,13 +472,37 @@ class BleManager extends GetxService { |
|
|
|
firmwareProductColor: '', |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 并行获取所有设备信息,不使用延迟 |
|
|
|
final results = await Future.wait([ |
|
|
|
_bleService.getBatteryInfo(), |
|
|
|
_bleService.getDeviceVersion(), |
|
|
|
_bleService.getProductId(), |
|
|
|
]); |
|
|
|
final commands = [ |
|
|
|
_bleService.getBatteryInfo, |
|
|
|
_bleService.getDeviceVersion, |
|
|
|
_bleService.getProductId, |
|
|
|
]; |
|
|
|
|
|
|
|
final delays = [ |
|
|
|
Duration.zero, // 第一个命令立即执行 |
|
|
|
const Duration(milliseconds: 100), // 第二个命令延迟100ms |
|
|
|
const Duration(milliseconds: 200), // 第三个命令延迟200ms |
|
|
|
]; |
|
|
|
|
|
|
|
final futures = commands |
|
|
|
.asMap() |
|
|
|
.map((index, command) { |
|
|
|
final delay = delays[index]; |
|
|
|
return MapEntry( |
|
|
|
index, |
|
|
|
Future.delayed(delay, command), |
|
|
|
); |
|
|
|
}) |
|
|
|
.values |
|
|
|
.toList(); |
|
|
|
|
|
|
|
final results = await Future.wait(futures); |
|
|
|
// // 并行获取所有设备信息,不使用延迟 |
|
|
|
// final results = await Future.wait([ |
|
|
|
// _bleService.getBatteryInfo(), |
|
|
|
// _bleService.getDeviceVersion(), |
|
|
|
// _bleService.getProductId(), |
|
|
|
// ]); |
|
|
|
|
|
|
|
Logger.info( |
|
|
|
'设备信息获取结果: 电池=${results[0]}, 版本=${results[1]}, 产品ID=${results[2]}'); |
|
|
|
|