Skip to content

Commit 9596560

Browse files
committed
attempt to make bluetooth UUIDs case insensitive
1 parent 7ded299 commit 9596560

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/Backend/Bluetooth/bluetooth_manager_plus.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class _OnDiscoveredServices extends _$OnDiscoveredServices {
143143
//Subscribes to all characteristics
144144
for (BluetoothService service in event.services) {
145145
BluetoothUartService? bluetoothUartService = uartServices.firstWhereOrNull(
146-
(element) => element.bleDeviceService == service.serviceUuid.str,
146+
(element) => element.bleDeviceService.toLowerCase() == service.serviceUuid.str.toLowerCase(),
147147
);
148148
if (bluetoothUartService != null) {
149149
BaseStatefulDevice? statefulDevice = ref.read(knownDevicesProvider)[event.device.remoteId.str];
@@ -326,9 +326,9 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
326326
if (statefulDevice == null) {
327327
return;
328328
}
329-
if (bluetoothCharacteristic.characteristicUuid == Guid("2a19")) {
329+
if (bluetoothCharacteristic.characteristicUuid.str.toLowerCase() == "2a19") {
330330
statefulDevice.batteryLevel.value = values.first.toDouble();
331-
} else if (bluetoothCharacteristic.characteristicUuid == Guid("5073792e-4fc0-45a0-b0a5-78b6c1756c91")) {
331+
} else if (bluetoothCharacteristic.characteristicUuid.str.toLowerCase() == "5073792e-4fc0-45a0-b0a5-78b6c1756c91") {
332332
try {
333333
String value = const Utf8Decoder().convert(values);
334334
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: value));
@@ -338,7 +338,7 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived {
338338
statefulDevice.messageHistory.add(MessageHistoryEntry(type: MessageHistoryType.receive, message: "Unknown: ${values.toString()}"));
339339
return;
340340
}
341-
} else if (statefulDevice.bluetoothUartService.value != null || bluetoothCharacteristic.characteristicUuid == Guid(statefulDevice.bluetoothUartService.value!.bleRxCharacteristic)) {
341+
} else if (statefulDevice.bluetoothUartService.value != null || bluetoothCharacteristic.characteristicUuid.str.toLowerCase() == statefulDevice.bluetoothUartService.value!.bleRxCharacteristic.toLowerCase()) {
342342
String value = "";
343343
try {
344344
value = const Utf8Decoder().convert(values);
@@ -555,8 +555,10 @@ Future<void> sendMessage(BaseStatefulDevice device, List<int> message, {bool wit
555555
}
556556
BluetoothDevice? bluetoothDevice = flutterBluePlus.connectedDevices.firstWhereOrNull((element) => element.remoteId.str == device.baseStoredDevice.btMACAddress);
557557
if (bluetoothDevice != null && device.bluetoothUartService.value != null) {
558-
BluetoothCharacteristic? bluetoothCharacteristic =
559-
bluetoothDevice.servicesList.firstWhereOrNull((element) => element.uuid == Guid(device.bluetoothUartService.value!.bleDeviceService))?.characteristics.firstWhereOrNull((element) => element.characteristicUuid == Guid(device.bluetoothUartService.value!.bleTxCharacteristic));
558+
BluetoothCharacteristic? bluetoothCharacteristic = bluetoothDevice.servicesList
559+
.firstWhereOrNull((element) => element.uuid.str.toLowerCase() == device.bluetoothUartService.value!.bleDeviceService.toLowerCase())
560+
?.characteristics
561+
.firstWhereOrNull((element) => element.characteristicUuid.str.toLowerCase() == device.bluetoothUartService.value!.bleTxCharacteristic.toLowerCase());
560562
if (bluetoothCharacteristic == null) {
561563
_bluetoothPlusLogger.warning("Unable to find bluetooth characteristic to send command to");
562564
return;

0 commit comments

Comments
 (0)