diff options
author | uvok | 2025-07-29 18:07:24 +0200 |
---|---|---|
committer | uvok | 2025-07-29 18:07:24 +0200 |
commit | 3e16a18fb5d279575377ae5cf1d3929a90cae79c (patch) | |
tree | 48a30745fd62c96ca6d0f635074ffc4222941ae0 | |
parent | 0e92f3c889f7a9f8832aa706aa9c3bfce1bb7891 (diff) |
Add service/characteristic scanning
-rw-r--r-- | lib/device_details.dart | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/device_details.dart b/lib/device_details.dart index d677b29..9c92a64 100644 --- a/lib/device_details.dart +++ b/lib/device_details.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:badge/first_where_ext.dart'; import 'package:flutter/material.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:logger/logger.dart'; @@ -26,6 +27,10 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { /// Whether the back button should be active. bool backActive = false; + BluetoothCharacteristic? current; + + BluetoothCharacteristic? available; + @override Widget build(BuildContext context) { return Scaffold( @@ -84,6 +89,22 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { logger.i("Connected!"); connectStatus = "Connected"; + + // ???? WTF ???? + List<BluetoothService> svcs = await dev.discoverServices(); + dev.onServicesReset.listen((_) async { + logger.i("Services Reset"); + try { + List<BluetoothService> svcs = await dev.discoverServices(); + findCharac(svcs); + } catch (e) { + logger.e(e); + } + }); + + logger.i("services discovered"); + + findCharac(svcs); } catch (e) { logger.e(e); dev.disconnect().ignore(); @@ -95,4 +116,33 @@ class DeviceDetailsState extends State<DeviceDetailsScreen> { } } } + + void findCharac(List<BluetoothService> svcs) { + if (svcs.isEmpty) { + connectStatus += ", No services found!"; + return; + } + connectStatus += ", Services found!"; + BluetoothService? badgeService = svcs.firstWhereOrNull( + (s) => s.serviceUuid.str == "ca260000-b4bb-46b2-bd06-b7b7a61ea990", + ); + + if (badgeService == null) { + } else { + logger.i("badge service found"); + current = badgeService.characteristics.firstWhereOrNull( + (c) => + c.characteristicUuid.str == "ca260001-b4bb-46b2-bd06-b7b7a61ea990", + ); + available = badgeService.characteristics.firstWhereOrNull( + (c) => + c.characteristicUuid.str == "ca260002-b4bb-46b2-bd06-b7b7a61ea990", + ); + } + + if (current == null || available == null) { + } else { + logger.i("characteristics found"); + } + } } |