Commit e102d8f4 authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬
Browse files

Missing commits and various bugfixes.

parent 46c72662
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-05-04 04:35:02.502371","version":"1.18.0-9.0.pre.58"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-05-12 01:26:21.344576","version":"1.18.0-10.0.pre"}
\ No newline at end of file \ No newline at end of file
...@@ -6,56 +6,105 @@ import 'package:kotlin_flavor/scope_functions.dart'; ...@@ -6,56 +6,105 @@ import 'package:kotlin_flavor/scope_functions.dart';
import 'package:logair_application/enums/bluetooth_connection_status.dart'; import 'package:logair_application/enums/bluetooth_connection_status.dart';
import 'package:logair_application/handlers/data_handler.dart'; import 'package:logair_application/handlers/data_handler.dart';
import 'package:logair_application/services/wake_service.dart';
/// Serves as a wrapper class around [FlutterBlue], and helps integrate it into the application with extensions /// Serves as a wrapper class around [FlutterBlue], and helps integrate it into the application with extensions
class BTLEHandler { class BTLEHandler {
/// Static values used by the chip.
/// TODO Optionize ?
static final String bluetoothLeCc254xServiceUUID = "0000ffe0-0000-1000-8000-00805f9b34fb";
static final String bluetoothLeCc254xReadUUID = "0000ffe1-0000-1000-8000-00805f9b34fb";
/// [Singleton]() instantiation factory. /// [Singleton]() instantiation factory.
factory BTLEHandler() => _singleton; factory BTLEHandler() => _singleton;
/// Internal static [Singleton]() constructor.
BTLEHandler._internal() { BTLEHandler._internal() {
fblueInstance.setLogLevel(LogLevel.info); this._fblueInstance = FlutterBlue.instance;
//this._fblueInstance.setLogLevel(LogLevel.);
} }
/// Internal static [Singleton]() reference. /// Internal static [Singleton]() reference.
static final BTLEHandler _singleton = new BTLEHandler._internal(); static final BTLEHandler _singleton = new BTLEHandler._internal();
static bool wakeServiceActive = false; /// The referenced [BluetoothCharacteristic].
/// Should be singular, unless we plan to broadcast over channels.
BluetoothCharacteristic _characteristic; BluetoothCharacteristic _characteristic;
static Duration duration = new Duration(seconds: 1); /// The static [FlutterBlue] instance that this handler should reference.
/// Enable avoiding extraneous GC, and referencing errors.
FlutterBlue _fblueInstance;
static final String bluetoothLeCc254xServiceUUID = "0000ffe0-0000-1000-8000-00805f9b34fb"; /// @Getter for [_fblueInstance]
static final String bluetoothLeCc254xReadUUID = "0000ffe1-0000-1000-8000-00805f9b34fb"; FlutterBlue get fblueInstance => this._fblueInstance;
Timer t; /// [BluetoothConnectionStatus] that will serve as the baseline to display status to the user to.
BluetoothConnectionStatus _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
FlutterBlue fblueInstance = FlutterBlue.instance; /// @Getter to get this [BluetoothDevice]s MAC address.
String get address => this._device?.let((it) => it.id.toString());
BluetoothConnectionStatus _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING; /// The [BluetoothDevice] that this handler references.
BluetoothDevice _device;
/// Method that sets the [BluetoothDevice] to be listened to by [FlutterBlue].
void setDevice(BluetoothDevice device) => device?.let((it) => this._device = it);
/// [Stream] that tracks when the app is connected to the [BluetoothDevice] /// [Stream] that notifes when the app is connected to the [BluetoothDevice].
Stream<bool> isDeviceConnected() async* { Stream<bool> isDeviceConnected() async* {
while (true) { while (true) {
await Future.delayed(Duration(milliseconds: 750));
yield (this._device != null); yield (this._device != null);
await Future.delayed(Duration(milliseconds: 750));
}
}
/// [Stream] that notifes the [BluetoothConnectionStatus] every 2 seconds.
Stream<BluetoothConnectionStatus> getConnectionStatus() async* {
while (true) {
yield _bluetoothConnectionStatus;
await Future.delayed(Duration(seconds: 2));
} }
} }
Future<bool> setupCharacteristics() async { /// Makes the phone connect to the [BluetoothDevice] and initiate [BluetoothService] discovery.
Future<void> connect() async {
/// If the [BluetoothDevice] is connected to this handler.
if (this._device != null)
await this._asyncConnectionProcess();
}
/// Makes the smartphone disconnect from the [BluetoothDevice].
Future<dynamic> disconnect() => this._device?.let((it) async {
/// Remove notifications and references to the [BluetoothDevice] or [BluetoothCharacteristic]s.
if (_characteristic != null)
await _characteristic.setNotifyValue(false);
_characteristic = null;
_device = null;
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
return it.disconnect();
});
/// Wrapper function that tries to make the handler connect to the desired [BluetoothCharacteristic], if it exists.
Future<bool> _setupCharacteristics() async {
List<BluetoothService> services = []; List<BluetoothService> services = [];
List<BluetoothCharacteristic> characteristics = []; List<BluetoothCharacteristic> characteristics = [];
/// Termination status variable.
bool success = false; bool success = false;
if (this._device != null) { if (this._device != null) {
/// Get the first round of [BluetoothService]s and apply filter to desired Service UUID.
services = await this._device.services.first; services = await this._device.services.first;
services = services.where((s) => s.uuid.toString() == bluetoothLeCc254xServiceUUID).toList(); services = services.where((s) => s.uuid.toString() == bluetoothLeCc254xServiceUUID).toList();
/// If the [BluetoothService] exists.
if (services.length > 0) { if (services.length > 0) {
/// Get the associated [BluetoothCharacteristic]s and apply filter to desired Characteristic UUID.
characteristics = services[0].characteristics; characteristics = services[0].characteristics;
characteristics = characteristics.where((c) => c.uuid.toString() == bluetoothLeCc254xReadUUID).toList(); characteristics = characteristics.where((c) => c.uuid.toString() == bluetoothLeCc254xReadUUID).toList();
/// If the [BluetoothCharacteristic] exists.
if (characteristics.length > 0) { if (characteristics.length > 0) {
/// Set the [BluetoothCharacteristic] to notify new data.
if (!characteristics[0].isNotifying) if (!characteristics[0].isNotifying)
await characteristics[0].setNotifyValue(true); await characteristics[0].setNotifyValue(true);
_characteristic = characteristics[0]; _characteristic = characteristics[0];
...@@ -63,94 +112,48 @@ class BTLEHandler { ...@@ -63,94 +112,48 @@ class BTLEHandler {
} }
} }
} }
return success; return success;
} }
Future<bool> setupListener() async { /// Wrapper function that enable data handoff to [DataHandler];
Future<bool> _setupListener() async {
bool success = false;
/// Guard against unwanted trigger.
if (_characteristic != null) { if (_characteristic != null) {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_STREAMING; _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_STREAMING;
/// Apply a pipe transform to the values that are notified by the [BluetoothCharacteristic].
_characteristic.value.transform( _characteristic.value.transform(
new StreamTransformer.fromHandlers( new StreamTransformer.fromHandlers(
handleData: (List<int> list, EventSink<List<int>> sink) { handleData: (List<int> list, EventSink<List<int>> sink) =>
if (list.isNotEmpty) sink.add((list.isNotEmpty) ? list : []))
sink.add(list); ).listen((data) =>
else /// Handoff the data to the [DataHandler].
sink.add([]); DataHandler().addData(data)
} );
)
).listen((data) => DataHandler().addData(data));
print("RETURNS"); print("RETURNS");
return true; success = true;
} else { } else {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_STREAMING; _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
return false;
}
}
Stream<BluetoothConnectionStatus> getConnectionStatus() async* {
while (true) {
yield _bluetoothConnectionStatus;
await Future.delayed(Duration(seconds: 2));
} }
return success;
} }
/// Makes the phone connect to the [BluetoothDevice] and initiate [BluetoothService] discovery. /// Wrapper function that aggregates all of the steps to connect to a [BluetoothDevice] and stream its data.
Future<void> connect() => this._device?.let( Future<void> _asyncConnectionProcess() async {
(it) {
asyncConnection();
return;
}
);
asyncConnection() async {
await this._device.connect(); await this._device.connect();
if (Platform.isAndroid) { if (Platform.isAndroid) {
/// Android can negotiate greater Message Transmission Units.
/// 517 is the maximum defined in the BLE specification, the request will assign the largest available MTU instead.
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_SETTING_MTU; _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_SETTING_MTU;
await this._device.requestMtu(517); await this._device.requestMtu(517);
} }
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_DISCOVERING_SERVICES; /// @bug{Paul Demarco has been notified} Delay to let MTU request sink in, otherwise hindering [BluetoothService] discovery.
await Future.delayed(Duration(seconds: 1));
await this._device.discoverServices(); await this._device.discoverServices();
this._device.services.map((event) => print); await _setupCharacteristics();
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_GETTING_CHARACTERISTICS; await _setupListener();
await setupCharacteristics();
await setupListener();
} }
Future<dynamic> disconnect() => this._device?.let((it) async {
if (_characteristic != null)
await _characteristic.setNotifyValue(false);
_characteristic = null;
_device = null;
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
return it.disconnect();
});
String get address => this._device?.let((it) => it.id.toString());
BluetoothDevice _device;
setDevice(BluetoothDevice device) => device?.let((it) => this._device = it);
bool switchState() {
if (wakeServiceActive)
_end();
else
_start();
return wakeServiceActive;
}
void _start() {
WakeService().modifyWakeService(true).then((value) => print('_device will stay awake $value'));
wakeServiceActive = true;
t = new Timer.periodic(duration, (Timer t) => print("${new DateTime.now()}"));
}
void _end() {
WakeService().modifyWakeService(false).then((value) => print('_device will stay awake $value'));
wakeServiceActive = false;
t.cancel();
}
} }
\ No newline at end of file
import 'dart:async';
import 'package:logair_application/services/wake_service.dart';
class BTWakeHandler {
factory BTWakeHandler() => _singleton;
BTWakeHandler._internal();
static final BTWakeHandler _singleton = BTWakeHandler._internal();
Timer _t;
static Duration duration = new Duration(seconds: 1);
static bool wakeServiceActive = false;
bool switchState() {
if (wakeServiceActive)
_end();
else
_start();
return wakeServiceActive;
}
void _start() {
WakeService().modifyWakeService(true).then((value) => print('_device will stay awake $value'));
wakeServiceActive = true;
_t = new Timer.periodic(duration, (Timer t) => print("${new DateTime.now()}"));
}
void _end() {
WakeService().modifyWakeService(false).then((value) => print('_device will stay awake $value'));
wakeServiceActive = false;
_t.cancel();
}
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; ...@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:device_preview/device_preview.dart'; import 'package:device_preview/device_preview.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:logair_application/controllers/map_display_controller.dart';
import 'package:logair_application/handlers/data_handler.dart'; import 'package:logair_application/handlers/data_handler.dart';
import 'package:logair_application/handlers/network_handler.dart'; import 'package:logair_application/handlers/network_handler.dart';
import 'package:logair_application/handlers/position_handler.dart'; import 'package:logair_application/handlers/position_handler.dart';
...@@ -15,7 +16,10 @@ import 'package:logair_application/routes/home.dart'; ...@@ -15,7 +16,10 @@ import 'package:logair_application/routes/home.dart';
// TODO USED FOR DEBUGGING // TODO USED FOR DEBUGGING
final bool displayMode = false; final bool displayMode = false;
void main() => runApp(displayMode ? DevicePreview(child: LogAirApplication()) : LogAirApplication()); void main() {
//debugPrintGestureArenaDiagnostics = true;
runApp(displayMode ? DevicePreview(child: LogAirApplication()) : LogAirApplication());
}
class LogAirApplication extends StatelessWidget { class LogAirApplication extends StatelessWidget {
void _startHandlers() { void _startHandlers() {
...@@ -24,6 +28,7 @@ class LogAirApplication extends StatelessWidget { ...@@ -24,6 +28,7 @@ class LogAirApplication extends StatelessWidget {
DataHandler(); DataHandler();
PreferencesHandler(); PreferencesHandler();
PositionHandler(); PositionHandler();
MapDisplayController();
} }
static const String _title = 'LogAir Connector'; static const String _title = 'LogAir Connector';
......
...@@ -22,6 +22,7 @@ class HomeView extends StatelessWidget { ...@@ -22,6 +22,7 @@ class HomeView extends StatelessWidget {
Expanded( Expanded(
flex: 1, flex: 1,
child: Listener( child: Listener(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onPointerDown: (_) => null, onPointerDown: (_) => null,
child: GestureDetector( child: GestureDetector(
......
...@@ -43,6 +43,7 @@ class _BluetoothButtonState extends State<BluetoothButton> { ...@@ -43,6 +43,7 @@ class _BluetoothButtonState extends State<BluetoothButton> {
page: BluetoothDialog(), page: BluetoothDialog(),
), ),
); );
return true;
} else { } else {
BTLEHandler().disconnect(); BTLEHandler().disconnect();
print('Tap off'); print('Tap off');
......
...@@ -2,7 +2,7 @@ name: logair_application ...@@ -2,7 +2,7 @@ name: logair_application
description: An application to link LogAir devices to the LogAir service, and provide description: An application to link LogAir devices to the LogAir service, and provide
feedback to the user. feedback to the user.
version: 0.0.2 version: 0.0.4
environment: environment:
sdk: ">=2.6.0 <3.0.0" sdk: ">=2.6.0 <3.0.0"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment