diff --git a/LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift b/LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift index fe10b62b9..9eb5f6c43 100644 --- a/LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift +++ b/LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift @@ -72,11 +72,9 @@ extension MainViewController { while i <= toLoad { if i < prediction.count { let sgvValue = Int(round(prediction[i])) - // Skip values higher than 600 - if sgvValue <= 600 { - let prediction = ShareGlucoseData(sgv: sgvValue, date: predictionTime, direction: "flat") - predictionData.append(prediction) - } + let clampedValue = min(max(sgvValue, globalVariables.minDisplayGlucose), globalVariables.maxDisplayGlucose) + let prediction = ShareGlucoseData(sgv: clampedValue, date: predictionTime, direction: "flat") + predictionData.append(prediction) predictionTime += 300 } i += 1 diff --git a/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift b/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift index 57a940695..407613301 100644 --- a/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift +++ b/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift @@ -182,7 +182,8 @@ extension MainViewController { minPredBG = min(minPredBG, predictionValue) maxPredBG = max(maxPredBG, predictionValue) - let prediction = ShareGlucoseData(sgv: Int(round(predictionValue)), date: predictionTime, direction: "flat") + let clampedValue = min(max(Int(round(predictionValue)), globalVariables.minDisplayGlucose), globalVariables.maxDisplayGlucose) + let prediction = ShareGlucoseData(sgv: clampedValue, date: predictionTime, direction: "flat") predictionData.append(prediction) predictionTime += 300 } 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 }