Skip to content

Commit

Permalink
Fix characteristic keying on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenboye committed Apr 9, 2024
1 parent 3fbd2e2 commit ed6809c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/src/universal_ble_linux/universal_ble_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ class UniversalBleLinux extends UniversalBlePlatform {
}

@override
Future<void> setNotifiable(String deviceId, String service,
String characteristic, BleInputProperty bleInputProperty) async {
Future<void> setNotifiable(String deviceId, String service, String characteristic, BleInputProperty bleInputProperty) async {
var key = "$deviceId-$service-$characteristic";

var char = _getCharacteristic(deviceId, service, characteristic);
if (bleInputProperty != BleInputProperty.disabled) {
if (char.notifying) throw Exception('Characteristic already notifying');

await char.startNotify();

if (_characteristicPropertiesSubscriptions[characteristic] != null) {
_characteristicPropertiesSubscriptions[characteristic]?.cancel();
if (_characteristicPropertiesSubscriptions[key] != null) {
_characteristicPropertiesSubscriptions[key]?.cancel();
}

_characteristicPropertiesSubscriptions[characteristic] =
char.propertiesChanged.listen((List<String> properties) {
_characteristicPropertiesSubscriptions[key] = char.propertiesChanged.listen((List<String> properties) {
for (String property in properties) {
switch (property) {
case BluezProperty.value:
Expand All @@ -171,15 +171,14 @@ class UniversalBleLinux extends UniversalBlePlatform {
);
break;
default:
UniversalBlePlatform.logInfo(
"UnhandledCharValuePropertyChange: $property");
UniversalBlePlatform.logInfo("UnhandledCharValuePropertyChange: $property");
}
}
});
} else {
if (!char.notifying) throw Exception('Characteristic not notifying');
await char.stopNotify();
_characteristicPropertiesSubscriptions.remove(characteristic)?.cancel();
_characteristicPropertiesSubscriptions.remove(key)?.cancel();
}
}

Expand Down

0 comments on commit ed6809c

Please sign in to comment.