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

Release/0.1.4 (#13)

* Set pump initial settings and pump popover

* Check reservoir

* fix initial setup

* open CGM source

* fix initial pump setup

* Hide debug options

* fix initial preferences

* use xcconfig

* Autoupdate build number

* Create README_RU.md

* Display version and build number

* English README

* Disclaimer

* disallow bolus 0

* possible fix wrong layout after start

* fix glucose Y range

* Optional api secret

* fix suggestion parsing

* Face id access

* fix clock

* build autoupdate

* Fix temp targets layout and pump view

* Fix pump updating logic

* fix omnipod reservooir

* Background timers

* legend

* Remove unused dependecies

* show temp target range

* FAQ_RU

* FAQ eng

* bump buils number

* clear signing

* fix reservoir bug

* Libre 2 glucose filter

* fix glucose filter logic

* skip_neutral_temps option fix

* Fix bild number update script

* Fix BloodGlucose parsing

* update charts on UIApplication.willEnterForegroundNotification

* Fix autotune deletion

* README updated

* Bump version

* Heartbeat based on glucose, not pump

* set pump heartbeat to true

* fix omnipod time

* set loop color to yellow if suggestion not found

* Rewrite sync logic again

* heartbeat if no new glucose

* set heartbeat date on force

* Set external date to heartbeat

* fix DecimalField autofocus

* some magic to reduce yellow loops

* Fix setting basal profile to pump

* add temp targets to account for calculating charts height

* bump version
Ivan пре 5 година
родитељ
комит
38eff136f7

+ 1 - 1
FreeAPS/Resources/Config.xcconfig

@@ -1 +1 @@
-BUILD_VERSION = 0.1.3
+BUILD_VERSION = 0.1.4

+ 1 - 4
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -86,7 +86,6 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
 
     func heartbeat(date: Date, force: Bool) {
         if force {
-            lastHeartBeatTime = date
             updatePumpData()
             return
         }
@@ -164,9 +163,7 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
 
     func pumpManagerBLEHeartbeatDidFire(_: PumpManager) {
         debug(.deviceManager, "Pump Heartbeat")
-        if glucoseStorage.isGlucoseFresh() {
-            heartbeat(date: Date(), force: false)
-        }
+        heartbeat(date: Date(), force: false)
     }
 
     func pumpManagerMustProvideBLEHeartbeat(_: PumpManager) -> Bool {

+ 0 - 2
FreeAPS/Sources/APS/GlucoseManager.swift

@@ -39,8 +39,6 @@ final class BaseGlucoseManager: GlucoseManager, Injectable {
                 if !filtered.isEmpty {
                     debug(.nightscout, "New glucose found")
                     self.apsManager.heartbeat(date: date, force: true)
-                } else {
-                    self.apsManager.heartbeat(date: date, force: false)
                 }
             }
             .store(in: &lifetime)

+ 24 - 11
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -654,6 +654,14 @@ extension MainChartView {
         .min()
     }
 
+    private func maxTargetValue() -> Int? {
+        tempTargets.map(\.targetTop).filter { $0 > 0 }.max().map(Int.init)
+    }
+
+    private func minTargetValue() -> Int? {
+        tempTargets.map(\.targetBottom).filter { $0 > 0 }.min().map(Int.init)
+    }
+
     private func glucoseToCoordinate(_ glucoseEntry: BloodGlucose, fullSize: CGSize) -> CGPoint {
         let x = timeToXCoordinate(glucoseEntry.dateString.timeIntervalSince1970, fullSize: fullSize)
         let y = glucoseToYCoordinate(glucoseEntry.glucose ?? 0, fullSize: fullSize)
@@ -686,14 +694,7 @@ extension MainChartView {
     private func glucoseToYCoordinate(_ glucoseValue: Int, fullSize: CGSize) -> CGFloat {
         let topYPaddint = Config.topYPadding + Config.basalHeight
         let bottomYPadding = Config.bottomYPadding
-        var maxValue = glucose.compactMap(\.glucose).max() ?? Config.maxGlucose
-        if let maxPredValue = maxPredValue() {
-            maxValue = max(maxValue, maxPredValue)
-        }
-        var minValue = glucose.compactMap(\.glucose).min() ?? Config.minGlucose
-        if let minPredValue = minPredValue() {
-            minValue = min(minValue, minPredValue)
-        }
+        let (minValue, maxValue) = minMaxYValues()
         let stepYFraction = (fullSize.height - topYPaddint - bottomYPadding) / CGFloat(maxValue - minValue)
         let yOffset = CGFloat(minValue) * stepYFraction
         let y = fullSize.height - CGFloat(glucoseValue) * stepYFraction + yOffset - bottomYPadding
@@ -725,17 +726,29 @@ extension MainChartView {
         return pointInLine(CGPoint(x: prevX, y: prevY), CGPoint(x: nextX, y: nextY), fraction)
     }
 
-    private func getGlucoseYRange(fullSize: CGSize) -> GlucoseYRange {
-        let topYPaddint = Config.topYPadding + Config.basalHeight
-        let bottomYPadding = Config.bottomYPadding
+    private func minMaxYValues() -> (min: Int, max: Int) {
         var maxValue = glucose.compactMap(\.glucose).max() ?? Config.maxGlucose
         if let maxPredValue = maxPredValue() {
             maxValue = max(maxValue, maxPredValue)
         }
+        if let maxTargetValue = maxTargetValue() {
+            maxValue = max(maxValue, maxTargetValue)
+        }
         var minValue = glucose.compactMap(\.glucose).min() ?? Config.minGlucose
         if let minPredValue = minPredValue() {
             minValue = min(minValue, minPredValue)
         }
+        if let minTargetValue = minTargetValue() {
+            minValue = min(minValue, minTargetValue)
+        }
+
+        return (min: minValue, max: maxValue)
+    }
+
+    private func getGlucoseYRange(fullSize: CGSize) -> GlucoseYRange {
+        let topYPaddint = Config.topYPadding + Config.basalHeight
+        let bottomYPadding = Config.bottomYPadding
+        let (minValue, maxValue) = minMaxYValues()
         let stepYFraction = (fullSize.height - topYPaddint - bottomYPadding) / CGFloat(maxValue - minValue)
         let yOffset = CGFloat(minValue) * stepYFraction
         let maxY = fullSize.height - CGFloat(minValue) * stepYFraction + yOffset - bottomYPadding

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

@@ -91,7 +91,7 @@ extension Home {
                     if viewModel.units == .mmolL {
                         Text(
                             targetFormatter
-                                .string(from: tepmTarget.targetBottom.asMmolL as NSNumber)! + " \(viewModel.units.rawValue)"
+                                .string(from: tepmTarget.targetBottom.asMmolL as NSNumber)!
                         )
                         .font(.caption)
                         .foregroundColor(.secondary)
@@ -104,10 +104,13 @@ extension Home {
                             )
                             .font(.caption)
                             .foregroundColor(.secondary)
+                        } else {
+                            Text(viewModel.units.rawValue).font(.caption)
+                                .foregroundColor(.secondary)
                         }
 
                     } else {
-                        Text(targetFormatter.string(from: tepmTarget.targetBottom as NSNumber)! + " \(viewModel.units.rawValue)")
+                        Text(targetFormatter.string(from: tepmTarget.targetBottom as NSNumber)!)
                             .font(.caption)
                             .foregroundColor(.secondary)
                         if tepmTarget.targetBottom != tepmTarget.targetTop {
@@ -116,6 +119,9 @@ extension Home {
                             Text(targetFormatter.string(from: tepmTarget.targetTop as NSNumber)! + " \(viewModel.units.rawValue)")
                                 .font(.caption)
                                 .foregroundColor(.secondary)
+                        } else {
+                            Text(viewModel.units.rawValue).font(.caption)
+                                .foregroundColor(.secondary)
                         }
                     }
                 }

+ 1 - 1
FreeAPS/Sources/Modules/PumpConfig/PumpConfigProvider.swift

@@ -15,7 +15,7 @@ extension PumpConfig {
         }
 
         func basalProfile() -> [BasalProfileEntry] {
-            storage.retrieve(OpenAPS.Settings.profile, as: Autotune.self)?.basalProfile
+            storage.retrieve(OpenAPS.Settings.pumpProfile, as: Autotune.self)?.basalProfile
                 ?? storage.retrieve(OpenAPS.Settings.pumpProfile, as: Autotune.self)?.basalProfile
                 ?? [BasalProfileEntry(start: "00:00", minutes: 0, rate: 1)]
         }

+ 1 - 1
FreeAPS/Sources/Services/Network/NightscoutAPI.swift

@@ -31,7 +31,7 @@ extension NightscoutAPI {
     func checkConnection() -> AnyPublisher<Void, Swift.Error> {
         struct Check: Codable, Equatable {
             var eventType = "Note"
-            var enteredBy = "feeaps-x://"
+            var enteredBy = "freeaps-x://"
             var notes = "FreeAPS X connected"
         }
         let check = Check()

+ 3 - 1
FreeAPS/Sources/Views/DecimalTextField.swift

@@ -55,7 +55,9 @@ struct DecimalTextField: UIViewRepresentable {
         toolBar.setItems([clearButton, space, doneButton], animated: true)
         textfield.inputAccessoryView = toolBar
         if autofocus {
-            textfield.becomeFirstResponder()
+            DispatchQueue.main.async {
+                textfield.becomeFirstResponder()
+            }
         }
         return textfield
     }