wip: stop connecting
This commit is contained in:
parent
0582fe0326
commit
b4777a1312
2 changed files with 22 additions and 5 deletions
|
@ -48,8 +48,10 @@ import io.reactivex.Completable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
import kotlin.concurrent.thread
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
@ -73,6 +75,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
private val handler: Handler = Handler(Looper.getMainLooper())
|
private val handler: Handler = Handler(Looper.getMainLooper())
|
||||||
private lateinit var statusChecker: Runnable
|
private lateinit var statusChecker: Runnable
|
||||||
var nextPodWarningCheck : Long = 0
|
var nextPodWarningCheck : Long = 0
|
||||||
|
@Volatile var stopConnecting: CountDownLatch? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
|
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
|
||||||
|
@ -171,19 +174,29 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
// empty on purpose
|
thread(
|
||||||
|
start = true,
|
||||||
|
name = "ConnectionThread",
|
||||||
|
) {
|
||||||
|
// TODO quadruple check that we are not creating a party of Threads here
|
||||||
|
try {
|
||||||
|
val stop = CountDownLatch(1)
|
||||||
|
stopConnecting = stop
|
||||||
|
omnipodManager.connect(stop)
|
||||||
|
} finally {
|
||||||
|
stopConnecting = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun disconnect(reason: String) {
|
override fun disconnect(reason: String) {
|
||||||
// TODO
|
omnipodManager.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopConnecting() {
|
override fun stopConnecting() {
|
||||||
// TODO
|
stopConnecting?.let { it.countDown() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun getPumpStatus(reason: String) {
|
override fun getPumpStatus(reason: String) {
|
||||||
aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason")
|
aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason")
|
||||||
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {
|
if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
|
||||||
interface OmnipodDashManager {
|
interface OmnipodDashManager {
|
||||||
|
|
||||||
|
@ -39,4 +40,7 @@ interface OmnipodDashManager {
|
||||||
fun silenceAlerts(alertTypes: EnumSet<AlertType>): Observable<PodEvent>
|
fun silenceAlerts(alertTypes: EnumSet<AlertType>): Observable<PodEvent>
|
||||||
|
|
||||||
fun deactivatePod(): Observable<PodEvent>
|
fun deactivatePod(): Observable<PodEvent>
|
||||||
|
|
||||||
|
fun disconnect()
|
||||||
|
fun connect(stop: CountDownLatch)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue