From 42b1fdba692bc4ef9e98b908017db783c294ef2d Mon Sep 17 00:00:00 2001 From: Viktar Hushchynski Date: Thu, 11 Apr 2024 22:00:30 -0400 Subject: [PATCH 1/2] fix: Fix compatibility with the new fw --- .../actions/ble_receive_w_a_v.dart | 108 ++++++++++-------- firmware/prj.conf | 4 + 2 files changed, 67 insertions(+), 45 deletions(-) diff --git a/AppWithWearable/lib/custom_code/actions/ble_receive_w_a_v.dart b/AppWithWearable/lib/custom_code/actions/ble_receive_w_a_v.dart index b33b5972925..9d6bbe87876 100644 --- a/AppWithWearable/lib/custom_code/actions/ble_receive_w_a_v.dart +++ b/AppWithWearable/lib/custom_code/actions/ble_receive_w_a_v.dart @@ -23,6 +23,12 @@ const int channelCount = 1; const int sampleWidth = 2; // 2 bytes for 16-bit samples const int chunkSize = 200; +// UUIDs for the specific service and characteristics +const String audioServiceUuid = "19b10000-e8f2-537e-4f6c-d104768a1214"; +const String audioCharacteristicUuid = "19b10001-e8f2-537e-4f6c-d104768a1214"; +const String audioCharacteristicFormatUuid = + "19b10002-e8f2-537e-4f6c-d104768a1214"; + /*List filterAudioData(List audioData) { // Calculate the scaling factor // @@ -50,56 +56,68 @@ Future bleReceiveWAV( print('Discovered ${services.length} services'); for (BluetoothService service in services) { - for (BluetoothCharacteristic characteristic in service.characteristics) { - final isNotify = characteristic.properties.notify; - - if (isNotify) { - await characteristic.setNotifyValue(true); - print('Subscribed to characteristic: ${characteristic.uuid}'); - List wavData = []; - int samplesToRead = 150000; - - characteristic.value.listen((value) { - value.removeRange(0, 3); - print('values -- ${value[0]}, ${value[1]}'); - - // Interpret bytes as Int16 directly - for (int i = 0; i < value.length; i += 2) { - int byte1 = value[i]; - int byte2 = value[i + 1]; - int int16Value = (byte2 << 8) | byte1; - wavData.add(int16Value); - - print('$int16Value'); - } - - print( - 'Received ------ ${value.length ~/ 2} samples, total: ${wavData.length}/$samplesToRead'); - if (wavData.length >= samplesToRead && !completer.isCompleted) { - print('Received desired amount of data'); - characteristic.setNotifyValue(false); - completer.complete(createWavFile(wavData)); - } else { - print('Still need ${samplesToRead - wavData.length} samples'); + if (service.uuid.str128.toLowerCase() == audioServiceUuid) { + for (BluetoothCharacteristic characteristic + in service.characteristics) { + if (characteristic.uuid.str128.toLowerCase() == + audioCharacteristicUuid || + characteristic.uuid.str128.toLowerCase() == + audioCharacteristicFormatUuid) { + final isNotify = characteristic.properties.notify; + + if (isNotify) { + await characteristic.setNotifyValue(true); + print( + 'Subscribed to characteristic: ${characteristic.uuid.str128}'); + List wavData = []; + int samplesToRead = 150000; + + characteristic.value.listen((value) { + if (value.isEmpty) return; + value.removeRange(0, 3); + // print('values -- ${value[0]}, ${value[1]}'); + + // Interpret bytes as Int16 directly + for (int i = 0; i < value.length; i += 2) { + int byte1 = value[i]; + int byte2 = value[i + 1]; + int int16Value = (byte2 << 8) | byte1; + wavData.add(int16Value); + + //print('$int16Value'); + } + + print( + 'Received ------ ${value.length ~/ 2} samples, total: ${wavData.length}/$samplesToRead'); + if (wavData.length >= samplesToRead && !completer.isCompleted) { + print('Received desired amount of data'); + characteristic.setNotifyValue(false); + completer.complete(createWavFile(wavData)); + } else { + print('Still need ${samplesToRead - wavData.length} samples'); + } + }); + + // Wait for the desired duration + final waitSeconds = recordDuration + 20; + await Future.delayed(Duration(seconds: waitSeconds)); + + // If the desired amount of data is not received within the duration, + // return null if the completer is not already completed + if (!completer.isCompleted) { + print( + 'Recording duration reached without receiving enough data'); + await characteristic.setNotifyValue(false); + completer.complete(null); + } + + return completer.future; } - }); - - // Wait for the desired duration - final waitSeconds = recordDuration + 20; - await Future.delayed(Duration(seconds: waitSeconds)); - - // If the desired amount of data is not received within the duration, - // return null if the completer is not already completed - if (!completer.isCompleted) { - print('Recording duration reached without receiving enough data'); - await characteristic.setNotifyValue(false); - completer.complete(null); } - - return completer.future; } } } + print('Desired characteristic not found'); if (!completer.isCompleted) { completer.complete(null); diff --git a/firmware/prj.conf b/firmware/prj.conf index 5db4e9ea606..f67e743c783 100644 --- a/firmware/prj.conf +++ b/firmware/prj.conf @@ -5,6 +5,10 @@ CONFIG_GPIO=y CONFIG_NRFX_PDM=y +# To flash via dev board +#CONFIG_BUILD_OUTPUT_UF2=n +#CONFIG_USE_DT_CODE_PARTITION=n + # # Bluetooth settings # From 916a555b89323ec06c968e0a7638b666add50ee5 Mon Sep 17 00:00:00 2001 From: Viktar Hushchynski Date: Thu, 11 Apr 2024 22:01:43 -0400 Subject: [PATCH 2/2] chore: Delete not needed submodule --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index cdd2e433378..00000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "src/BLE_Audio_Stream_NRF52840"] - path = src/BLE_Audio_Stream_NRF52840 - url = https://github.com/aapatni/BLE_Audio_Stream_NRF52840