Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 2 deletions mobile/lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:polydodo/src/presentation/bluetooth_route/bluetoothSelector_route.dart';
import 'package:polydodo/src/presentation/wallets/wallets_route.dart';

import 'locator.dart';
import 'theme.dart';
Expand All @@ -21,7 +20,6 @@ class App extends StatelessWidget {
theme: theme,
initialRoute: BluetoothSelectorRoute.name,
routes: {
WalletsRoute.name: (context) => WalletsRoute(),
BluetoothSelectorRoute.name: (context) => BluetoothSelectorRoute(),
},
),
Expand Down
16 changes: 9 additions & 7 deletions mobile/lib/src/application/device/device_selector_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ class DeviceSelectorCubit extends Cubit<DeviceState> {
}
}

void connect(AcquisitionDevice device) async {
Future<void> connect(AcquisitionDevice device) async {
emit(DeviceConnectionInProgress());

_deviceRepository.connect(device).then(
(value) => {
_acquisitionDeviceStream.cancel(),
emit(DeviceConnectionSuccess())
},
onError: (e) => {emit(DeviceConnectionFailure(e)), resetSearch()});
try {
await _deviceRepository.connect(device);
_acquisitionDeviceStream.cancel();
emit(DeviceConnectionSuccess());
} catch (e) {
emit(DeviceConnectionFailure(e));
resetSearch();
}
}

void resetSearch() {
Expand Down
7 changes: 3 additions & 4 deletions mobile/lib/src/application/eeg_data/data_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class DataCubit extends Cubit<DataState> {
DataCubit(this._deviceRepository, this._eegDataRepository)
: super(DataStateInitial());

void startStreaming() {
Future<void> startStreaming() async {
emit(DataStateRecording());
_deviceRepository
.startDataStream()
.then((stream) => _eegDataRepository.createRecordingFromStream(stream));
_eegDataRepository
.createRecordingFromStream(await _deviceRepository.startDataStream());
}

void stopStreaming() {
Expand Down
63 changes: 0 additions & 63 deletions mobile/lib/src/application/wallets/wallets_cubit.dart

This file was deleted.

25 changes: 0 additions & 25 deletions mobile/lib/src/application/wallets/wallets_state.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:equatable/equatable.dart';
import 'package:polydodo/src/domain/entity.dart';

import '../unique_id.dart';

class AcquisitionDevice extends Entity {
final String name;

Expand Down
11 changes: 5 additions & 6 deletions mobile/lib/src/domain/eeg_data/eeg_data.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// EEGData can be extended later to add our metrics
import '../unique_id.dart';
import 'package:polydodo/src/domain/entity.dart';

class EEGData {
UniqueId id;
class EEGData extends Entity {
List<List> _values;
int sampleCounter = 0;

EEGData(this.id, this._values)
: assert(id != null),
assert(_values != null);
EEGData(id, this._values)
: assert(_values != null),
super(id);

List<List> get values => _values;

Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/src/domain/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:polydodo/src/domain/unique_id.dart';
abstract class Entity extends Equatable {
final UniqueId id;

Entity(this.id);
Entity(this.id) : assert(id != null);

@override
List<Object> get props => [id];
Expand Down
1 change: 0 additions & 1 deletion mobile/lib/src/domain/wallet/constants.dart

This file was deleted.

6 changes: 0 additions & 6 deletions mobile/lib/src/domain/wallet/i_wallet_repository.dart

This file was deleted.

57 changes: 0 additions & 57 deletions mobile/lib/src/domain/wallet/money.dart

This file was deleted.

32 changes: 0 additions & 32 deletions mobile/lib/src/domain/wallet/owner.dart

This file was deleted.

35 changes: 0 additions & 35 deletions mobile/lib/src/domain/wallet/wallet.dart

This file was deleted.

50 changes: 23 additions & 27 deletions mobile/lib/src/infrastructure/bluetooth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,46 +76,42 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
flutterBlue.stopScan();

try {
await _selectedDevice
.connect()
.then((value) => findRelevantCharacteristics())
.timeout(Duration(seconds: 6),
onTimeout: () =>
{disconnect(), throw Exception("Connection Timed out")});
await _selectedDevice.connect().timeout(Duration(seconds: 6),
onTimeout: () =>
{disconnect(), throw Exception("Connection Timed out")});

await findRelevantCharacteristics();
} catch (e) {
if (e is PlatformException) {
if (e.code != "already_connected") throw Exception(e.details);
} else
throw e;
}

return;
}

void disconnect() async {
Future<void> disconnect() async {
if (_selectedDevice != null) {
await _selectedDevice.disconnect();
_selectedDevice = null;
}
}

void findRelevantCharacteristics() {
_selectedDevice.discoverServices().then((services) => {
for (BluetoothCharacteristic characteristic in (services.where(
(service) => service.uuid.toString().contains(BLE_SERVICE)))
.first
.characteristics)
{
if (characteristic.uuid.toString().contains(BLE_RECEIVE))
{_receiveCharacteristic = characteristic}
else if (characteristic.uuid.toString().contains(BLE_SEND))
{_sendCharacteristic = characteristic}
},
if (_receiveCharacteristic == null)
throw Exception('Device is missing receive Characteristic'),
if (_sendCharacteristic == null)
throw Exception('Device is missing send Characteristic')
});
Future<void> findRelevantCharacteristics() async {
var characteristics = (await _selectedDevice.discoverServices())
.firstWhere((service) => service.uuid.toString().contains(BLE_SERVICE))
.characteristics;
for (BluetoothCharacteristic characteristic in characteristics) {
if (characteristic.uuid.toString().contains(BLE_RECEIVE)) {
_receiveCharacteristic = characteristic;
} else if (characteristic.uuid.toString().contains(BLE_SEND)) {
_sendCharacteristic = characteristic;
}
}

if (_receiveCharacteristic == null)
throw Exception('Device is missing receive Characteristic');
if (_sendCharacteristic == null)
throw Exception('Device is missing send Characteristic');
}

Future<Stream<List<int>>> startDataStream() async {
Expand All @@ -125,7 +121,7 @@ class BluetoothRepository implements IAcquisitionDeviceRepository {
return _receiveCharacteristic.value;
}

void stopDataStream() async {
Future<void> stopDataStream() async {
await _receiveCharacteristic.setNotifyValue(false);
await _sendCharacteristic.write(stopStreamChar.codeUnits);
}
Expand Down
Loading