-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move observation handling to common source set
- Loading branch information
Showing
16 changed files
with
117 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.juul.kable | ||
|
||
internal actual fun Peripheral.observationHandler(): Observation.Handler = object : Observation.Handler { | ||
override suspend fun startObservation(characteristic: Characteristic) { | ||
(this@observationHandler as AndroidPeripheral).startObservation(characteristic) | ||
} | ||
|
||
override suspend fun stopObservation(characteristic: Characteristic) { | ||
(this@observationHandler as AndroidPeripheral).stopObservation(characteristic) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.juul.kable | ||
|
||
internal actual fun Peripheral.observationHandler(): Observation.Handler = object : Observation.Handler { | ||
override suspend fun startObservation(characteristic: Characteristic) { | ||
(this@observationHandler as ApplePeripheral).startNotifications(characteristic) | ||
} | ||
|
||
override suspend fun stopObservation(characteristic: Characteristic) { | ||
(this@observationHandler as ApplePeripheral).stopNotifications(characteristic) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.juul.kable | ||
|
||
internal sealed class ObservationEvent<T> { | ||
|
||
abstract val characteristic: Characteristic | ||
|
||
data class CharacteristicChange<T>( | ||
override val characteristic: Characteristic, | ||
val data: T, | ||
) : ObservationEvent<T>() | ||
|
||
data class Error<T>( | ||
override val characteristic: Characteristic, | ||
val cause: Throwable, | ||
) : ObservationEvent<T>() | ||
} | ||
|
||
internal fun <T> dematerialize(event: ObservationEvent<T>): T = when (event) { | ||
is ObservationEvent.Error -> throw event.cause | ||
is ObservationEvent.CharacteristicChange -> event.data | ||
} | ||
|
||
internal fun <T> ObservationEvent<T>.isAssociatedWith(characteristic: Characteristic): Boolean = | ||
this.characteristic.characteristicUuid == characteristic.characteristicUuid && | ||
this.characteristic.serviceUuid == characteristic.serviceUuid |
Oops, something went wrong.