Commit 846b6e67 authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

BTHandler handoff to DataHandler, disconnect needs tweaking.

parent f8b18fb1
{"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.6.3+1\\\\","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.6.3+1\\\\","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-02-25 15:01:23.953288","version":"1.14.6"}
\ No newline at end of file
{"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.6.3+1\\\\","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.6.3+1\\\\","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-02-25 22:17:56.836840","version":"1.15.4-pre.158"}
\ No newline at end of file
......@@ -18,11 +18,11 @@ Dates are in the sensible `DD/MM/YYYY` format.
- Prefs stored from one session to the next.
- Language switch possible (not just locale).
- Add | (UI) Leaflet (flutter_map) | just the map (6h) + (overlay data || )
- Bluetooth (recents list.s)
- Add | (Func) Cache file for data | 2+3-4h
- Add | (BS) Location (expansion needed) | ~
- Add | (BS) Bluetooth LE (expansion needed) | 4-8h (flutter_blue )
- Add | (BS) Background service framework () | 2-6h (sticky notification system + )
- allow people to set their own service / characteristic UUID
- Bluetooth (recents list.s) add to shared prefs on connect, keep max 10.
## Unreleased
......@@ -30,9 +30,16 @@ Dates are in the sensible `DD/MM/YYYY` format.
### [0.0.2] Summary
Made the application be able to connect to LogAir's devices, in a brute fashion. App can read data from device and transfer to `DataHandler` instance.
### [0.0.2] Added
- Next : Disconnect from BTLE device before allowing reconnection.
- (OS) Initial `DataHandler` implementation.
- (OS) Read data pushed by device.
- (Req) `test` and `flutter_test` to dev dependencies.
- (OS:Android) Background Service.
- (OS) Get `BluetoothService` / `BluetoothCharacteristic` by default values
- (OS) Disconnect from BTLE device before allowing reconnection.
- (UI) `BluetoothButton` : Will check BT availability, BT is on, BT is connected.
- (OS) `SharedPreferences` storage access and reference storage
- (OS) Connecting to BTLE devices
......
......@@ -35,11 +35,13 @@ User should be able to set service/characteristic UUID manually on fail.
Also also, the UI and service elements of battery, bluetooth or web should be distinct.
Check on whether or not a listener can be affixed to whatever the platform is doing, consider the Kotlin/Swift equivalents to `TimerTask's`, but in the background.
`@Deprecated` Check on whether or not a listener can be affixed to whatever the platform is doing, consider the Kotlin/Swift equivalents to `TimerTask's`, but in the background.
Bluetooth should have at least a few tasks (discovery -> pump all MAC's and display), (connect <- ) (read ->). Event Streams ?
`@Deprecated` Bluetooth should have at least a few tasks (discovery -> pump all MAC's and display), (connect <- ) (read ->). Event Streams ?
Other option for making the service run in background: make the platform side tick once per second and notify the dart framework, may need to use a sticky notification as well.
`@Deprecated` Other option for making the service run in background: make the platform side tick once per second and notify the dart framework, may need to use a sticky notification as well.
Use instances of Stream, gotten from the betterment of my understanding of streams.
### [0.0.2] iOS
......@@ -57,7 +59,7 @@ TestFlight is not a "viable" option, only allows 10000 beta testers and required
Will require discussion obviously.
Idea is to use a enterprise app profile and to automate the install via batch script / iTunes.
Current idea is to use a enterprise app profile and to automate the install via batch script / iTunes.
### [0.0.2] Resources
......
......@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:kotlin_flavor/scope_functions.dart';
import 'package:logair_application/handlers/data_handler.dart';
import 'package:logair_application/services/wake_service.dart';
......@@ -11,6 +12,11 @@ class BTLEHandler {
/// [Singleton]() instantiation factory.
factory BTLEHandler() => _singleton;
BTLEHandler._internal() {
fblueInstance.setLogLevel(LogLevel.info);
}
/// Internal static [Singleton]() reference.
static final BTLEHandler _singleton = new BTLEHandler._internal();
......@@ -30,10 +36,6 @@ class BTLEHandler {
FlutterBlue fblueInstance = FlutterBlue.instance;
BTLEHandler._internal() {
fblueInstance.setLogLevel(LogLevel.info);
}
/// [Stream] that tracks when the app is connected to the [BluetoothDevice]
Stream<bool> isDeviceConnected() async* {
while (true) {
......@@ -72,27 +74,16 @@ class BTLEHandler {
handleData: (List<int> list, EventSink<List<int>> sink) {
if (list.isNotEmpty)
sink.add(list);
else
sink.add([]);
}
)
).listen((event) {
_partialData += event;
});
).listen((data) => DataHandler().addData(data));
return true;
} else
return false;
}
List<int> _partialData = [];
Stream<List<int>> getData() async* {
while(true) {
List<int> temp = _partialData;
_partialData = [];
yield temp;
await Future.delayed(Duration(milliseconds: 500));
}
}
/// Makes the phone connect to the [BluetoothDevice] and initiate [BluetoothService] discovery.
Future<void> connect() => this._device?.let(
(it) {
......@@ -110,9 +101,11 @@ class BTLEHandler {
await setupListener();
}
Future<dynamic> disconnect() => this._device?.let((it) {
_device = null;
Future<dynamic> disconnect() => this._device?.let((it) async {
if (_characteristic != null)
await _characteristic.setNotifyValue(false);
_characteristic = null;
_device = null;
return it.disconnect();
});
......
class DataHandler {
factory DataHandler() => _singleton;
DataHandler._internal();
static final DataHandler _singleton = new DataHandler._internal();
List<int> _data = [];
List<List<int>> _sortedData = [];
addData(List<int> data) {
_data.addAll(data);
int index = _data.indexWhere((e) => e == 13);
if (index >= 0 && _data.length >= index && _data[index + 1] == 10) {
_sortedData.add(_data.getRange(0, index).where((e) => e != 10).toList());
_data.removeRange(0, index + 1);
}
}
doPrint() => _sortedData.map((x) => String.fromCharCodes(x)).forEach(print);
Stream<List<int>> getLatestData() async* {
while(true) {
yield _sortedData.last;
await Future.delayed(Duration(milliseconds: 500));
}
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ class _BluetoothButtonState extends State<BluetoothButton> {
_bluetoothConnected = true;
return value;
}));
} else {
BTLEHandler().disconnect();
print('Tap off');
......
......@@ -2,8 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:logair_application/ui/components/slim_list_tile.dart';
class BTLEScanTile extends StatelessWidget {
/// The [ScanResult] on which the information is based.
final ScanResult result;
......
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
......@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:logair_application/handlers/bluetooth_le_handler.dart';
import 'package:logair_application/handlers/data_handler.dart';
import 'package:logair_application/ui/carousel_card.dart';
import 'package:logair_application/services/battery_service.dart';
import 'package:logair_application/ui/components/bluetooth_button.dart';
......@@ -27,9 +28,7 @@ class DataWidget extends StatelessWidget {
),
Text("Data", style: TextStyle(fontFamily: "Consolas", fontSize: 22)),
RaisedButton(
onPressed: () => {
BTLEHandler().switchState()
},
onPressed: () => BTLEHandler().switchState(),
child: Text('Toggle BTLE Service'),
),
BluetoothButton(),
......@@ -45,17 +44,24 @@ class DataWidget extends StatelessWidget {
},
),
StreamBuilder<List<int>>(
stream: BTLEHandler().getData(),
stream: DataHandler().getLatestData(),
initialData: [],
builder: (context, snapshot) {
List<int> data = snapshot.data;
if (data != null && data.length > 0) {
return Text(String.fromCharCodes(data));
return Text(
String.fromCharCodes(data),
textAlign: TextAlign.center,
);
} else
return Text("No data streaming");
},
)
),
RaisedButton(
onPressed: () => DataHandler().doPrint(),
child: Text('Print Data Set'),
),
]
),
);
......
......@@ -3,6 +3,7 @@ import 'package:logair_application/localization/localization.dart';
import 'package:permission_handler/permission_handler.dart';
// TODO INTERNATIONALIZE
// TODO Keep ? is it necessary ?
class PermissionDialog extends StatelessWidget {
final String title;
final String dialogText;
......
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