Skip to content

Commit c5b2b50

Browse files
committed
Added Bluetooth descriptors
1 parent 41a0116 commit c5b2b50

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Removed Flutter as a dependency
44
* Added characteristic properties
55
* Added toLowerCase to every call that requires a UUID, because the web api expects only lower case UUIDS.
6+
* Added Bluetooth descriptors.
67

78
## 0.0.1
89

lib/src/bluetooth_characteristic_properties.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class BluetoothCharacteristicProperties {
1212
@visibleForTesting
1313
BluetoothCharacteristicProperties(this._properties);
1414

15-
WebBluetoothCharacteristicProperties _properties;
15+
final WebBluetoothCharacteristicProperties _properties;
1616

1717
bool get broadcast => _properties.broadcast;
1818

lib/src/bluetooth_descriptor.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
part of flutter_web_bluetooth;
2+
3+
class BluetoothDescriptor {
4+
@visibleForTesting
5+
BluetoothDescriptor(this._descriptor);
6+
7+
final WebBluetoothRemoteGATTDescriptor _descriptor;
8+
9+
String get uuid => _descriptor.uuid;
10+
11+
ByteData? get value => _descriptor.value;
12+
13+
///
14+
/// May throw [NotSupportedError] if the operation is not allowed.
15+
///
16+
Future<ByteData> readValue() async {
17+
try {
18+
return await _descriptor.readValue();
19+
} catch (e) {
20+
final error = e.toString().trim();
21+
if (error.startsWith('NotSupportedError')) {
22+
throw NotSupportedError(this.uuid);
23+
}
24+
throw e;
25+
}
26+
}
27+
28+
///
29+
/// May throw [NotSupportedError] if the operation is not allowed.
30+
///
31+
Future<void> writeValue(Uint8List data) async {
32+
try {
33+
_descriptor.writeValue(data);
34+
} catch (e) {
35+
final error = e.toString().trim();
36+
if (error.startsWith('NotSupportedError')) {
37+
throw NotSupportedError(this.uuid);
38+
}
39+
throw e;
40+
}
41+
}
42+
}

lib/src/flutter_web_bluetooth_unsupported.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ part 'bluetooth_characteristic_properties.dart';
1313

1414
part 'bluetooth_default_uuids.dart';
1515

16+
part 'bluetooth_descriptor.dart';
17+
1618
part 'bluetooth_device.dart';
1719

1820
part 'bluetooth_service.dart';

lib/src/flutter_web_bluetooth_web.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ part 'bluetooth_characteristic_properties.dart';
1414

1515
part 'bluetooth_default_uuids.dart';
1616

17+
part 'bluetooth_descriptor.dart';
18+
1719
part 'bluetooth_device.dart';
1820

1921
part 'bluetooth_service.dart';

0 commit comments

Comments
 (0)