Преглед изворни кода

Release/0.1.22 (#52)

* showEventualBG

* Fix autotune CR

* Use pumpProfile in autotune

* remove bolus reporter from guards

* Listen network status updates

* Show documents in Files app

* 0.1 CR increment

* Move eventualBG to the legend panel

* Fix decimal input in Manual TBR screen

* Bump version
Ivan пре 5 година
родитељ
комит
1066b92e35

+ 2 - 2
FreeAPS.xcodeproj/project.pbxproj

@@ -2005,7 +2005,7 @@
 					"@executable_path/Frameworks",
 				);
 				MARKETING_VERSION = "$(CURRENT_PROJECT_VERSION)";
-				PRODUCT_BUNDLE_IDENTIFIER = "---CHANGE-IT-TO-YOUR-OWN---";
+				PRODUCT_BUNDLE_IDENTIFIER = "---CHANE-IT-TO-YOUR-OWN---";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_VERSION = 5.0;
 				TARGETED_DEVICE_FAMILY = "1,2";
@@ -2031,7 +2031,7 @@
 					"@executable_path/Frameworks",
 				);
 				MARKETING_VERSION = "$(CURRENT_PROJECT_VERSION)";
-				PRODUCT_BUNDLE_IDENTIFIER = "---CHANGE-IT-TO-YOUR-OWN---";
+				PRODUCT_BUNDLE_IDENTIFIER = "---CHANE-IT-TO-YOUR-OWN---";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_VERSION = 5.0;
 				TARGETED_DEVICE_FAMILY = "1,2";

+ 1 - 1
FreeAPS/Resources/Config.xcconfig

@@ -1 +1 @@
-BUILD_VERSION = 0.1.21
+BUILD_VERSION = 0.1.22

+ 2 - 0
FreeAPS/Resources/Info.plist

@@ -30,6 +30,8 @@
 	</array>
 	<key>LSRequiresIPhoneOS</key>
 	<true/>
+	<key>LSSupportsOpeningDocumentsInPlace</key>
+	<true/>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>

+ 5 - 5
FreeAPS/Sources/APS/APSManager.swift

