Просмотр исходного кода

Improve the basal manual temp : allows to do bolus, new UI, persistant basal temp.
compile with the Xcode Version 14

(cherry picked from commit 56c4ff81f7b8d7e9a3201c89eeaed002d3bcc816)

avouspierre 3 лет назад
Родитель
Сommit
fc8dea0860

+ 38 - 0
FreeAPS/Resources/Assets.xcassets/Colors/ManualTempBasal.colorset/Contents.json

@@ -0,0 +1,38 @@
+{
+  "colors" : [
+    {
+      "color" : {
+        "color-space" : "srgb",
+        "components" : {
+          "alpha" : "1.000",
+          "blue" : "0.988",
+          "green" : "0.588",
+          "red" : "0.118"
+        }
+      },
+      "idiom" : "universal"
+    },
+    {
+      "appearances" : [
+        {
+          "appearance" : "luminosity",
+          "value" : "dark"
+        }
+      ],
+      "color" : {
+        "color-space" : "srgb",
+        "components" : {
+          "alpha" : "1.000",
+          "blue" : "0.988",
+          "green" : "0.588",
+          "red" : "0.118"
+        }
+      },
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 19 - 6
FreeAPS/Sources/APS/APSManager.swift

@@ -88,7 +88,7 @@ final class BaseAPSManager: APSManager, Injectable {
 
     var bluetoothManager: BluetoothStateManager? { deviceDataManager.bluetoothManager }
 
-    var isManualTempBasal: Bool = false
+    @Persisted(key: "isManualTempBasal") var isManualTempBasal: Bool = false
 
     let isLooping = CurrentValueSubject<Bool, Never>(false)
     let lastLoopDateSubject = PassthroughSubject<Date, Never>()
@@ -241,11 +241,6 @@ 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")
@@ -415,6 +410,13 @@ final class BaseAPSManager: APSManager, Injectable {
         }
 
         guard let pump = pumpManager else { return }
+
+        // unable to do temp basal during manual temp basal 😁
+        if isManualTempBasal {
+            processError(APSError.manualBasalTemp(message: "Loop not possible during the manual basal temp"))
+            return
+        }
+
         debug(.apsManager, "Enact temp basal \(rate) - \(duration)")
 
         let roundedAmout = pump.roundToSupportedBasalRate(unitsPerHour: rate)
@@ -529,6 +531,11 @@ final class BaseAPSManager: APSManager, Injectable {
                 processError(error)
                 return
             }
+            // unable to do temp basal during manual temp basal 😁
+            if isManualTempBasal {
+                processError(APSError.manualBasalTemp(message: "Loop not possible during the manual basal temp"))
+                return
+            }
             guard !settings.closedLoop else {
                 return
             }
@@ -580,6 +587,12 @@ final class BaseAPSManager: APSManager, Injectable {
             return Fail(error: APSError.apsError(message: "Pump not set")).eraseToAnyPublisher()
         }
 
+        // unable to do temp basal during manual temp basal 😁
+        if isManualTempBasal {
+            return Fail(error: APSError.manualBasalTemp(message: "Loop not possible during the manual basal temp"))
+                .eraseToAnyPublisher()
+        }
+
         let basalPublisher: AnyPublisher<Void, Error> = Deferred { () -> AnyPublisher<Void, Error> in
             if let error = self.verifyStatus() {
                 return Fail(error: error).eraseToAnyPublisher()

+ 1 - 0
FreeAPS/Sources/Helpers/Color+Extensions.swift

@@ -52,6 +52,7 @@ extension Color {
     static let loopGreen = Color("LoopGreen")
     static let loopYellow = Color("LoopYellow")
     static let loopRed = Color("LoopRed")
+    static let loopManualTemp = Color("ManualTempBasal")
     //   static let insulin = Color("Insulin")
     static let uam = Color("UAM")
     static let zt = Color("ZT")

+ 5 - 0
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -47,6 +47,7 @@ extension Home {
         @Published var pumpDisplayState: PumpDisplayState?
         @Published var alarm: GlucoseAlarm?
         @Published var animatedBackground = false
+        @Published var manualTempBasal = false
 
         override func subscribe() {
             setupGlucose()
@@ -68,6 +69,7 @@ extension Home {
             lastLoopDate = apsManager.lastLoopDate
             carbsRequired = suggestion?.carbsReq
             alarm = provider.glucoseStorage.alarm
+            manualTempBasal = apsManager.isManualTempBasal
 
             setStatusTitle()
             setupCurrentTempTarget()
@@ -197,6 +199,7 @@ extension Home {
         private func setupBasals() {
             DispatchQueue.main.async { [weak self] in
                 guard let self = self else { return }
+                self.manualTempBasal = self.apsManager.isManualTempBasal
                 self.tempBasals = self.provider.pumpHistory(hours: self.filteredHours).filter {
                     $0.type == .tempBasal || $0.type == .tempBasalDuration
                 }
@@ -260,6 +263,7 @@ extension Home {
         private func setupTempTargets() {
             DispatchQueue.main.async { [weak self] in
                 guard let self = self else { return }
+                self.manualTempBasal = self.apsManager.isManualTempBasal
                 self.tempTargets = self.provider.tempTargets(hours: self.filteredHours)
             }
         }
@@ -357,6 +361,7 @@ extension Home.StateModel:
         closedLoop = settingsManager.settings.closedLoop
         units = settingsManager.settings.units
         animatedBackground = settingsManager.settings.animatedBackground
+        manualTempBasal = apsManager.isManualTempBasal
         setupGlucose()
     }
 

+ 7 - 1
FreeAPS/Sources/Modules/Home/View/Header/LoopView.swift

@@ -13,6 +13,7 @@ struct LoopView: View {
     @Binding var timerDate: Date
     @Binding var isLooping: Bool
     @Binding var lastLoopDate: Date
+    @Binding var manualTempBasal: Bool
 
     private var dateFormatter: DateFormatter {
         let formatter = DateFormatter()
@@ -34,6 +35,8 @@ struct LoopView: View {
             }
             if isLooping {
                 Text("looping").font(.caption2)
+            } else if manualTempBasal {
+                Text("Manual").font(.caption2)
             } else if actualSuggestion?.timestamp != nil {
                 Text(timeString).font(.caption2)
                     .foregroundColor(.secondary)
@@ -55,6 +58,9 @@ struct LoopView: View {
         guard actualSuggestion?.timestamp != nil else {
             return .loopGray
         }
+        guard manualTempBasal == false else {
+            return .loopManualTemp
+        }
         let delta = timerDate.timeIntervalSince(lastLoopDate) - Config.lag
 
         if delta <= 5.minutes.timeInterval {
@@ -71,7 +77,7 @@ struct LoopView: View {
 
     func mask(in rect: CGRect) -> Path {
         var path = Rectangle().path(in: rect)
-        if !closedLoop {
+        if !closedLoop || manualTempBasal {
             path.addPath(Rectangle().path(in: CGRect(x: rect.minX, y: rect.midY - 5, width: rect.width, height: 10)))
         }
         return path

+ 2 - 1
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -123,7 +123,8 @@ extension Home {
                 closedLoop: $state.closedLoop,
                 timerDate: $state.timerDate,
                 isLooping: $state.isLooping,
-                lastLoopDate: $state.lastLoopDate
+                lastLoopDate: $state.lastLoopDate,
+                manualTempBasal: $state.manualTempBasal
             ).onTapGesture {
                 isStatusPopupPresented = true
             }.onLongPressGesture {