From ea9d336944c8ce91e15966b70fd06850bd75cc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Sat, 21 Mar 2026 16:37:14 +0100 Subject: [PATCH 1/2] Display HIGH/LOW for out-of-range BG values on main screen Show "HIGH" when BG >= 400 and "LOW" when BG <= 39, matching Dexcom sensor range behavior. Reduce font size for these labels to fit the display. --- LoopFollow/Controllers/Nightscout/BGData.swift | 11 ++++++++--- LoopFollow/ViewControllers/MainViewController.swift | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/LoopFollow/Controllers/Nightscout/BGData.swift b/LoopFollow/Controllers/Nightscout/BGData.swift index c07da66d5..5571739c6 100644 --- a/LoopFollow/Controllers/Nightscout/BGData.swift +++ b/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 <= 39 { + Observable.shared.bgText.value = "LOW" + } else if latestBG >= 400 { + Observable.shared.bgText.value = "HIGH" + } else { + Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG)) + } Observable.shared.bg.value = latestBG // Direction handling diff --git a/LoopFollow/ViewControllers/MainViewController.swift b/LoopFollow/ViewControllers/MainViewController.swift index e494ea946..e7af6bd51 100644 --- a/LoopFollow/ViewControllers/MainViewController.swift +++ b/LoopFollow/ViewControllers/MainViewController.swift @@ -277,7 +277,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) @@ -1085,7 +1085,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 @@ -1105,6 +1105,12 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele } BGText.textColor = color + + if latestBG <= 39 || latestBG >= 400 { + BGText.font = UIFont.systemFont(ofSize: 65, weight: .black) + } else { + BGText.font = UIFont.systemFont(ofSize: 85, weight: .black) + } } } From 0e86e9c2b4a7a2cb99358f543f1d9f22a6184c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Thu, 9 Apr 2026 11:22:31 +0200 Subject: [PATCH 2/2] Extract BG display range to named constants Move the 39/400 mg/dL thresholds into globalVariables so the main screen HIGH/LOW display logic shares a single source of truth instead of repeating magic numbers across call sites. --- LoopFollow/Controllers/Nightscout/BGData.swift | 4 ++-- LoopFollow/Helpers/Globals.swift | 7 +++++++ LoopFollow/ViewControllers/MainViewController.swift | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/LoopFollow/Controllers/Nightscout/BGData.swift b/LoopFollow/Controllers/Nightscout/BGData.swift index 5571739c6..58f4cf61f 100644 --- a/LoopFollow/Controllers/Nightscout/BGData.swift +++ b/LoopFollow/Controllers/Nightscout/BGData.swift @@ -242,9 +242,9 @@ extension MainViewController { // Set BGText with the latest BG value self.updateBGTextAppearance() - if latestBG <= 39 { + if latestBG <= globalVariables.minDisplayGlucose { Observable.shared.bgText.value = "LOW" - } else if latestBG >= 400 { + } else if latestBG >= globalVariables.maxDisplayGlucose { Observable.shared.bgText.value = "HIGH" } else { Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG)) diff --git a/LoopFollow/Helpers/Globals.swift b/LoopFollow/Helpers/Globals.swift index a93d5fa36..770ad7f70 100644 --- a/LoopFollow/Helpers/Globals.swift +++ b/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 } diff --git a/LoopFollow/ViewControllers/MainViewController.swift b/LoopFollow/ViewControllers/MainViewController.swift index e7af6bd51..be2ad505d 100644 --- a/LoopFollow/ViewControllers/MainViewController.swift +++ b/LoopFollow/ViewControllers/MainViewController.swift @@ -1106,7 +1106,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele BGText.textColor = color - if latestBG <= 39 || latestBG >= 400 { + if latestBG <= globalVariables.minDisplayGlucose || latestBG >= globalVariables.maxDisplayGlucose { BGText.font = UIFont.systemFont(ofSize: 65, weight: .black) } else { BGText.font = UIFont.systemFont(ofSize: 85, weight: .black)