Skip to content

Fix #29 #28 #11 #30

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.pycampers.rx_ble'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pycampers.rx_ble

import com.pycampers.plugin_scaffold.StreamSink
import com.pycampers.plugin_scaffold.MainThreadStreamSink
import com.pycampers.plugin_scaffold.trySendThrowable
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.Result
Expand All @@ -9,11 +9,11 @@ interface ConnectInterface {
fun disconnect(call: MethodCall, result: Result)
fun getConnectionState(call: MethodCall, result: Result)
fun connectOnCancel(id: Int, args: Any?)
fun connectOnListen(id: Int, args: Any?, sink: StreamSink)
fun connectOnListen(id: Int, args: Any?, sink: MainThreadStreamSink)
}

class ConnectMethods : ConnectInterface {
override fun connectOnListen(id: Int, args: Any?, sink: StreamSink) {
override fun connectOnListen(id: Int, args: Any?, sink: MainThreadStreamSink) {
val map = args as Map<*, *>
val deviceId = map["deviceId"] as String
val waitForDevice = map["waitForDevice"] as Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pycampers.rx_ble

import com.pycampers.plugin_scaffold.StreamSink
import com.pycampers.plugin_scaffold.MainThreadStreamSink
import com.pycampers.plugin_scaffold.trySend
import com.pycampers.plugin_scaffold.trySendThrowable
import io.flutter.plugin.common.MethodCall
Expand All @@ -14,7 +14,7 @@ interface ReadWriteInterface {
fun readChar(call: MethodCall, result: Result)
fun writeChar(call: MethodCall, result: Result)
fun requestMtu(call: MethodCall, result: Result)
fun observeCharOnListen(id: Int, args: Any?, sink: StreamSink)
fun observeCharOnListen(id: Int, args: Any?, sink: MainThreadStreamSink)
fun observeCharOnCancel(id: Int, args: Any?)
}

Expand Down Expand Up @@ -73,7 +73,7 @@ class ReadWriteMethods : ReadWriteInterface {
sendSingle(connection.requestMtu(value), result)
}

override fun observeCharOnListen(id: Int, args: Any?, sink: StreamSink) {
override fun observeCharOnListen(id: Int, args: Any?, sink: MainThreadStreamSink) {
val map = args as Map<*, *>
val deviceId = map["deviceId"] as String
val uuid = UUID.fromString(map["uuid"] as String)
Expand Down
6 changes: 3 additions & 3 deletions android/src/main/kotlin/com/pycampers/rx_ble/ScanMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.ParcelUuid;
import com.polidea.rxandroidble2.RxBleClient
import com.polidea.rxandroidble2.scan.ScanFilter
import com.polidea.rxandroidble2.scan.ScanSettings
import com.pycampers.plugin_scaffold.StreamSink
import com.pycampers.plugin_scaffold.MainThreadStreamSink
import com.pycampers.plugin_scaffold.trySend
import com.pycampers.plugin_scaffold.trySendThrowable
import dumpScanResult
Expand All @@ -15,7 +15,7 @@ import io.reactivex.disposables.Disposable
interface ScanInterface {
fun stopScan(call: MethodCall, result: MethodChannel.Result)
fun scanOnCancel(id: Int, args: Any?)
fun scanOnListen(id: Int, args: Any?, sink: StreamSink)
fun scanOnListen(id: Int, args: Any?, sink: MainThreadStreamSink)
}

class ScanMethods(val bleClient: RxBleClient) : ScanInterface {
Expand All @@ -26,7 +26,7 @@ class ScanMethods(val bleClient: RxBleClient) : ScanInterface {
disposable = null
}

override fun scanOnListen(id: Int, args: Any?, sink: StreamSink) {
override fun scanOnListen(id: Int, args: Any?, sink: MainThreadStreamSink) {
val map = args as Map<*, *>
val scanSettings = ScanSettings.Builder().setScanMode(map["scanMode"] as Int - 1).build()

Expand Down
74 changes: 74 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
end

target 'Runner' do
use_frameworks!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
end
}

# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
73 changes: 61 additions & 12 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "2.4.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
charcode:
dependency: transitive
description:
Expand All @@ -29,6 +43,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -39,55 +67,69 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
plugin_scaffold:
dependency: transitive
description:
name: plugin_scaffold
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.2.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.0.5"
rx_ble:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "0.5.5"
version: "0.6.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -120,7 +162,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
Expand All @@ -134,7 +176,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.11"
typed_data:
dependency: transitive
description:
Expand All @@ -149,5 +191,12 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.4.0 <3.0.0"
2 changes: 1 addition & 1 deletion ios/Classes/ReadWriteMethods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ReadWriteMethods: NSObject {
let peripheral = try getPeripheral(deviceId)
let char = try getCharFromCache(deviceId, uuid)

sendSingle(peripheral.writeValue(value.data, for: char, type: .withResponse), result) {
sendSingle(peripheral.writeValue(value.data, for: char, type: .withoutResponse, canSendWriteWithoutResponseCheckEnabled: true), result) {
FlutterStandardTypedData(bytes: $0.value ?? Data())
}
}
Expand Down
Loading