Skip to content

Commit 8b41fad

Browse files
Fix regression after upgrading NRF 2.2.4 (#10)
* Fix regression after update NRF 2.2.4 * Bump library version * Update changelog
1 parent 652df2d commit 8b41fad

File tree

7 files changed

+135
-122
lines changed

7 files changed

+135
-122
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
Version 0.1.0
1+
# CHANGELOG
2+
3+
## Version 0.2.1
4+
5+
- Fix regression bugs for version 0.2.0
6+
7+
## Version 0.2.0
8+
9+
- Update NRF BLE 2.2.4
10+
- Update NRF Scanner 1.5.0
11+
12+
## Version 0.1.3
13+
14+
- Update Arrow 0.13.2
15+
16+
## Version 0.1.0
217

318
Initial release
419

beckon/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
targetSdkVersion 30
1313
buildToolsVersion = "30.0.2"
1414
versionCode 1
15-
versionName "0.1.2"
15+
versionName "0.2.1"
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1818

beckon/src/main/java/com/technocreatives/beckon/BeckonClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface BeckonClient {
4646
fun disconnectAllConnectedButNotSavedDevices(): Completable
4747

4848
/**
49-
* Search for all connected devices in the systems which satisfies ScannerSetting
49+
* Search for all currently connected devices in the systems which satisfies ScannerSetting
5050
* If setting.useFilter == True, this function will ignore all connected and saved devices in Beckon
5151
*/
5252
fun search(setting: ScannerSetting, descriptor: Descriptor): Observable<Either<ConnectionError, BeckonDevice>>

beckon/src/main/java/com/technocreatives/beckon/extension/BeckonClientEx.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fun BeckonClient.scanAndConnect(
5656

5757
val searchStream =
5858
search(conditions, setting, descriptor).map { it.mapLeft { BeckonException(it) } }
59+
5960
val scanStream = scan(conditions, setting)
6061
.flatMapSingleEither { safeConnect(it, descriptor) }
6162

beckon/src/main/java/com/technocreatives/beckon/extension/BeckonDeviceEx.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.technocreatives.beckon.State
1111
import com.technocreatives.beckon.checkNotifyList
1212
import io.reactivex.Completable
1313
import io.reactivex.Observable
14-
import io.reactivex.functions.BiFunction
1514
import java.util.UUID
1615

1716
data class BeckonState<State>(
@@ -29,7 +28,7 @@ fun BeckonDevice.deviceStates(): Observable<BeckonState<State>> {
2928
return Observable.combineLatest(
3029
states(),
3130
connectionStates(),
32-
BiFunction<State, ConnectionState, BeckonState<State>> { t1, t2 ->
31+
{ t1, t2 ->
3332
BeckonState(metadata(), t2, t1)
3433
}
3534
)

beckon/src/main/java/com/technocreatives/beckon/internal/BeckonBleManager.kt

Lines changed: 114 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -133,123 +133,12 @@ internal class BeckonBleManager(
133133
}
134134
}
135135

136-
private val gattCallback = object : BleManagerGattCallback() {
137-
138-
override fun initialize() {
139-
Timber.d("initialize")
140-
if (bluetoothGatt != null) {
141-
val services = bluetoothGatt!!.services.map { it.uuid }
142-
val characteristics = allCharacteristics(bluetoothGatt!!)
143-
val detail = DeviceDetail(services, characteristics)
144-
145-
// TODO Fix disposable
146-
val disposable =
147-
Observable.just(Unit).delay(1600, TimeUnit.MILLISECONDS).flatMapCompletable {
148-
subscribeBla(descriptor.subscribes, detail)
149-
}
150-
.andThen(readBla(descriptor.reads, detail).ignoreElements())
151-
.subscribe(
152-
{
153-
devicesSubject.onSuccess(detail.right())
154-
},
155-
{
156-
devicesSubject.onSuccess(
157-
ConnectionError.GeneralError(
158-
device.address,
159-
it
160-
).left()
161-
)
162-
}
163-
)
164-
} else {
165-
devicesSubject.onSuccess(ConnectionError.BluetoothGattNull(device.address).left())
166-
}
167-
}
168-
169-
override fun onDeviceDisconnected() {
170-
Timber.d("onDeviceDisconnected gattCallback")
171-
}
172-
173-
override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean {
174-
Timber.d("isRequiredServiceSupported $gatt")
175-
val services = gatt.services.map { it.uuid }
176-
Timber.d("All discovered services $services")
177-
bluetoothGatt = gatt
178-
179-
return true
180-
}
181-
182-
private fun allCharacteristics(gatt: BluetoothGatt): List<CharacteristicSuccess> {
183-
return gatt.services.flatMap { allCharacteristics(it) }
184-
}
185-
186-
private fun allCharacteristics(service: BluetoothGattService): List<CharacteristicSuccess> {
187-
return service.characteristics.flatMap {
188-
allCharacteristics(service, it)
189-
}
190-
}
191-
192-
fun allCharacteristics(
193-
service: BluetoothGattService,
194-
char: BluetoothGattCharacteristic
195-
): List<CharacteristicSuccess> {
196-
return Property.values().toList()
197-
.map { findCharacteristic(service, char, it) }
198-
.filterOption()
199-
}
200-
201-
private fun findCharacteristic(
202-
service: BluetoothGattService,
203-
char: BluetoothGattCharacteristic,
204-
type: Property
205-
): Option<CharacteristicSuccess> {
206-
return when (type) {
207-
Property.WRITE -> writeCharacteristic(service, char)
208-
Property.READ -> readCharacteristic(service, char)
209-
Property.NOTIFY -> notifyCharacteristic(service, char)
210-
}
211-
}
212-
213-
private fun notifyCharacteristic(
214-
service: BluetoothGattService,
215-
char: BluetoothGattCharacteristic
216-
): Option<CharacteristicSuccess.Notify> {
217-
return if (char.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY > 0 &&
218-
char.properties and BluetoothGattCharacteristic.PROPERTY_READ > 0
219-
) {
220-
Option(CharacteristicSuccess.Notify(char.uuid, service.uuid, char))
221-
} else {
222-
None
223-
}
224-
}
225-
226-
private fun readCharacteristic(
227-
service: BluetoothGattService,
228-
char: BluetoothGattCharacteristic
229-
): Option<CharacteristicSuccess.Read> {
230-
return if (char.properties and BluetoothGattCharacteristic.PROPERTY_READ > 0) {
231-
Option(CharacteristicSuccess.Read(char.uuid, service.uuid, char))
232-
} else {
233-
None
234-
}
235-
}
236-
237-
private fun writeCharacteristic(
238-
service: BluetoothGattService,
239-
char: BluetoothGattCharacteristic
240-
): Option<CharacteristicSuccess.Write> {
241-
return if (char.properties and BluetoothGattCharacteristic.PERMISSION_WRITE > 0) {
242-
Option(CharacteristicSuccess.Write(char.uuid, service.uuid, char))
243-
} else {
244-
None
245-
}
246-
}
247-
}
136+
// private val gattCallback =
248137

249138
fun doCreateBond(): Completable {
250139
bondSubject.onNext(BondState.CreatingBond)
251140
return Completable.create { emitter ->
252-
ensureBond()
141+
createBondInsecure()
253142
.done { emitter.onComplete() }
254143
.fail { device, status ->
255144
emitter.onError(
@@ -281,7 +170,118 @@ internal class BeckonBleManager(
281170
}
282171

283172
override fun getGattCallback(): BleManagerGattCallback {
284-
return gattCallback
173+
return object : BleManagerGattCallback() {
174+
175+
override fun initialize() {
176+
Timber.d("initialize")
177+
if (bluetoothGatt != null) {
178+
val services = bluetoothGatt!!.services.map { it.uuid }
179+
val characteristics = allCharacteristics(bluetoothGatt!!)
180+
val detail = DeviceDetail(services, characteristics)
181+
182+
// TODO Fix disposable
183+
val disposable =
184+
Observable.just(Unit).delay(1600, TimeUnit.MILLISECONDS).flatMapCompletable {
185+
subscribeBla(descriptor.subscribes, detail)
186+
}
187+
.andThen(readBla(descriptor.reads, detail).ignoreElements())
188+
.subscribe(
189+
{
190+
devicesSubject.onSuccess(detail.right())
191+
},
192+
{
193+
devicesSubject.onSuccess(
194+
ConnectionError.GeneralError(
195+
device.address,
196+
it
197+
).left()
198+
)
199+
}
200+
)
201+
} else {
202+
devicesSubject.onSuccess(ConnectionError.BluetoothGattNull(device.address).left())
203+
}
204+
}
205+
206+
override fun onDeviceDisconnected() {
207+
Timber.d("onDeviceDisconnected gattCallback")
208+
}
209+
210+
override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean {
211+
Timber.d("isRequiredServiceSupported $gatt")
212+
val services = gatt.services.map { it.uuid }
213+
Timber.d("All discovered services $services")
214+
bluetoothGatt = gatt
215+
216+
return true
217+
}
218+
219+
private fun allCharacteristics(gatt: BluetoothGatt): List<CharacteristicSuccess> {
220+
return gatt.services.flatMap { allCharacteristics(it) }
221+
}
222+
223+
private fun allCharacteristics(service: BluetoothGattService): List<CharacteristicSuccess> {
224+
return service.characteristics.flatMap {
225+
allCharacteristics(service, it)
226+
}
227+
}
228+
229+
fun allCharacteristics(
230+
service: BluetoothGattService,
231+
char: BluetoothGattCharacteristic
232+
): List<CharacteristicSuccess> {
233+
return Property.values().toList()
234+
.map { findCharacteristic(service, char, it) }
235+
.filterOption()
236+
}
237+
238+
private fun findCharacteristic(
239+
service: BluetoothGattService,
240+
char: BluetoothGattCharacteristic,
241+
type: Property
242+
): Option<CharacteristicSuccess> {
243+
return when (type) {
244+
Property.WRITE -> writeCharacteristic(service, char)
245+
Property.READ -> readCharacteristic(service, char)
246+
Property.NOTIFY -> notifyCharacteristic(service, char)
247+
}
248+
}
249+
250+
private fun notifyCharacteristic(
251+
service: BluetoothGattService,
252+
char: BluetoothGattCharacteristic
253+
): Option<CharacteristicSuccess.Notify> {
254+
return if (char.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY > 0 &&
255+
char.properties and BluetoothGattCharacteristic.PROPERTY_READ > 0
256+
) {
257+
Option(CharacteristicSuccess.Notify(char.uuid, service.uuid, char))
258+
} else {
259+
None
260+
}
261+
}
262+
263+
private fun readCharacteristic(
264+
service: BluetoothGattService,
265+
char: BluetoothGattCharacteristic
266+
): Option<CharacteristicSuccess.Read> {
267+
return if (char.properties and BluetoothGattCharacteristic.PROPERTY_READ > 0) {
268+
Option(CharacteristicSuccess.Read(char.uuid, service.uuid, char))
269+
} else {
270+
None
271+
}
272+
}
273+
274+
private fun writeCharacteristic(
275+
service: BluetoothGattService,
276+
char: BluetoothGattCharacteristic
277+
): Option<CharacteristicSuccess.Write> {
278+
return if (char.properties and BluetoothGattCharacteristic.PERMISSION_WRITE > 0) {
279+
Option(CharacteristicSuccess.Write(char.uuid, service.uuid, char))
280+
} else {
281+
None
282+
}
283+
}
284+
}
285285
}
286286

287287
fun connectionState(): Observable<ConnectionState> {

beckon/src/main/java/com/technocreatives/beckon/internal/BeckonClientImpl.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ internal class BeckonClientImpl(
9494
setting: ScannerSetting,
9595
descriptor: Descriptor
9696
): Observable<Either<ConnectionError, BeckonDevice>> {
97-
Timber.d("Search: $setting")
98-
9997
Timber.d("Search: $setting")
10098
val connectedDevicesInSystem = context.bluetoothManager()
10199
.connectedDevices()
@@ -249,7 +247,7 @@ internal class BeckonClientImpl(
249247
.doFinally { beckonStore.dispatch(BeckonAction.RemoveConnectedDevice(device)) }
250248
}
251249

252-
// error can happen
250+
// exception can happen
253251
override fun save(macAddress: String): Single<String> {
254252
return when (val device = beckonStore.currentState().findConnectedDevice(macAddress)) {
255253
is None -> Single.error(ConnectionError.ConnectedDeviceNotFound(macAddress).toException())

0 commit comments

Comments
 (0)