mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 15:34:26 +01:00
Fixing proximity sensor
This commit is contained in:
@@ -13,6 +13,10 @@ sealed class BleManagerResult <T> {
|
|||||||
fun hasBeenDisconnected(): Boolean {
|
fun hasBeenDisconnected(): Boolean {
|
||||||
return this is LinkLossResult || this is DisconnectedResult || this is MissingServiceResult
|
return this is LinkLossResult || this is DisconnectedResult || this is MissingServiceResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasBeenDisconnectedWithoutLinkLoss(): Boolean {
|
||||||
|
return this is DisconnectedResult || this is MissingServiceResult
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConnectingResult<T> : BleManagerResult<T>()
|
class ConnectingResult<T> : BleManagerResult<T>()
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ import no.nordicsemi.android.prx.repository.AlarmHandler
|
|||||||
import no.nordicsemi.android.prx.repository.PRXManager
|
import no.nordicsemi.android.prx.repository.PRXManager
|
||||||
import no.nordicsemi.android.prx.repository.PRXService
|
import no.nordicsemi.android.prx.repository.PRXService
|
||||||
import no.nordicsemi.android.prx.repository.ProximityServerManager
|
import no.nordicsemi.android.prx.repository.ProximityServerManager
|
||||||
import no.nordicsemi.android.service.BleManagerResult
|
import no.nordicsemi.android.service.*
|
||||||
import no.nordicsemi.android.service.ConnectingResult
|
|
||||||
import no.nordicsemi.android.service.ServiceManager
|
|
||||||
import no.nordicsemi.android.service.SuccessResult
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -33,7 +30,7 @@ class PRXRepository @Inject internal constructor(
|
|||||||
internal val data = _data.asStateFlow()
|
internal val data = _data.asStateFlow()
|
||||||
|
|
||||||
val isRunning = data.map { it.isRunning() }
|
val isRunning = data.map { it.isRunning() }
|
||||||
val hasBeenDisconnected = data.map { it.hasBeenDisconnected() }
|
val hasBeenDisconnectedWithoutLinkLoss = data.map { it.hasBeenDisconnectedWithoutLinkLoss() }
|
||||||
|
|
||||||
fun launch(device: BluetoothDevice) {
|
fun launch(device: BluetoothDevice) {
|
||||||
serviceManager.startService(PRXService::class.java, device)
|
serviceManager.startService(PRXService::class.java, device)
|
||||||
@@ -50,20 +47,14 @@ class PRXRepository @Inject internal constructor(
|
|||||||
handleLocalAlarm(it)
|
handleLocalAlarm(it)
|
||||||
}.launchIn(scope)
|
}.launchIn(scope)
|
||||||
|
|
||||||
scope.launch {
|
manager.start(device)
|
||||||
manager.start(device)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun PRXManager.start(device: BluetoothDevice) {
|
private fun PRXManager.start(device: BluetoothDevice) {
|
||||||
try {
|
connect(device)
|
||||||
connect(device)
|
.useAutoConnect(true)
|
||||||
.useAutoConnect(false)
|
.retry(3, 100)
|
||||||
.retry(3, 100)
|
.enqueue()
|
||||||
.suspend()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLocalAlarm(result: BleManagerResult<PRXData>) {
|
private fun handleLocalAlarm(result: BleManagerResult<PRXData>) {
|
||||||
@@ -74,6 +65,10 @@ class PRXRepository @Inject internal constructor(
|
|||||||
alarmHandler.pauseAlarm()
|
alarmHandler.pauseAlarm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// (result as? LinkLossResult<PRXData>)?.let {
|
||||||
|
// alarmHandler.playAlarm(it.data.localAlarmLevel)
|
||||||
|
// repository.setLocalAlarmLevel(repository.data.value.linkLossAlarmLevel)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enableAlarm() {
|
fun enableAlarm() {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ internal class PRXService : NotificationService() {
|
|||||||
|
|
||||||
repository.start(device, lifecycleScope)
|
repository.start(device, lifecycleScope)
|
||||||
|
|
||||||
repository.hasBeenDisconnected.onEach {
|
repository.hasBeenDisconnectedWithoutLinkLoss.onEach {
|
||||||
if (it) stopSelf()
|
if (it) stopSelf()
|
||||||
}.launchIn(lifecycleScope)
|
}.launchIn(lifecycleScope)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user