|
|
@@ -2,6 +2,7 @@ import Combine
|
|
|
import Foundation
|
|
|
import LoopKit
|
|
|
import LoopKitUI
|
|
|
+import OmniBLE
|
|
|
import RileyLinkKit
|
|
|
import SwiftDate
|
|
|
import Swinject
|
|
|
@@ -19,6 +20,7 @@ protocol APSManager {
|
|
|
var lastLoopDateSubject: PassthroughSubject<Date, Never> { get }
|
|
|
var bolusProgress: CurrentValueSubject<Decimal?, Never> { get }
|
|
|
var pumpExpiresAtDate: CurrentValueSubject<Date?, Never> { get }
|
|
|
+ var isManualTempBasal: Bool { get }
|
|
|
func enactTempBasal(rate: Double, duration: TimeInterval)
|
|
|
func makeProfiles() -> AnyPublisher<Bool, Never>
|
|
|
func determineBasal() -> AnyPublisher<Bool, Never>
|
|
|
@@ -36,6 +38,7 @@ enum APSError: LocalizedError {
|
|
|
case apsError(message: String)
|
|
|
case deviceSyncError(message: String)
|
|
|
case deviceAlert(message: String)
|
|
|
+ case manualBasalTemp(message: String)
|
|
|
|
|
|
var errorDescription: String? {
|
|
|
switch self {
|
|
|
@@ -51,6 +54,8 @@ enum APSError: LocalizedError {
|
|
|
return "Sync error: \(message)"
|
|
|
case let .deviceAlert(message):
|
|
|
return "Pump message: \(message)"
|
|
|
+ case let .manualBasalTemp(message):
|
|
|
+ return "Manual Basal Temp : \(message)"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -85,6 +90,8 @@ final class BaseAPSManager: APSManager, Injectable {
|
|
|
|
|
|
var bluetoothManager: BluetoothStateManager? { deviceDataManager.bluetoothManager }
|
|
|
|
|
|
+ var isManualTempBasal: Bool = false
|
|
|
+
|
|
|
let isLooping = CurrentValueSubject<Bool, Never>(false)
|
|
|
let lastLoopDateSubject = PassthroughSubject<Date, Never>()
|
|
|
let lastError = CurrentValueSubject<Error?, Never>(nil)
|
|
|
@@ -146,6 +153,21 @@ final class BaseAPSManager: APSManager, Injectable {
|
|
|
}
|
|
|
}
|
|
|
.store(in: &lifetime)
|
|
|
+
|
|
|
+ // manage a manual Temp Basal from OmniPod - Force loop() after stop a temp basal or finished
|
|
|
+ deviceDataManager.manualTempBasal
|
|
|
+ .receive(on: processQueue)
|
|
|
+ .sink { manualBasal in
|
|
|
+ if manualBasal {
|
|
|
+ self.isManualTempBasal = true
|
|
|
+ } else {
|
|
|
+ if self.isManualTempBasal {
|
|
|
+ self.isManualTempBasal = false
|
|
|
+ self.loop()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .store(in: &lifetime)
|
|
|
}
|
|
|
|
|
|
func heartbeat(date: Date) {
|
|
|
@@ -221,6 +243,11 @@ final class BaseAPSManager: APSManager, Injectable {
|
|
|
return APSError.invalidPumpState(message: "Pump suspended")
|
|
|
}
|
|
|
|
|
|
+ // block all if manual temp basal
|
|
|
+ if isManualTempBasal {
|
|
|
+ return APSError.manualBasalTemp(message: "Unable to change anything")
|
|
|
+ }
|
|
|
+
|
|
|
let reservoir = storage.retrieve(OpenAPS.Monitor.reservoir, as: Decimal.self) ?? 100
|
|
|
guard reservoir > 0 else {
|
|
|
return APSError.invalidPumpState(message: "Reservoir is empty")
|