Skip to content

Commit

Permalink
Added Bluetooth descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen1602 committed May 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 41a0116 commit c5b2b50
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
* Removed Flutter as a dependency
* Added characteristic properties
* Added toLowerCase to every call that requires a UUID, because the web api expects only lower case UUIDS.
* Added Bluetooth descriptors.

## 0.0.1

2 changes: 1 addition & 1 deletion lib/src/bluetooth_characteristic_properties.dart
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ class BluetoothCharacteristicProperties {
@visibleForTesting
BluetoothCharacteristicProperties(this._properties);

WebBluetoothCharacteristicProperties _properties;
final WebBluetoothCharacteristicProperties _properties;

bool get broadcast => _properties.broadcast;

42 changes: 42 additions & 0 deletions lib/src/bluetooth_descriptor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
part of flutter_web_bluetooth;

class BluetoothDescriptor {
@visibleForTesting
BluetoothDescriptor(this._descriptor);

final WebBluetoothRemoteGATTDescriptor _descriptor;

String get uuid => _descriptor.uuid;

ByteData? get value => _descriptor.value;

///
/// May throw [NotSupportedError] if the operation is not allowed.
///
Future<ByteData> readValue() async {
try {
return await _descriptor.readValue();
} catch (e) {
final error = e.toString().trim();
if (error.startsWith('NotSupportedError')) {
throw NotSupportedError(this.uuid);
}
throw e;
}
}

///
/// May throw [NotSupportedError] if the operation is not allowed.
///
Future<void> writeValue(Uint8List data) async {
try {
_descriptor.writeValue(data);
} catch (e) {
final error = e.toString().trim();
if (error.startsWith('NotSupportedError')) {
throw NotSupportedError(this.uuid);
}
throw e;
}
}
}
2 changes: 2 additions & 0 deletions lib/src/flutter_web_bluetooth_unsupported.dart
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ part 'bluetooth_characteristic_properties.dart';

part 'bluetooth_default_uuids.dart';

part 'bluetooth_descriptor.dart';

part 'bluetooth_device.dart';

part 'bluetooth_service.dart';
2 changes: 2 additions & 0 deletions lib/src/flutter_web_bluetooth_web.dart
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ part 'bluetooth_characteristic_properties.dart';

part 'bluetooth_default_uuids.dart';

part 'bluetooth_descriptor.dart';

part 'bluetooth_device.dart';

part 'bluetooth_service.dart';

0 comments on commit c5b2b50

Please sign in to comment.