Add manufacturer data filtering (#23)
* Add manufacturer data filtering * Implement manufacturer data filter in windows * Fix manufacturerData filtering on windows * Fix linux * Clean comments --------- Co-authored-by: Foti Dim <fdimanidis@gmail.com>
This commit is contained in:
@@ -24,7 +24,6 @@ class MockUniversalBle extends UniversalBlePlatform {
|
||||
|
||||
@override
|
||||
Future<void> startScan({
|
||||
WebRequestOptionsBuilder? webRequestOptions,
|
||||
ScanFilter? scanFilter,
|
||||
}) async {
|
||||
onScanResult?.call(_mockBleScanResult);
|
||||
|
||||
+24
-12
@@ -25,9 +25,9 @@ class _MyAppState extends State<MyApp> {
|
||||
bool _isQueueEnabled = true;
|
||||
|
||||
AvailabilityState? bleAvailabilityState;
|
||||
late WebRequestOptionsBuilder _requestOptions;
|
||||
final List<String> _services = [
|
||||
"00001800-0000-1000-8000-00805f9b34fb",
|
||||
"0000180f-0000-1000-8000-00805f9b34fb",
|
||||
"00002a00-0000-1000-8000-00805f9b34fb",
|
||||
"00002a01-0000-1000-8000-00805f9b34fb",
|
||||
"00002a19-0000-1000-8000-00805f9b34fb",
|
||||
@@ -48,13 +48,6 @@ class _MyAppState extends State<MyApp> {
|
||||
UniversalBle.queuesCommands = _isQueueEnabled;
|
||||
UniversalBle.timeout = const Duration(seconds: 10);
|
||||
|
||||
/// Add common services for web
|
||||
if (kIsWeb) {
|
||||
_services.addAll(WebRequestOptionsBuilder.defaultServices);
|
||||
}
|
||||
_requestOptions =
|
||||
WebRequestOptionsBuilder.acceptAllDevices(optionalServices: _services);
|
||||
|
||||
UniversalBle.onAvailabilityChange = (state) {
|
||||
setState(() {
|
||||
bleAvailabilityState = state;
|
||||
@@ -77,6 +70,28 @@ class _MyAppState extends State<MyApp> {
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> startScan() async {
|
||||
await UniversalBle.startScan(
|
||||
scanFilter: ScanFilter(
|
||||
withServices: kIsWeb ? _services : [],
|
||||
withManufacturerData: [
|
||||
ManufacturerDataFilter(
|
||||
companyIdentifier: 0x012D,
|
||||
data: Uint8List.fromList(
|
||||
[0x03, 0x00, 0x64, 0x00],
|
||||
),
|
||||
),
|
||||
ManufacturerDataFilter(
|
||||
companyIdentifier: 0x012D,
|
||||
data: Uint8List.fromList(
|
||||
[0x03, 0x00, 0x65, 0x00],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -110,10 +125,7 @@ class _MyAppState extends State<MyApp> {
|
||||
_isScanning = true;
|
||||
});
|
||||
try {
|
||||
await UniversalBle.startScan(
|
||||
webRequestOptions: _requestOptions,
|
||||
// scanFilter: ScanFilter(withServices: ['180f']),
|
||||
);
|
||||
await startScan();
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
|
||||
Reference in New Issue
Block a user