-
Notifications
You must be signed in to change notification settings - Fork 3
Serial #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Serial #36
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
5a37c04
Add base Flutter dependencies
abelfodil 65cf38d
Bump minimal android sdk version
abelfodil 0c53add
Increment and decrement with counter cubit & create main/app/locator …
8697b35
create and implement domain layer
38e939e
Connection bluetooth avec le ganglion
MouradLachhab 15e4ab8
Create Flutter code structure example based on this [arch](https://gi…
ff2854f
Merge branch 'master' of https://github.com/PolyCortex/polydodo into …
428d554
Remove widget test specific to counter app
118ed85
Create an empty test for pipeline to perform build
baebeab
Create an empty test in order for build pipeline to pass
0c23975
fix mistake: move test/ under mobile/
37b8cc2
Requete de donnees et enregistrement sur csv
MouradLachhab a756532
Changement du format du fichier output pour openBCI
MouradLachhab 6c66e52
Merge remote-tracking branch 'remotes/origin/base-arch-structure' int…
MouradLachhab c7929d5
Fixed some duplicates
MouradLachhab 6663be0
Merge branch 'base-arch-structure' into bluetooth
MouradLachhab 0809597
Finished updating bluetooth files. Missing csv feature
MouradLachhab 437ff84
Added recording feature
MouradLachhab dd515c8
Removed main2 temporary file
MouradLachhab 8a56384
Removed unecessary prints
MouradLachhab 475aef0
Extracted variable and renamed for clarity
MouradLachhab 3468343
Removed unecessary imports and exposed methods in bluetooth interface
MouradLachhab 9680850
Removed unecessary bluetooth from domain
MouradLachhab 71c36f2
Created eeg data repository
MouradLachhab 6985672
Changed string id to UniqueID, fixed state inconsistency
MouradLachhab 3bead5f
Fixed typo, removed unecessary delay
MouradLachhab 5cd7bf4
Merging Master into bluetooth
MouradLachhab 707a85f
format
abelfodil 3c67918
Fixed typo
MouradLachhab 80f22c5
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
MouradLachhab 82c7b1e
Removed general export files in favor of individual import
MouradLachhab 798d10a
Added missing files for last commit
MouradLachhab dd694c5
Extracted openbci header and only adding it at export time
MouradLachhab d9a554a
Added error handling for failed connections
MouradLachhab 226d8e6
Handling already connected error and cleaned slightly findCharacteris…
MouradLachhab 2af1964
Merge branch 'master' into bluetooth
MouradLachhab b4192ad
Switched to generic acquisiton device in application layer
MouradLachhab 6a6edd6
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
MouradLachhab b95d5b2
Reverted merge with master
MouradLachhab 351c57b
Added handling for packet id 0 and fixed data values
MouradLachhab bc62be0
Returning Container in view instead of new ListView
MouradLachhab 6056901
Remove default formatter for workspace because it prevents dartfmt to…
436aa8e
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
7a463c1
Reset esbenp.prettier-vscode as default formatter, but specified dart…
bbe2475
Changes based on last pull request comments (injecting flutter blue i…
MouradLachhab fdda64d
Changed Acquisition initialization method to more generic name instea…
MouradLachhab 6bd2028
Initial connection with usb serial achieved, missing data formatting
MouradLachhab a44ca17
Merge branch 'bluetooth' into serial
MouradLachhab 4a4fecd
Renamed serial port
MouradLachhab 7561a4d
Moved back flutter instance into repository initialization and created
MouradLachhab e237995
Merge branch 'bluetooth' into serial
MouradLachhab f3719b6
Switched to AcquisitionDevice interface usage
MouradLachhab 303a8df
Merge branch 'master' into serial
MouradLachhab c68745b
Seperated data formatting into stream transformer
MouradLachhab 9c08814
Implemented Cyton transformer
MouradLachhab 469cd05
Small convention changes and changed BaseTransformer to an abstract c…
MouradLachhab 3b865b7
Made async function into future
MouradLachhab 6abde11
Removed transformer interface
MouradLachhab b63d3b9
Dynamically changing repositories and transformers
MouradLachhab 326db2e
Added missing file
MouradLachhab 60cdf14
Fixed negative handling in cyton transformer and cleaned up a bit
MouradLachhab c252b57
Added unit testing
MouradLachhab 254e647
Awaiting stream in serial
MouradLachhab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
|
|
||
| <!-- 0x0403 / FTDI --> | ||
| <usb-device vendor-id="1027" /> | ||
|
|
||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
mobile/lib/src/infrastructure/connection_repositories/acquisition_device_repository.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:polydodo/src/domain/acquisition_device/acquisition_device.dart'; | ||
| import 'package:polydodo/src/domain/acquisition_device/i_acquisition_device_repository.dart'; | ||
| import 'package:polydodo/src/infrastructure/connection_repositories/bluetooth_repository.dart'; | ||
| import 'package:polydodo/src/infrastructure/connection_repositories/serial_repository.dart'; | ||
| import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; | ||
|
|
||
| class AcquisitionDeviceRepository implements IAcquisitionDeviceRepository { | ||
| final BluetoothRepository _bluetoothRepository = new BluetoothRepository(); | ||
| final SerialRepository _serialRepository = new SerialRepository(); | ||
| IAcquisitionDeviceRepository _currentRepository; | ||
|
|
||
| StreamSubscription _bluetoothStream; | ||
| StreamSubscription _serialStream; | ||
| StreamSubscription _currentStream; | ||
|
|
||
| StreamController<List<AcquisitionDevice>> _acquisitionDeviceController; | ||
| StreamingSharedPreferences _preferences; | ||
|
|
||
| AcquisitionDeviceRepository() { | ||
| _currentRepository = _serialRepository; | ||
| _acquisitionDeviceController = new StreamController(); | ||
| } | ||
|
|
||
| Future<void> initializeRepository() async { | ||
| if (_preferences == null) { | ||
| _preferences = await StreamingSharedPreferences.instance; | ||
| _preferences | ||
| .getBool('using_bluetooth', defaultValue: false) | ||
| .listen((usingBluetooth) { | ||
| disconnect(); | ||
| _currentStream.pause(); | ||
| _currentRepository = | ||
| usingBluetooth ? _bluetoothRepository : _serialRepository; | ||
| _currentRepository.initializeRepository(); | ||
| _currentStream = usingBluetooth ? _bluetoothStream : _serialStream; | ||
| _currentStream.resume(); | ||
| }); | ||
|
|
||
| _serialStream = _serialRepository.watch().listen((event) { | ||
| _acquisitionDeviceController.add(event); | ||
| }); | ||
| _bluetoothStream = _bluetoothRepository.watch().listen((event) { | ||
| _acquisitionDeviceController.add(event); | ||
| }); | ||
|
|
||
| _currentStream = _bluetoothStream; | ||
| _serialStream.pause(); | ||
| } | ||
| } | ||
|
|
||
| void connect(AcquisitionDevice device, Function(bool, Exception) callback) { | ||
| _currentRepository.connect(device, callback); | ||
| } | ||
|
|
||
| void disconnect() { | ||
| _currentRepository.disconnect(); | ||
| } | ||
|
|
||
| Future<Stream<List<int>>> startDataStream() { | ||
| return _currentRepository.startDataStream(); | ||
| } | ||
|
|
||
| void stopDataStream() { | ||
| _currentRepository.stopDataStream(); | ||
| } | ||
|
|
||
| Stream<List<AcquisitionDevice>> watch() { | ||
| return _acquisitionDeviceController.stream; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
mobile/lib/src/infrastructure/connection_repositories/eeg_data_repository.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import 'dart:async'; | ||
| import 'dart:io'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:csv/csv.dart'; | ||
| import 'package:path_provider/path_provider.dart'; | ||
| import 'package:polydodo/src/domain/eeg_data/eeg_data.dart'; | ||
| import 'package:polydodo/src/domain/eeg_data/i_eeg_data_repository.dart'; | ||
| import 'package:polydodo/src/domain/unique_id.dart'; | ||
| import 'package:polydodo/src/infrastructure/eeg_data_transformers/baseOpenBCITransformer.dart'; | ||
| import 'package:polydodo/src/infrastructure/eeg_data_transformers/cytonTransformer.dart'; | ||
| import 'package:polydodo/src/infrastructure/constants.dart'; | ||
| import 'package:polydodo/src/infrastructure/eeg_data_transformers/ganglionTransformer.dart'; | ||
| import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; | ||
|
|
||
| class EEGDataRepository implements IEEGDataRepository { | ||
| EEGData _recordingData; | ||
| BaseOpenBCITransformer<List<int>, List<dynamic>> currentStreamTransformer; | ||
|
|
||
| final GanglionTransformer<List<int>, List> _ganglionTransformer = | ||
| new GanglionTransformer<List<int>, List>.broadcast(); | ||
|
|
||
| final CytonTransformer<List<int>, List<dynamic>> _cytonTransformer = | ||
| new CytonTransformer<Uint8List, List>.broadcast(); | ||
|
|
||
| BaseOpenBCITransformer<List<int>, List<dynamic>> _currentTransformer; | ||
| StreamSubscription _currentTransformerStream; | ||
|
|
||
| StreamingSharedPreferences _preferences; | ||
|
|
||
| void initialize() async { | ||
| if (_preferences == null) { | ||
| _preferences = await StreamingSharedPreferences.instance; | ||
| } | ||
|
|
||
| _currentTransformer = | ||
| _preferences.getBool('using_bluetooth', defaultValue: false).getValue() | ||
| ? _ganglionTransformer | ||
| : _cytonTransformer; | ||
| } | ||
|
|
||
| void createRecordingFromStream(Stream<List<int>> stream) { | ||
| _recordingData = | ||
| EEGData(UniqueId.from(DateTime.now().toString()), List<List>()); | ||
|
|
||
| _currentTransformer.reset(); | ||
| _currentTransformerStream = stream | ||
| .asBroadcastStream() | ||
| .transform(_currentTransformer) | ||
| .listen((data) => _recordingData.values.add(data)); | ||
| } | ||
|
|
||
| Future<void> stopRecordingFromStream() async { | ||
| // todo: move save future to another file | ||
| _currentTransformerStream.cancel(); | ||
|
|
||
| final directory = await getExternalStorageDirectory(); | ||
| final pathOfTheFileToWrite = | ||
| directory.path + '/' + _recordingData.fileName + ".txt"; | ||
| File file = File(pathOfTheFileToWrite); | ||
| List<List> fileContent = []; | ||
| //todo: dynamically change header when we change transformer | ||
| fileContent.addAll(OPEN_BCI_CYTON_HEADER); | ||
| fileContent.addAll(_recordingData.values); | ||
| String csv = const ListToCsvConverter().convert(fileContent); | ||
| await file.writeAsString(csv); | ||
| } | ||
|
|
||
| // todo: implement export and import | ||
| void importData() {} | ||
| void exportData() {} | ||
| } |
69 changes: 69 additions & 0 deletions
69
mobile/lib/src/infrastructure/connection_repositories/serial_repository.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import 'dart:async'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:polydodo/src/domain/unique_id.dart'; | ||
| import 'package:polydodo/src/domain/acquisition_device/acquisition_device.dart'; | ||
| import 'package:polydodo/src/domain/acquisition_device/i_acquisition_device_repository.dart'; | ||
| import 'package:polydodo/src/infrastructure/constants.dart'; | ||
| import 'package:usb_serial/usb_serial.dart'; | ||
|
|
||
| class SerialRepository implements IAcquisitionDeviceRepository { | ||
| UsbDevice _selectedDevice; | ||
| UsbPort _serialPort; | ||
| List<AcquisitionDevice> _acquisitionDevicePersistency = []; | ||
| List<UsbDevice> _serialDevices = []; | ||
| final streamController = StreamController<List<AcquisitionDevice>>(); | ||
|
|
||
| void initializeRepository() { | ||
| _acquisitionDevicePersistency.clear(); | ||
| _serialDevices.clear(); | ||
| UsbSerial.listDevices().then((devices) => addDevices(devices)); | ||
| } | ||
|
|
||
| void addDevices(List<UsbDevice> serialDevices) { | ||
| for (UsbDevice serialDevice in serialDevices) { | ||
| AcquisitionDevice device = AcquisitionDevice( | ||
| UniqueId.from(serialDevice.deviceId.toString()), | ||
| serialDevice.productName); | ||
|
|
||
| _acquisitionDevicePersistency.add(device); | ||
| _serialDevices.add(serialDevice); | ||
| } | ||
| streamController.add(_acquisitionDevicePersistency); | ||
| } | ||
|
|
||
| Future<void> connect( | ||
| AcquisitionDevice device, Function(bool, Exception) callback) async { | ||
| _selectedDevice = | ||
| _serialDevices[_acquisitionDevicePersistency.indexOf(device)]; | ||
| _serialPort = await _selectedDevice.create(); | ||
| bool openSuccessful = await _serialPort.open(); | ||
|
|
||
| if (!openSuccessful) { | ||
| callback(false, Exception("Could not open port")); | ||
| } | ||
|
|
||
| _serialPort.setPortParameters( | ||
| 115200, UsbPort.DATABITS_8, UsbPort.STOPBITS_1, UsbPort.PARITY_NONE); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optionnel, il y a moyen de setup le device à 921600 baud/s |
||
|
|
||
| callback(true, null); | ||
| } | ||
|
|
||
| Future<void> disconnect() async { | ||
| await _serialPort?.close(); | ||
| _selectedDevice = null; | ||
| _serialPort = null; | ||
| } | ||
|
|
||
| Future<Stream<List<int>>> startDataStream() async { | ||
| await _serialPort.write(Uint8List.fromList(START_STREAM_CHAR.codeUnits)); | ||
|
|
||
| return _serialPort.inputStream; | ||
| } | ||
|
|
||
| Future<void> stopDataStream() async { | ||
| await _serialPort.write(Uint8List.fromList(STOP_STREAM_CHAR.codeUnits)); | ||
| } | ||
|
|
||
| Stream<List<AcquisitionDevice>> watch() => streamController.stream; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.