1import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_service.dart';
 2import 'package:bluetooth_low_energy/bluetooth_low_energy.dart';
 3
 4/// UUID wrapper for BluetoothLowEnergy
 5final class BluetoothLowEnergyUUID extends BluetoothUuid<UUID> {
 6  /// Create a [BluetoothLowEnergyUUID] from a [UUID]
 7  BluetoothLowEnergyUUID(UUID uuid): super(uuid: uuid.toString(), source: uuid);
 8
 9  /// Create a [BluetoothLowEnergyUUID] from a [String]
10  factory BluetoothLowEnergyUUID.fromString(String uuid) => BluetoothLowEnergyUUID(UUID.fromString(uuid));
11}
12
13/// Wrapper class with generic interface for a [GATTService]
14final class BluetoothLowEnergyService
15    extends BluetoothService<GATTService, BluetoothLowEnergyCharacteristic> {
16
17   /// Create a [BluetoothLowEnergyService] from a [GATTService]
18  BluetoothLowEnergyService.fromSource(GATTService service):
19    super(uuid: BluetoothLowEnergyUUID(service.uuid), source: service);
20
21  @override
22  List<BluetoothLowEnergyCharacteristic> get characteristics => source.characteristics.map(BluetoothLowEnergyCharacteristic.fromSource).toList();
23}
24
25/// Wrapper class with generic interface for a [GATTCharacteristic]
26final class BluetoothLowEnergyCharacteristic extends BluetoothCharacteristic<GATTCharacteristic> {
27  /// Create a [BluetoothLowEnergyCharacteristic] from the backend specific source
28  BluetoothLowEnergyCharacteristic.fromSource(GATTCharacteristic source):
29    super(uuid: BluetoothLowEnergyUUID(source.uuid), source: source);
30
31  @override
32  bool get canRead => source.properties.contains(GATTCharacteristicProperty.read);
33
34  @override
35  bool get canWrite => source.properties.contains(GATTCharacteristicProperty.write);
36
37  @override
38  bool get canWriteWithoutResponse => source.properties.contains(GATTCharacteristicProperty.writeWithoutResponse);
39
40  @override
41  bool get canNotify => source.properties.contains(GATTCharacteristicProperty.notify);
42
43  @override
44  bool get canIndicate => source.properties.contains(GATTCharacteristicProperty.indicate);
45}