更新设备校准
This commit is contained in:
@@ -123,6 +123,8 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
var bluetoothState = await FlutterBluePlus.isOn;
|
||||
if (!bluetoothState && !_isDialogShowing) {
|
||||
_isDialogShowing = true;
|
||||
blueteethBindController.model.blelist = [];
|
||||
blueteethBindController.updateAll();
|
||||
await _showBluetoothNotEnabledDialog();
|
||||
_isDialogShowing = false;
|
||||
return;
|
||||
@@ -134,68 +136,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
});
|
||||
|
||||
await FlutterBluePlus.startScan(timeout: Duration(seconds: 10));
|
||||
// await FlutterBluePlus.startScan(timeout: Duration(minutes: 30));
|
||||
|
||||
// _scanSubscription = FlutterBluePlus.scanResults.listen((results) {
|
||||
// if (!mounted) return; // 确保页面未销毁
|
||||
// final signalThreshold = blueteethBindController.model.singal!;
|
||||
// final filteredResults = results
|
||||
// .where((r) =>
|
||||
// r.rssi > signalThreshold &&
|
||||
// r.advertisementData.localName == "AITH-V2" &&
|
||||
// r.advertisementData.manufacturerData.containsKey(0xFFED))
|
||||
// .toList();
|
||||
|
||||
// // 解析数据
|
||||
// final parsedDeviceList = <BleDeviceData>[];
|
||||
|
||||
// for (var r in filteredResults) {
|
||||
// try {
|
||||
// List<int> rawData = r.advertisementData.manufacturerData[0xFFED]!;
|
||||
// BleDeviceData deviceData = parseBleData(rawData);
|
||||
// deviceData.name = r.advertisementData.advName;
|
||||
// deviceData.rssi = r.rssi;
|
||||
// deviceData.mac = deviceData.deviceId.replaceAll(':', '');
|
||||
// parsedDeviceList.add(deviceData);
|
||||
// if (deviceData.mac!.toLowerCase() == 'b43a45c3dfa0') {
|
||||
// print('匹配设备数据: ${deviceData.mac}-->sn:${deviceData.sn}');
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("设备数据解析失败: $e");
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 使用一个临时变量 lastDeviceList 来比较是否有变化
|
||||
// setState(() {
|
||||
// bool hasChanges = false;
|
||||
|
||||
// // 如果 devicelist 长度不同或内容有差异,认为有变化
|
||||
// if (blueteethBindController.model.devicelist?.length !=
|
||||
// parsedDeviceList.length) {
|
||||
// hasChanges = true;
|
||||
// } else {
|
||||
// // 深度比较每个设备的属性(比如 mac, rssi)
|
||||
// for (int i = 0;
|
||||
// i < blueteethBindController.model.devicelist!.length;
|
||||
// i++) {
|
||||
// if (blueteethBindController.model.devicelist![i].mac !=
|
||||
// parsedDeviceList[i].mac ||
|
||||
// blueteethBindController.model.devicelist![i].rssi !=
|
||||
// parsedDeviceList[i].rssi) {
|
||||
// hasChanges = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 如果有变化,更新 devicelist 和 blelist
|
||||
// if (hasChanges) {
|
||||
// blueteethBindController.model.devicelist = parsedDeviceList;
|
||||
// blueteethBindController.model.blelist = filteredResults;
|
||||
// // blueteethBindController.updateDeviceStatus();
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
_scanSubscription = FlutterBluePlus.scanResults.listen((results) {
|
||||
if (!mounted) return;
|
||||
@@ -322,6 +263,7 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
_scanSubscription?.cancel(); // 取消扫描订阅
|
||||
connectTimer?.cancel(); // 取消连接定时器
|
||||
blueteethBindController.stopStatusPolling(); // 停止状态轮询
|
||||
blueteethBindController.model.blelist = [];
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -753,19 +695,6 @@ class _BlueteethDevicePageState extends State<BlueteethDevicePage> {
|
||||
),
|
||||
],
|
||||
));
|
||||
// await showDialog(
|
||||
// context: context,
|
||||
// builder: (_) => AlertDialog(
|
||||
// title: Text("蓝牙未开启"),
|
||||
// content: Text("请先打开蓝牙再进行设备扫描"),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () => Navigator.of(context).pop(),
|
||||
// child: Text("知道了"),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user