|
@@ -1,6 +1,7 @@
|
|
|
import 'dart:async';
|
|
|
|
|
|
import 'package:vnote_device_plugin/events/event_type.dart';
|
|
|
+import 'package:vnote_device_plugin/utils/logger.dart';
|
|
|
|
|
|
import '../consts/status.dart';
|
|
|
import '../events/defines.dart';
|
|
@@ -44,10 +45,12 @@ class DeviceSearcher {
|
|
|
}
|
|
|
|
|
|
void init() {
|
|
|
+ _log("Init");
|
|
|
DeviceEventCenter.instance.addListener(_listener);
|
|
|
}
|
|
|
|
|
|
void dispose() {
|
|
|
+ _log("Dispose");
|
|
|
DeviceEventCenter.instance.removeListener(_listener);
|
|
|
}
|
|
|
|
|
@@ -55,6 +58,9 @@ class DeviceSearcher {
|
|
|
_busy = true;
|
|
|
|
|
|
_startCompleter = Completer<void>();
|
|
|
+
|
|
|
+ _log("Start");
|
|
|
+
|
|
|
await VnoteDevicePluginPlatform.instance.callAction(
|
|
|
"SEARCH_START",
|
|
|
{"TYPE": type},
|
|
@@ -65,6 +71,9 @@ class DeviceSearcher {
|
|
|
|
|
|
Future<void> stop() async {
|
|
|
_stopCompleter = Completer<void>();
|
|
|
+
|
|
|
+ _log("Stop");
|
|
|
+
|
|
|
await VnoteDevicePluginPlatform.instance.callAction(
|
|
|
"SEARCH_STOP",
|
|
|
{"TYPE": type},
|
|
@@ -89,15 +98,18 @@ class DeviceSearcher {
|
|
|
}
|
|
|
|
|
|
void _onStartCallback(Map<String, dynamic>? data) {
|
|
|
+ _log("Start callback");
|
|
|
_startCompleter?.complete();
|
|
|
}
|
|
|
|
|
|
void _onTimeoutCallback() {
|
|
|
+ _log("Timeout callback");
|
|
|
_busy = false;
|
|
|
timeoutEvent.emit(this, null);
|
|
|
}
|
|
|
|
|
|
void _onStopCallback(Map<String, dynamic>? data) {
|
|
|
+ _log("Stop callback");
|
|
|
if (_stopCompleter == null) {
|
|
|
// 搜索超时
|
|
|
if (_busy) {
|
|
@@ -110,16 +122,24 @@ class DeviceSearcher {
|
|
|
}
|
|
|
|
|
|
void _onFoundCallback(Map<String, dynamic>? data) {
|
|
|
+ _log("Found");
|
|
|
_busy = false;
|
|
|
// {"STATUS":104,"DATA":{"BLE_NAME":"IR Thermo","BLE_PRODUCT_NAME":"体温计(家测宝)","MAC":"44:A6:E5:16:62:33","MODEL":"DT-8836","TYPE":"temp"}}
|
|
|
if (data != null) {
|
|
|
final device = DeviceInfo.fromEventData(data);
|
|
|
+ _log(
|
|
|
+ "BleName: ${device.bleName}, ProductName: ${device.productName}, Model: ${device.model}, Mac: ${device.mac}");
|
|
|
successEvent.emit(this, device);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void _onNotFoundCallback(Map<String, dynamic>? data) {
|
|
|
final message = data?["MESSAGE"] ?? "ERROR";
|
|
|
+ _log("Error: $message");
|
|
|
failEvent.emit(this, message); // TODO:
|
|
|
}
|
|
|
+
|
|
|
+ void _log(String content) {
|
|
|
+ LogUtil.write("DeviceSearcher[$type] $content.");
|
|
|
+ }
|
|
|
}
|