@@ -292,7 +292,7 @@ final class BaseAPSManager: APSManager, Injectable {
     private var bolusReporter: DoseProgressReporter?
 
     func enactBolus(amount: Double, isSMB: Bool) {
-        guard let pump = pumpManager, verifyStatus(), bolusReporter == nil else { return }
+        guard let pump = pumpManager, verifyStatus() else { return }
 
         let roundedAmout = pump.roundToSupportedBolusVolume(units: amount)
 
@@ -471,21 +471,21 @@ final class BaseAPSManager: APSManager, Injectable {
     private func enactSuggested() {
         guard let suggested = storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self) else {
             isLooping.send(false)
-            debug(.apsManager, "Suggestion not found")
+            warning(.apsManager, "Suggestion not found")
             processError(APSError.apsError(message: "Suggestion not found"))
             return
         }
 
         guard Date().timeIntervalSince(suggested.deliverAt ?? .distantPast) < Config.eхpirationInterval else {
             isLooping.send(false)
-            debug(.apsManager, "Suggestion expired")
+            warning(.apsManager, "Suggestion expired")
             processError(APSError.apsError(message: "Suggestion expired"))
             return
         }
 
-        guard let pump = pumpManager, verifyStatus(), bolusReporter == nil else {
+        guard let pump = pumpManager, verifyStatus() else {
             isLooping.send(false)
-            debug(.apsManager, "Invalid pump state")
+            warning(.apsManager, "Invalid pump state")
             return
         }
 

+ 7 - 2
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -116,12 +116,15 @@ final class OpenAPS {
                 let pumpHistory = self.loadFileFromStorage(name: OpenAPS.Monitor.pumpHistory)
                 let glucose = self.loadFileFromStorage(name: Monitor.glucose)
                 let profile = self.loadFileFromStorage(name: Settings.profile)
+                let pumpProfile = self.loadFileFromStorage(name: Settings.pumpProfile)
+                let carbs = self.loadFileFromStorage(name: Monitor.carbHistory)
 
                 let autotunePreppedGlucose = self.autotunePrepare(
                     pumphistory: pumpHistory,
                     profile: profile,
                     glucose: glucose,
-                    pumpprofile: profile,
+                    pumpprofile: pumpProfile,
+                    carbs: carbs,
                     categorizeUamAsBasal: categorizeUamAsBasal,
                     tuneInsulinCurve: tuneInsulinCurve
                 )
@@ -132,7 +135,7 @@ final class OpenAPS {
                 let autotuneResult = self.autotuneRun(
                     autotunePreparedData: autotunePreppedGlucose,
                     previousAutotuneResult: previousAutotune ?? profile,
-                    pumpProfile: profile
+                    pumpProfile: pumpProfile
                 )
 
                 debug(.openAPS, "AUTOTUNE RESULT: \(autotuneResult)")
@@ -240,6 +243,7 @@ final class OpenAPS {
         profile: JSON,
         glucose: JSON,
         pumpprofile: JSON,
+        carbs: JSON,
         categorizeUamAsBasal: Bool,
         tuneInsulinCurve: Bool
     ) -> RawJSON {
@@ -253,6 +257,7 @@ final class OpenAPS {
                 profile,
                 glucose,
                 pumpprofile,
+                carbs,
                 categorizeUamAsBasal,
                 tuneInsulinCurve
             ])

+ 3 - 1
FreeAPS/Sources/Modules/AutotuneConfig/AutotuneConfigViewModel.swift

@@ -11,7 +11,9 @@ extension AutotuneConfig {
         @Published var publishedDate = Date()
         @Persisted(key: "lastAutotuneDate") private var lastAutotuneDate = Date() {
             didSet {
-                publishedDate = lastAutotuneDate
+                DispatchQueue.main.async {
+                    self.publishedDate = self.lastAutotuneDate
+                }
             }
         }
 

+ 1 - 1
FreeAPS/Sources/Modules/CREditor/CREditorViewModel.swift

@@ -7,7 +7,7 @@ extension CREditor {
 
         let timeValues = stride(from: 0.0, to: 1.days.timeInterval, by: 30.minutes.timeInterval).map { $0 }
 
-        let rateValues = stride(from: 2, to: 50.01, by: 0.5).map { $0 }
+        let rateValues = stride(from: 2, to: 50.01, by: 0.1).map { $0 }
 
         var canAdd: Bool {
             guard let lastItem = items.last else { return true }

+ 3 - 0
FreeAPS/Sources/Modules/Home/HomeViewModel.swift

@@ -40,6 +40,7 @@ extension Home {
         @Published var errorMessage: String? = nil
         @Published var errorDate: Date? = nil
         @Published var bolusProgress: Decimal?
+        @Published var eventualBG: Int?
 
         @Published var allowManualTemp = false
         @Published var units: GlucoseUnits = .mmolL
@@ -234,6 +235,8 @@ extension Home {
             } else {
                 statusTitle = "Suggested"
             }
+
+            eventualBG = suggestion.eventualBG
         }
 
         private func setupReservoir() {

+ 39 - 21
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -155,27 +155,45 @@ extension Home {
         }
 
         var legendPanal: some View {
-            HStack(alignment: .firstTextBaseline) {
-                Circle().fill(Color.loopGreen).frame(width: 8, height: 8)
-                    .padding(.leading, 8)
-                Text("BG")
-                    .font(.system(size: 12, weight: .bold)).foregroundColor(.loopGreen)
-                Circle().fill(Color.insulin).frame(width: 8, height: 8)
-                    .padding(.leading, 8)
-                Text("IOB")
-                    .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
-                Circle().fill(Color.zt).frame(width: 8, height: 8)
-                    .padding(.leading, 8)
-                Text("ZT")
-                    .font(.system(size: 12, weight: .bold)).foregroundColor(.zt)
-                Circle().fill(Color.loopYellow).frame(width: 8, height: 8)
-                    .padding(.leading, 8)
-                Text("COB")
-                    .font(.system(size: 12, weight: .bold)).foregroundColor(.loopYellow)
-                Circle().fill(Color.uam).frame(width: 8, height: 8)
-                    .padding(.leading, 8)
-                Text("UAM")
-                    .font(.system(size: 12, weight: .bold)).foregroundColor(.uam)
+            HStack(alignment: .center) {
+                Group {
+                    Circle().fill(Color.loopGreen).frame(width: 8, height: 8)
+                    Text("BG")
+                        .font(.system(size: 12, weight: .bold)).foregroundColor(.loopGreen)
+                }
+                Group {
+                    Circle().fill(Color.insulin).frame(width: 8, height: 8)
+                        .padding(.leading, 8)
+                    Text("IOB")
+                        .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
+                }
+                Group {
+                    Circle().fill(Color.zt).frame(width: 8, height: 8)
+                        .padding(.leading, 8)
+                    Text("ZT")
+                        .font(.system(size: 12, weight: .bold)).foregroundColor(.zt)
+                }
+                Group {
+                    Circle().fill(Color.loopYellow).frame(width: 8, height: 8)
+                        .padding(.leading, 8)
+                    Text("COB")
+                        .font(.system(size: 12, weight: .bold)).foregroundColor(.loopYellow)
+                }
+                Group {
+                    Circle().fill(Color.uam).frame(width: 8, height: 8)
+                        .padding(.leading, 8)
+                    Text("UAM")
+                        .font(.system(size: 12, weight: .bold)).foregroundColor(.uam)
+                }
+
+                if let eventualBG = viewModel.eventualBG {
+                    Text(
+                        "⇢ " + numberFormatter.string(
+                            from: (viewModel.units == .mmolL ? eventualBG.asMmolL : Decimal(eventualBG)) as NSNumber
+                        )!
+                    )
+                    .font(.system(size: 12, weight: .bold)).foregroundColor(.secondary)
+                }
             }
             .frame(maxWidth: .infinity, maxHeight: 30)
         }

+ 1 - 1
FreeAPS/Sources/Modules/ManualTempBasal/View/ManualTempBasalRootView.swift

@@ -7,7 +7,7 @@ extension ManualTempBasal {
         private var formatter: NumberFormatter {
             let formatter = NumberFormatter()
             formatter.numberStyle = .decimal
-            formatter.maximumFractionDigits = 0
+            formatter.maximumFractionDigits = 2
             return formatter
         }
 

+ 9 - 0
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -56,6 +56,9 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         broadcaster.register(PumpHistoryObserver.self, observer: self)
         broadcaster.register(CarbsObserver.self, observer: self)
         broadcaster.register(TempTargetsObserver.self, observer: self)
+        _ = reachabilityManager.startListening(onQueue: processQueue) { status in
+            debug(.nightscout, "Network status: \(status)")
+        }
     }
 
     var cgmURL: URL? {
@@ -73,6 +76,12 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         let useLocal = (settingsManager.settings.useLocalGlucoseSource ?? false) && settingsManager.settings
             .localGlucosePort != nil
 
+        if !useLocal {
+            guard isNetworkReachable else {
+                return Just([]).eraseToAnyPublisher()
+            }
+        }
+
         let maybeNightscout = useLocal
             ? NightscoutAPI(url: URL(string: "http://127.0.0.1:\(settingsManager.settings.localGlucosePort!)")!)
             : nightscoutAPI