Skip to content
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

Ble support for iOS #5

Draft
wants to merge 68 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e284550
Build from source (#1)
Ben1980 Jan 29, 2024
306fd94
Update dive_computer_ffi.dart
Ben1980 Jan 29, 2024
98ec792
Extracting hardware interfaces into own utility class
Ben1980 Jan 29, 2024
21e085a
usb.h and .c added. Bindings extended
Ben1980 Jan 29, 2024
3782658
Update dive_computer_ffi_bindings_generated.dart
Ben1980 Jan 29, 2024
41ca423
usbhid added
Ben1980 Jan 29, 2024
b60e629
Update CMakeLists.txt
Ben1980 Jan 29, 2024
220a724
backup
Ben1980 Jan 29, 2024
41a1ed6
Merge branch 'develop' into usb-support
Sese-Schneider Jan 29, 2024
1434aef
Merge branch 'usb-support' of https://github.com/Ben1980/dive_compute…
Ben1980 Jan 30, 2024
9dd3c6e
Update dive_computer_interfaces.dart
Ben1980 Jan 30, 2024
3f93792
adding defines
Ben1980 Feb 1, 2024
553e091
hidapi submodule added
Ben1980 Feb 2, 2024
08db24c
Update CMakeLists.txt
Ben1980 Feb 2, 2024
39e9c46
macos is creating usbhid iterator
Ben1980 Feb 2, 2024
a3ba3a1
libusb added as submodule
Ben1980 Feb 6, 2024
5aea268
Update pubspec.yaml
Ben1980 Feb 6, 2024
b3d22b9
getting macos compiling
Ben1980 Feb 6, 2024
9094209
ios classes added
Ben1980 Feb 12, 2024
f548774
ble added to libdive config
Ben1980 Feb 12, 2024
394519f
bluez submodule added
Ben1980 Feb 12, 2024
b3b46d3
ble
Ben1980 Feb 12, 2024
02adc84
Create bluez
Ben1980 Feb 12, 2024
102980d
Merge branch 'develop' of https://github.com/DiveNote/dive_computer i…
Ben1980 Feb 12, 2024
4ff9362
cleanup
Ben1980 Feb 14, 2024
4a6a9b4
Update README.md
Ben1980 Feb 14, 2024
bf56213
Update config.h
Ben1980 Feb 14, 2024
bb8fd97
Update hid.c
Ben1980 Feb 14, 2024
d9a905a
Update Podfile.lock
Ben1980 Feb 14, 2024
d652784
fixing xcode project settings
Ben1980 Feb 14, 2024
72315eb
adding USB and USBHID
Ben1980 Feb 14, 2024
14195eb
small cleanup
Ben1980 Feb 14, 2024
e9190bd
flutter BLE added
Ben1980 Feb 14, 2024
70706d1
ios setup
Ben1980 Feb 14, 2024
17aedff
adding sources
Ben1980 Feb 14, 2024
1181727
config moved
Ben1980 Feb 14, 2024
cb5a458
Merge branch 'usb-support' into ble-support
Ben1980 Feb 14, 2024
650192e
c files fixed
Ben1980 Feb 14, 2024
f80a6c8
serial removed from ios
Ben1980 Feb 14, 2024
82bd894
ble ffi binding added
Ben1980 Feb 14, 2024
d9bdc39
Create bluetooth.c
Ben1980 Feb 14, 2024
697b73b
some small fixes
Ben1980 Feb 15, 2024
6bf838c
formating fixed
Ben1980 Feb 15, 2024
6c03a09
Merge branch 'usb-support' into ble-support
Ben1980 Feb 15, 2024
45ce139
cleanup
Ben1980 Feb 15, 2024
6d225eb
adding example for mobile
Ben1980 Feb 15, 2024
6f952b2
Update bluetooth_provider.dart
Ben1980 Feb 16, 2024
ca64250
Update main.dart
Ben1980 Feb 16, 2024
25b2108
reverted changes
Ben1980 Feb 20, 2024
fa1590b
Merge branch 'usb-support' into ble-support
Ben1980 Feb 20, 2024
c8359cd
updates
Ben1980 Feb 28, 2024
a8f4f72
adding flutter_blue_plus
Ben1980 Feb 28, 2024
031ca60
Adding custom.h for custom BLE
Ben1980 Feb 28, 2024
e0b4b97
Create custom.c
Ben1980 Feb 28, 2024
9920d80
Update pubspec.lock
Ben1980 Feb 28, 2024
c2dbb65
fixing example
Ben1980 Feb 28, 2024
6d12c3a
adding ble repro of subsurface
Ben1980 Feb 28, 2024
265e56b
Merge branch 'develop' of https://github.com/DiveNote/dive_computer i…
Ben1980 Feb 28, 2024
2f026a1
Merge branch 'develop' into ble-support
Ben1980 Feb 28, 2024
fcae7a5
Update pubspec.lock
Ben1980 Feb 28, 2024
f70aabb
Delete bluez
Ben1980 Feb 28, 2024
3c23f8a
Update bluetooth_provider.dart
Ben1980 Feb 28, 2024
1d77189
Update pubspec.lock
Ben1980 Feb 28, 2024
e19bc75
cleanup
Ben1980 Feb 28, 2024
c90fc77
Adding BluetoothCache singleton
Ben1980 Feb 29, 2024
3196263
baqckup
Ben1980 Mar 5, 2024
d058f0b
FBP should be used within the plugin, not in the example itself
Ben1980 Mar 5, 2024
c385b2b
Trying to get ble devices via isolate
Ben1980 Mar 7, 2024
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
10 changes: 8 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ PODS:
- dive_computer (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_blue_plus (0.0.1):
- Flutter

DEPENDENCIES:
- dive_computer (from `.symlinks/plugins/dive_computer/ios`)
- Flutter (from `Flutter`)
- flutter_blue_plus (from `.symlinks/plugins/flutter_blue_plus/ios`)

EXTERNAL SOURCES:
dive_computer:
:path: ".symlinks/plugins/dive_computer/ios"
Flutter:
:path: Flutter
flutter_blue_plus:
:path: ".symlinks/plugins/flutter_blue_plus/ios"

SPEC CHECKSUMS:
dive_computer: b7f216c7462ea4d565c0cd0d23395df3309bbe56
dive_computer: b5812e10488f2173633747360efad9e8ed9f2dee
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_blue_plus: 4837da7d00cf5d441fdd6635b3a57f936778ea96

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
4784EFBF2FF99F6D74E8C8ED /* [CP] Embed Pods Frameworks */,
7DE1D0F21F9C4C7940F5E24A /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -216,7 +216,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down Expand Up @@ -308,7 +308,7 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
4784EFBF2FF99F6D74E8C8ED /* [CP] Embed Pods Frameworks */ = {
7DE1D0F21F9C4C7940F5E24A /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 10 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app always needs Bluetooth to function</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth Peripheral to function</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app always needs location and when in use to function</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app always needs location to function</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs location when in use to function</string>
</dict>
</plist>
108 changes: 108 additions & 0 deletions example/lib/bluetooth_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';

class BluetoothProvider with ChangeNotifier {
BluetoothAdapterState _adapterState = BluetoothAdapterState.unknown;
late StreamSubscription<BluetoothAdapterState> _adapterStateStateSubscription;
late StreamSubscription<List<ScanResult>> _scanResultsSubscription;
late StreamSubscription<bool> _isScanningSubscription;
List<BluetoothDevice> _systemDevices = [];
List<ScanResult> _scanResults = [];
bool _isScanning = false;

BluetoothProvider() {
FlutterBluePlus.setLogLevel(LogLevel.none, color: false);
_initBLE();
}

@override
void dispose() {
_scanResultsSubscription.cancel();
_isScanningSubscription.cancel();
_adapterStateStateSubscription.cancel();
super.dispose();
}

void _initBLE() async {
if (await FlutterBluePlus.isSupported == false) {
print("Bluetooth not supported by this device");
return;
}

_adapterStateStateSubscription =
FlutterBluePlus.adapterState.listen((state) {
_adapterState = state;

if (state == BluetoothAdapterState.on) {
FlutterBluePlus.startScan(timeout: const Duration(seconds: 15));

try {
FlutterBluePlus.systemDevices.then((systemDevices) {
if (systemDevices.isNotEmpty) {
_systemDevices = systemDevices;
notifyListeners();
}
});
} catch (e, s) {
print('Error while getting system devices: $e, $s');
}
} else {
print('Bluetooth adapter is ${state.toString().split('.')[1]}');
}
}, onError: (e, s) {
print('Error while listening to adapter state stream: $e, $s');
});

if (Platform.isAndroid) {
await FlutterBluePlus.turnOn();
}

_scanResultsSubscription = FlutterBluePlus.scanResults.listen((results) {
if (results.isNotEmpty) {
_scanResults = results;
notifyListeners();
}
}, onError: (e, s) {
print('Error while listening to scan results stream: $e, $s');
});

_isScanningSubscription = FlutterBluePlus.isScanning.listen((state) {
_isScanning = state;
notifyListeners();
}, onError: (e, s) {
print('Error while listening to isScanning stream: $e, $s');
});
}

Future<void> scanForDevices() async {
if (_adapterState == BluetoothAdapterState.on) {
print('Scanning for devices...');
try {
FlutterBluePlus.systemDevices.then((systemDevices) {
if (systemDevices.isNotEmpty) {
_systemDevices = systemDevices;
notifyListeners();
}
});
} catch (e, s) {
print('Error while getting system devices: $e, $s');
}

if (_isScanning == false) {
FlutterBluePlus.startScan(timeout: const Duration(seconds: 15));
}
}

return Future.delayed(const Duration(milliseconds: 500));
}

List<BluetoothDevice> get systemDevices =>
_systemDevices.where((device) => device.platformName.isNotEmpty).toList();

List<ScanResult> get scanResults => _scanResults
.where((device) => device.device.platformName.isNotEmpty)
.toList();
}
Loading
Loading