Skip to content

Commit

Permalink
Added licence
Browse files Browse the repository at this point in the history
  • Loading branch information
Reedyuk committed Sep 4, 2019
1 parent 7ad954e commit 69667f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
19 changes: 19 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 Andrew Reed. http://andrewreed.co.uk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
16 changes: 14 additions & 2 deletions examples/ios/Blue-Falcon/ViewModels/DeviceViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ class DeviceViewModel: NSObject, BlueFalconDelegate, ObservableObject {
}

func connect() {
AppDelegate.instance.blueFalcon.connect(bluetoothPeripheral: device)
AppDelegate.instance.blueFalcon.stopScanning()
if self.device.state != .connecting {
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: {
if self.device.state != .connected {
AppDelegate.instance.blueFalcon.disconnect(bluetoothPeripheral: self.device)
}
})
AppDelegate.instance.blueFalcon.connect(bluetoothPeripheral: device)
}
}

private func setupServices(bluetoothPeripheral: CBPeripheral) {
Expand All @@ -50,6 +58,8 @@ class DeviceViewModel: NSObject, BlueFalconDelegate, ObservableObject {
!services.isEmpty
else { return }
print("didDiscoverServices \(services)")
//consider having a delay on when to update the services and their characteristics becuase this is
//called every time we get a new characteristic.
self.services = services
self.deviceServiceCellViewModels = services.map { service -> DeviceServiceCellViewModel in
DeviceServiceCellViewModel(id: service.uuid, service: service)
Expand All @@ -65,7 +75,9 @@ class DeviceViewModel: NSObject, BlueFalconDelegate, ObservableObject {
AppDelegate.instance.connectedDevices.append(bluetoothPeripheral)
}

func didDisconnect(bluetoothPeripheral: CBPeripheral) {}
func didDisconnect(bluetoothPeripheral: CBPeripheral) {
state = .disconnected
}

func didDiscoverServices(bluetoothPeripheral: CBPeripheral) {
// setupServices(bluetoothPeripheral: bluetoothPeripheral)
Expand Down
9 changes: 5 additions & 4 deletions examples/ios/Blue-Falcon/Views/DevicesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ struct DevicesView : View {
}
.navigationBarTitle(Text("Blue Falcon Devices"))
}
}.onAppear {
self.scan()
}.onDisappear {
self.viewModel.stopScanning()
.onAppear {
self.scan()
}.onDisappear {
self.viewModel.stopScanning()
}
}
.colorScheme(.dark)
}
Expand Down
8 changes: 5 additions & 3 deletions library/src/iosMain/kotlin/dev/bluefalcon/BlueFalcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ actual class BlueFalcon {
advertisementData: Map<Any?, *>,
RSSI: NSNumber
) {
log("Discovered device ${didDiscoverPeripheral.name}")
delegates.forEach {
it.didDiscoverDevice(didDiscoverPeripheral)
if (isScanning) {
log("Discovered device ${didDiscoverPeripheral.name}")
delegates.forEach {
it.didDiscoverDevice(didDiscoverPeripheral)
}
}
}

Expand Down

0 comments on commit 69667f1

Please sign in to comment.