Skip to content

Commit 9c79601

Browse files
authored
Display HIGH/LOW for out-of-range BG on main screen (#565)
1 parent 1eb0865 commit 9c79601

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

LoopFollow/Controllers/Nightscout/BGData.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,19 @@ extension MainViewController {
236236
let latestBG = entries[latestEntryIndex].sgv
237237
let priorBG = entries[latestEntryIndex - 1].sgv
238238
let deltaBG = latestBG - priorBG
239-
let lastBGTime = entries[latestEntryIndex].date
240239

241240
self.updateServerText(with: sourceName)
242241

243242
// Set BGText with the latest BG value
244-
self.setBGTextColor()
243+
self.updateBGTextAppearance()
245244

246-
Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG))
245+
if latestBG <= globalVariables.minDisplayGlucose {
246+
Observable.shared.bgText.value = "LOW"
247+
} else if latestBG >= globalVariables.maxDisplayGlucose {
248+
Observable.shared.bgText.value = "HIGH"
249+
} else {
250+
Observable.shared.bgText.value = Localizer.toDisplayUnits(String(latestBG))
251+
}
247252
Observable.shared.bg.value = latestBG
248253

249254
// Direction handling

LoopFollow/Helpers/Globals.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ enum globalVariables {
1111
static let dotCarb: Float = 5
1212
static let dotBolus: Float = 5
1313
static let dotOther: Float = 5
14+
15+
// Glucose display range (mg/dL)
16+
// Values at or below the min are shown as "LOW" on the main display;
17+
// values at or above the max are shown as "HIGH". Also used to clamp
18+
// prediction values on the graph.
19+
static let minDisplayGlucose: Int = 39
20+
static let maxDisplayGlucose: Int = 400
1421
}

LoopFollow/ViewControllers/MainViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
266266
Storage.shared.colorBGText.$value
267267
.receive(on: DispatchQueue.main)
268268
.sink { [weak self] _ in
269-
self?.setBGTextColor()
269+
self?.updateBGTextAppearance()
270270
}
271271
.store(in: &cancellables)
272272

@@ -1200,7 +1200,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
12001200
}
12011201
}
12021202

1203-
func setBGTextColor() {
1203+
func updateBGTextAppearance() {
12041204
if bgData.count > 0 {
12051205
let latestBG = bgData[bgData.count - 1].sgv
12061206
var color = NSUIColor.label
@@ -1220,6 +1220,12 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
12201220
}
12211221

12221222
BGText.textColor = color
1223+
1224+
if latestBG <= globalVariables.minDisplayGlucose || latestBG >= globalVariables.maxDisplayGlucose {
1225+
BGText.font = UIFont.systemFont(ofSize: 65, weight: .black)
1226+
} else {
1227+
BGText.font = UIFont.systemFont(ofSize: 85, weight: .black)
1228+
}
12231229
}
12241230
}
12251231

0 commit comments

Comments
 (0)