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

Display HIGH/LOW for out-of-range BG on main screen (#565)

Jonas Björkert 3 месяцев назад
Родитель
Сommit
9c79601de0

+ 8 - 3
LoopFollow/Controllers/Nightscout/BGData.swift

@@ -236,14 +236,19 @@ extension MainViewController {
             let latestBG = entries[latestEntryIndex].sgv
             let priorBG = entries[latestEntryIndex - 1].sgv
             let deltaBG = latestBG - priorBG
-            let lastBGTime = entries[latestEntryIndex].date
 
             self.updateServerText(with: sourceName)
 
             // Set BGText with the latest BG value
-            self.setBGTextColor()
+            self.updateBGTextAppearance()
 
-            Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG))
+            if latestBG <= globalVariables.minDisplayGlucose {
+                Observable.shared.bgText.value = "LOW"
+            } else if latestBG >= globalVariables.maxDisplayGlucose {
+                Observable.shared.bgText.value = "HIGH"
+            } else {
+                Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG))
+            }
             Observable.shared.bg.value = latestBG
 
             // Direction handling

+ 7 - 0
LoopFollow/Helpers/Globals.swift

@@ -11,4 +11,11 @@ enum globalVariables {
     static let dotCarb: Float = 5
     static let dotBolus: Float = 5
     static let dotOther: Float = 5
+
+    // Glucose display range (mg/dL)
+    // Values at or below the min are shown as "LOW" on the main display;
+    // values at or above the max are shown as "HIGH". Also used to clamp
+    // prediction values on the graph.
+    static let minDisplayGlucose: Int = 39
+    static let maxDisplayGlucose: Int = 400
 }

+ 8 - 2
LoopFollow/ViewControllers/MainViewController.swift

@@ -266,7 +266,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         Storage.shared.colorBGText.$value
             .receive(on: DispatchQueue.main)
             .sink { [weak self] _ in
-                self?.setBGTextColor()
+                self?.updateBGTextAppearance()
             }
             .store(in: &cancellables)
 
@@ -1200,7 +1200,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         }
     }
 
-    func setBGTextColor() {
+    func updateBGTextAppearance() {
         if bgData.count > 0 {
             let latestBG = bgData[bgData.count - 1].sgv
             var color = NSUIColor.label
@@ -1220,6 +1220,12 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
             }
 
             BGText.textColor = color
+
+            if latestBG <= globalVariables.minDisplayGlucose || latestBG >= globalVariables.maxDisplayGlucose {
+                BGText.font = UIFont.systemFont(ofSize: 65, weight: .black)
+            } else {
+                BGText.font = UIFont.systemFont(ofSize: 85, weight: .black)
+            }
         }
     }