Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
5a37c04
Add base Flutter dependencies
abelfodil Sep 13, 2020
65cf38d
Bump minimal android sdk version
abelfodil Sep 14, 2020
0c53add
Increment and decrement with counter cubit & create main/app/locator …
Sep 15, 2020
8697b35
create and implement domain layer
Sep 15, 2020
38e939e
Connection bluetooth avec le ganglion
MouradLachhab Sep 17, 2020
15e4ab8
Create Flutter code structure example based on this [arch](https://gi…
Sep 19, 2020
ff2854f
Merge branch 'master' of https://github.com/PolyCortex/polydodo into …
Sep 19, 2020
428d554
Remove widget test specific to counter app
Sep 19, 2020
118ed85
Create an empty test for pipeline to perform build
Sep 19, 2020
baebeab
Create an empty test in order for build pipeline to pass
Sep 19, 2020
0c23975
fix mistake: move test/ under mobile/
Sep 19, 2020
37b8cc2
Requete de donnees et enregistrement sur csv
MouradLachhab Sep 20, 2020
a756532
Changement du format du fichier output pour openBCI
MouradLachhab Sep 23, 2020
6c66e52
Merge remote-tracking branch 'remotes/origin/base-arch-structure' int…
MouradLachhab Sep 23, 2020
c7929d5
Fixed some duplicates
MouradLachhab Sep 23, 2020
6663be0
Merge branch 'base-arch-structure' into bluetooth
MouradLachhab Sep 24, 2020
0809597
Finished updating bluetooth files. Missing csv feature
MouradLachhab Sep 24, 2020
437ff84
Added recording feature
MouradLachhab Sep 24, 2020
dd515c8
Removed main2 temporary file
MouradLachhab Sep 24, 2020
8a56384
Removed unecessary prints
MouradLachhab Sep 28, 2020
475aef0
Extracted variable and renamed for clarity
MouradLachhab Sep 28, 2020
3468343
Removed unecessary imports and exposed methods in bluetooth interface
MouradLachhab Sep 28, 2020
9680850
Removed unecessary bluetooth from domain
MouradLachhab Sep 28, 2020
71c36f2
Created eeg data repository
MouradLachhab Sep 28, 2020
6985672
Changed string id to UniqueID, fixed state inconsistency
MouradLachhab Sep 29, 2020
3bead5f
Fixed typo, removed unecessary delay
MouradLachhab Sep 30, 2020
5cd7bf4
Merging Master into bluetooth
MouradLachhab Oct 1, 2020
707a85f
format
abelfodil Oct 1, 2020
3c67918
Fixed typo
MouradLachhab Oct 1, 2020
80f22c5
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
MouradLachhab Oct 1, 2020
82c7b1e
Removed general export files in favor of individual import
MouradLachhab Oct 1, 2020
798d10a
Added missing files for last commit
MouradLachhab Oct 1, 2020
dd694c5
Extracted openbci header and only adding it at export time
MouradLachhab Oct 1, 2020
d9a554a
Added error handling for failed connections
MouradLachhab Oct 1, 2020
226d8e6
Handling already connected error and cleaned slightly findCharacteris…
MouradLachhab Oct 1, 2020
2af1964
Merge branch 'master' into bluetooth
MouradLachhab Oct 2, 2020
b4192ad
Switched to generic acquisiton device in application layer
MouradLachhab Oct 3, 2020
6a6edd6
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
MouradLachhab Oct 3, 2020
b95d5b2
Reverted merge with master
MouradLachhab Oct 3, 2020
351c57b
Added handling for packet id 0 and fixed data values
MouradLachhab Oct 3, 2020
bc62be0
Returning Container in view instead of new ListView
MouradLachhab Oct 3, 2020
6056901
Remove default formatter for workspace because it prevents dartfmt to…
Oct 3, 2020
436aa8e
Merge branch 'bluetooth' of https://github.com/PolyCortex/polydodo in…
Oct 3, 2020
7a463c1
Reset esbenp.prettier-vscode as default formatter, but specified dart…
Oct 3, 2020
bbe2475
Changes based on last pull request comments (injecting flutter blue i…
MouradLachhab Oct 4, 2020
fdda64d
Changed Acquisition initialization method to more generic name instea…
MouradLachhab Oct 4, 2020
6bd2028
Initial connection with usb serial achieved, missing data formatting
MouradLachhab Oct 4, 2020
a44ca17
Merge branch 'bluetooth' into serial
MouradLachhab Oct 6, 2020
4a4fecd
Renamed serial port
MouradLachhab Oct 6, 2020
7561a4d
Moved back flutter instance into repository initialization and created
MouradLachhab Oct 6, 2020
e237995
Merge branch 'bluetooth' into serial
MouradLachhab Oct 8, 2020
f3719b6
Switched to AcquisitionDevice interface usage
MouradLachhab Oct 8, 2020
303a8df
Merge branch 'master' into serial
MouradLachhab Oct 12, 2020
c68745b
Seperated data formatting into stream transformer
MouradLachhab Oct 12, 2020
9c08814
Implemented Cyton transformer
MouradLachhab Oct 13, 2020
469cd05
Small convention changes and changed BaseTransformer to an abstract c…
MouradLachhab Oct 14, 2020
3b865b7
Made async function into future
MouradLachhab Oct 16, 2020
6abde11
Removed transformer interface
MouradLachhab Oct 16, 2020
b63d3b9
Dynamically changing repositories and transformers
MouradLachhab Oct 16, 2020
326db2e
Added missing file
MouradLachhab Oct 18, 2020
60cdf14
Fixed negative handling in cyton transformer and cleaned up a bit
MouradLachhab Oct 19, 2020
c252b57
Added unit testing
MouradLachhab Oct 19, 2020
254e647
Awaiting stream in serial
MouradLachhab Oct 19, 2020
6625807
Added status check for Cyton
MouradLachhab Oct 25, 2020
09a75be
Merge branch 'master' into serial
MouradLachhab Oct 25, 2020
ff5022c
Made exception parameter optional
MouradLachhab Oct 26, 2020
9b8c10f
Using implicit variable type instead of string
MouradLachhab Oct 26, 2020
0f8669c
Added overrides for interface implemented methods
MouradLachhab Oct 27, 2020
9044602
Linter changes using pedantic
MouradLachhab Oct 28, 2020
4daf17d
Merge branch 'master' into linter
MouradLachhab Oct 28, 2020
57c9c64
Fixed error from list on data save
MouradLachhab Oct 28, 2020
3082195
Trying minimum iOS 11.0
MouradLachhab Oct 28, 2020
8ad8100
Added analysis option file for linter
MouradLachhab Oct 28, 2020
1ac633a
Fixed more linting issues, ignoring protos, added analyze to mobile w…
MouradLachhab Oct 28, 2020
325a380
Fixed linting issue
MouradLachhab Oct 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:

- run: flutter pub get

- run: flutter analyze

- run: flutter test

- run: flutter build apk
Expand Down
9 changes: 9 additions & 0 deletions mobile/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
- lib/protos

linter:
rules:
avoid_shadowing_type_parameters: false
2 changes: 1 addition & 1 deletion mobile/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>10.0</string>
<string>11.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions mobile/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -354,7 +354,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -403,7 +403,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
19 changes: 8 additions & 11 deletions mobile/lib/src/application/device/device_selector_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.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:streaming_shared_preferences/streaming_shared_preferences.dart';
import 'package:pedantic/pedantic.dart';
Comment thread
abelfodil marked this conversation as resolved.
import 'device_selector_state.dart';

class DeviceSelectorCubit extends Cubit<DeviceState> {
Expand All @@ -21,13 +22,11 @@ class DeviceSelectorCubit extends Cubit<DeviceState> {
void startSearching() {
_deviceRepository.initializeRepository();

if (_acquisitionDeviceStream == null) {
_acquisitionDeviceStream = _deviceRepository
.watch()
.asBroadcastStream()
.listen((devices) => emit(DeviceSearchInProgress(devices)),
onError: (e) => emit(DeviceSearchFailure(e)));
}
_acquisitionDeviceStream ??= _deviceRepository
.watch()
.asBroadcastStream()
.listen((devices) => emit(DeviceSearchInProgress(devices)),
onError: (e) => emit(DeviceSearchFailure(e)));
}

Future<void> connect(AcquisitionDevice device) async {
Expand All @@ -53,11 +52,9 @@ class DeviceSelectorCubit extends Cubit<DeviceState> {

// todo: change bluetooth preferences in the preference section of the app
void swapBluetooth() async {
print("swap");
usingBluetooth = !usingBluetooth;
StreamingSharedPreferences _prefs =
await StreamingSharedPreferences.instance;
var _prefs = await StreamingSharedPreferences.instance;

_prefs.setBool('using_bluetooth', usingBluetooth);
unawaited(_prefs.setBool('using_bluetooth', usingBluetooth));
}
}
2 changes: 1 addition & 1 deletion mobile/lib/src/domain/unique_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class UniqueId extends Equatable {
List<Object> get props => [_id];

@override
toString() => _id;
String toString() => _id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:polydodo/src/infrastructure/connection_repositories/serial_repos
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';

class AcquisitionDeviceRepository implements IAcquisitionDeviceRepository {
final BluetoothRepository _bluetoothRepository = new BluetoothRepository();
final SerialRepository _serialRepository = new SerialRepository();
final BluetoothRepository _bluetoothRepository = BluetoothRepository();
final SerialRepository _serialRepository = SerialRepository();
IAcquisitionDeviceRepository _currentRepository;

StreamSubscription _bluetoothStream;
Expand All @@ -20,9 +20,10 @@ class AcquisitionDeviceRepository implements IAcquisitionDeviceRepository {

AcquisitionDeviceRepository() {
_currentRepository = _serialRepository;
_acquisitionDeviceController = new StreamController();
_acquisitionDeviceController = StreamController();
}

@override
Future<void> initializeRepository() async {
if (_preferences == null) {
_preferences = await StreamingSharedPreferences.instance;
Expand Down Expand Up @@ -50,22 +51,27 @@ class AcquisitionDeviceRepository implements IAcquisitionDeviceRepository {
}
}

@override
void connect(AcquisitionDevice device, Function(bool, Exception) callback) {
_currentRepository.connect(device, callback);
}

@override
void disconnect() {
_currentRepository.disconnect();
}

@override
Future<Stream<List<int>>> startDataStream() {
return _currentRepository.startDataStream();
}

@override
void stopDataStream() {
_currentRepository.stopDataStream();
}

@override
Stream<List<AcquisitionDevice>> watch() {
return _acquisitionDeviceController.stream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ 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:polydodo/src/domain/unique_id.dart';
import 'package:pedantic/pedantic.dart';
Comment thread
abelfodil marked this conversation as resolved.

class BluetoothRepository implements IAcquisitionDeviceRepository {
static const String BLE_SERVICE = "0000fe84-0000-1000-8000-00805f9b34fb";
static const String BLE_RECEIVE = "2d30c082-f39f-4ce6-923f-3484ea480596";
static const String BLE_SEND = "2d30c083-f39f-4ce6-923f-3484ea480596";
static const String BLE_SERVICE = '0000fe84-0000-1000-8000-00805f9b34fb';
static const String BLE_RECEIVE = '2d30c082-f39f-4ce6-923f-3484ea480596';
static const String BLE_SEND = '2d30c083-f39f-4ce6-923f-3484ea480596';

AcquisitionDevice _selectedDevice;
QualifiedCharacteristic _sendCharacteristic;
Expand All @@ -18,7 +19,7 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
FlutterReactiveBle flutterReactiveBle;
StreamSubscription<ConnectionStateUpdate> _connectedDeviceStream;
StreamSubscription<DiscoveredDevice> _bluetoothScanSubscription;
List<AcquisitionDevice> _acquisitionDevicePersistency = [];
final List<AcquisitionDevice> _acquisitionDevicePersistency = [];
final streamController = StreamController<List<AcquisitionDevice>>();

@override
Expand All @@ -35,7 +36,7 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
}

void addDevice(DiscoveredDevice bluetoothDevice) {
AcquisitionDevice device = AcquisitionDevice(
var device = AcquisitionDevice(
UniqueId.from(bluetoothDevice.id.toString()), bluetoothDevice.name);

final idx = _acquisitionDevicePersistency.indexOf(device);
Expand Down Expand Up @@ -66,15 +67,15 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
callback(true);
} else if (event.connectionState == DeviceConnectionState.disconnected) {
disconnect();
callback(false, Exception("Failed to connect to device"));
callback(false, Exception('Failed to connect to device'));
}
});
}

@override
void disconnect() async {
Future<void> disconnect() async {
_selectedDevice = null;
_connectedDeviceStream?.cancel();
await _connectedDeviceStream?.cancel();
}

void setupCharacteristics() async {
Expand All @@ -95,8 +96,9 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
deviceId: _selectedDevice.id.toString(),
priority: ConnectionPriority.highPerformance);

flutterReactiveBle.writeCharacteristicWithoutResponse(_sendCharacteristic,
value: START_STREAM_CHAR.codeUnits);
unawaited(flutterReactiveBle.writeCharacteristicWithoutResponse(
_sendCharacteristic,
value: START_STREAM_CHAR.codeUnits));

return flutterReactiveBle.subscribeToCharacteristic(_receiveCharacteristic);
}
Expand All @@ -106,8 +108,9 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
await flutterReactiveBle.requestConnectionPriority(
deviceId: _selectedDevice.id.toString(),
priority: ConnectionPriority.balanced);
flutterReactiveBle.writeCharacteristicWithoutResponse(_sendCharacteristic,
value: STOP_STREAM_CHAR.codeUnits);
unawaited(flutterReactiveBle.writeCharacteristicWithoutResponse(
_sendCharacteristic,
value: STOP_STREAM_CHAR.codeUnits));
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@ import 'package:polydodo/src/infrastructure/eeg_data_transformers/cytonTransform
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';
import 'package:pedantic/pedantic.dart';
Comment thread
abelfodil marked this conversation as resolved.

class EEGDataRepository implements IEEGDataRepository {
EEGData _recordingData;
BaseOpenBCITransformer<List<int>, List<dynamic>> currentStreamTransformer;

final GanglionTransformer<List<int>, List> _ganglionTransformer =
new GanglionTransformer<List<int>, List>.broadcast();
GanglionTransformer<List<int>, List>.broadcast();

final CytonTransformer<List<int>, List<dynamic>> _cytonTransformer =
new CytonTransformer<Uint8List, List>.broadcast();
CytonTransformer<Uint8List, List>.broadcast();

BaseOpenBCITransformer<List<int>, List<dynamic>> _currentTransformer;
StreamSubscription _currentTransformerStream;

StreamingSharedPreferences _preferences;

@override
void initialize() async {
if (_preferences == null) {
_preferences = await StreamingSharedPreferences.instance;
}
_preferences ??= await StreamingSharedPreferences.instance;

_currentTransformer =
_preferences.getBool('using_bluetooth', defaultValue: false).getValue()
? _ganglionTransformer
: _cytonTransformer;
}

@override
void createRecordingFromStream(Stream<List<int>> stream) {
_recordingData =
EEGData(UniqueId.from(DateTime.now().toString()), List<List>());
_recordingData = EEGData(UniqueId.from(DateTime.now().toString()), [[]]);

_currentTransformer.reset();
_currentTransformerStream = stream
Expand All @@ -50,23 +50,27 @@ class EEGDataRepository implements IEEGDataRepository {
.listen((data) => _recordingData.values.add(data));
}

@override
Future<void> stopRecordingFromStream() async {
// todo: move save future to another file
_currentTransformerStream.cancel();
unawaited(_currentTransformerStream.cancel());

final directory = await getExternalStorageDirectory();
final pathOfTheFileToWrite =
directory.path + '/' + _recordingData.fileName + ".txt";
File file = File(pathOfTheFileToWrite);
List<List> fileContent = [];
directory.path + '/' + _recordingData.fileName + '.txt';
var file = File(pathOfTheFileToWrite);
var 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);
var csv = const ListToCsvConverter().convert(fileContent);
await file.writeAsString(csv);
}

// todo: implement export and import
@override
void importData() {}

@override
void exportData() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ 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';
import 'package:pedantic/pedantic.dart';
Comment thread
abelfodil marked this conversation as resolved.

class SerialRepository implements IAcquisitionDeviceRepository {
UsbDevice _selectedDevice;
UsbPort _serialPort;
List<AcquisitionDevice> _acquisitionDevicePersistency = [];
List<UsbDevice> _serialDevices = [];
StreamSubscription _inputStreamSubscription;
final List<AcquisitionDevice> _acquisitionDevicePersistency = [];
final List<UsbDevice> _serialDevices = [];
final streamController = StreamController<List<AcquisitionDevice>>();

@override
Expand All @@ -23,8 +24,8 @@ class SerialRepository implements IAcquisitionDeviceRepository {
}

void addDevices(List<UsbDevice> serialDevices) {
for (UsbDevice serialDevice in serialDevices) {
AcquisitionDevice device = AcquisitionDevice(
for (var serialDevice in serialDevices) {
var device = AcquisitionDevice(
UniqueId.from(serialDevice.deviceId.toString()),
serialDevice.productName);

Expand All @@ -40,31 +41,31 @@ class SerialRepository implements IAcquisitionDeviceRepository {
_selectedDevice =
_serialDevices[_acquisitionDevicePersistency.indexOf(device)];
_serialPort = await _selectedDevice.create();
bool openSuccessful = await _serialPort.open();
var openSuccessful = await _serialPort.open();

if (!openSuccessful) {
callback(false, Exception("Could not open port"));
callback(false, Exception('Could not open port'));
}

_serialPort.setPortParameters(
await _serialPort.setPortParameters(
115200, UsbPort.DATABITS_8, UsbPort.STOPBITS_1, UsbPort.PARITY_NONE);

_checkCytonConnection(callback);
unawaited(_checkCytonConnection(callback));
}

Future<void> _checkCytonConnection(
Function(bool, [Exception]) callback) async {
var status = "";
var status = '';

_inputStreamSubscription = _serialPort.inputStream.listen((event) {
status += String.fromCharCodes(event);

if (isFullMessage(status)) {
_inputStreamSubscription.cancel();

if (status == CYTON_SYSTEM_UP)
if (status == CYTON_SYSTEM_UP) {
callback(true);
else {
} else {
disconnect();
callback(false, Exception(status));
}
Expand All @@ -83,7 +84,7 @@ class SerialRepository implements IAcquisitionDeviceRepository {
@override
Future<void> disconnect() async {
await _serialPort?.close();
_inputStreamSubscription?.cancel();
await _inputStreamSubscription?.cancel();
_selectedDevice = null;
_serialPort = null;
}
Expand Down
Loading