@@ -38,13 +38,13 @@ extension InsulinCorrection {
3838 /// - scheduledBasalRate: The scheduled basal rate at the time the correction is delivered
3939 /// - maxBasalRate: The maximum allowed basal rate
4040 /// - duration: The duration of the temporary basal
41- /// - minimumProgrammableIncrementPerUnit : The smallest fraction of a unit supported in basal delivery
41+ /// - rateRounder : The smallest fraction of a unit supported in basal delivery
4242 /// - Returns: A temp basal recommendation
4343 fileprivate func asTempBasal(
4444 scheduledBasalRate: Double ,
4545 maxBasalRate: Double ,
4646 duration: TimeInterval ,
47- minimumProgrammableIncrementPerUnit : Double
47+ rateRounder : ( ( Double ) -> Double ) ?
4848 ) -> TempBasalRecommendation {
4949 var rate = units / ( duration / TimeInterval( hours: 1 ) ) // units/hour
5050 switch self {
@@ -55,7 +55,8 @@ extension InsulinCorrection {
5555 }
5656
5757 rate = Swift . min ( maxBasalRate, Swift . max ( 0 , rate) )
58- rate = round ( rate * minimumProgrammableIncrementPerUnit) / minimumProgrammableIncrementPerUnit
58+
59+ rate = rateRounder ? ( rate) ?? rate
5960
6061 return TempBasalRecommendation (
6162 unitsPerHour: rate,
@@ -83,16 +84,16 @@ extension InsulinCorrection {
8384 /// - Parameters:
8485 /// - pendingInsulin: The number of units expected to be delivered, but not yet reflected in the correction
8586 /// - maxBolus: The maximum allowable bolus value in units
86- /// - minimumProgrammableIncrementPerUnit : The smallest fraction of a unit supported in bolus delivery
87+ /// - volumeRounder : The smallest fraction of a unit supported in bolus delivery
8788 /// - Returns: A bolus recommendation
8889 fileprivate func asBolus(
8990 pendingInsulin: Double ,
9091 maxBolus: Double ,
91- minimumProgrammableIncrementPerUnit : Double
92+ volumeRounder : ( ( Double ) -> Double ) ?
9293 ) -> BolusRecommendation {
9394 var units = self . units - pendingInsulin
9495 units = Swift . min ( maxBolus, Swift . max ( 0 , units) )
95- units = round ( units * minimumProgrammableIncrementPerUnit ) / minimumProgrammableIncrementPerUnit
96+ units = volumeRounder ? ( units) ?? units
9697
9798 return BolusRecommendation (
9899 amount: units,
@@ -340,8 +341,8 @@ extension Collection where Element == GlucoseValue {
340341 /// - basalRates: The schedule of basal rates
341342 /// - maxBasalRate: The maximum allowed basal rate
342343 /// - lastTempBasal: The previously set temp basal
344+ /// - rateRounder: Closure that rounds recommendation to nearest supported rate. If nil, no rounding is performed
343345 /// - duration: The duration of the temporary basal
344- /// - minimumProgrammableIncrementPerUnit: The smallest fraction of a unit supported in basal delivery
345346 /// - continuationInterval: The duration of time before an ongoing temp basal should be continued with a new command
346347 /// - Returns: The recommended temporary basal rate and duration
347348 func recommendedTempBasal(
@@ -353,8 +354,8 @@ extension Collection where Element == GlucoseValue {
353354 basalRates: BasalRateSchedule ,
354355 maxBasalRate: Double ,
355356 lastTempBasal: DoseEntry ? ,
357+ rateRounder: ( ( Double ) -> Double ) ? = nil ,
356358 duration: TimeInterval = . minutes( 30 ) ,
357- minimumProgrammableIncrementPerUnit: Double = 40 ,
358359 continuationInterval: TimeInterval = . minutes( 11 )
359360 ) -> TempBasalRecommendation ? {
360361 let correction = self . insulinCorrection (
@@ -379,7 +380,7 @@ extension Collection where Element == GlucoseValue {
379380 scheduledBasalRate: scheduledBasalRate,
380381 maxBasalRate: maxBasalRate,
381382 duration: duration,
382- minimumProgrammableIncrementPerUnit : minimumProgrammableIncrementPerUnit
383+ rateRounder : rateRounder
383384 )
384385
385386 return temp? . ifNecessary (
@@ -400,7 +401,7 @@ extension Collection where Element == GlucoseValue {
400401 /// - model: The insulin absorption model
401402 /// - pendingInsulin: The number of units expected to be delivered, but not yet reflected in the correction
402403 /// - maxBolus: The maximum bolus to return
403- /// - minimumProgrammableIncrementPerUnit: The smallest fraction of a unit supported in bolus delivery
404+ /// - volumeRounder: Closure that rounds recommendation to nearest supported bolus volume. If nil, no rounding is performed
404405 /// - Returns: A bolus recommendation
405406 func recommendedBolus(
406407 to correctionRange: GlucoseRangeSchedule ,
@@ -410,7 +411,7 @@ extension Collection where Element == GlucoseValue {
410411 model: InsulinModel ,
411412 pendingInsulin: Double ,
412413 maxBolus: Double ,
413- minimumProgrammableIncrementPerUnit : Double = 40
414+ volumeRounder : ( ( Double ) -> Double ) ? = nil
414415 ) -> BolusRecommendation {
415416 guard let correction = self . insulinCorrection (
416417 to: correctionRange,
@@ -425,7 +426,7 @@ extension Collection where Element == GlucoseValue {
425426 var bolus = correction. asBolus (
426427 pendingInsulin: pendingInsulin,
427428 maxBolus: maxBolus,
428- minimumProgrammableIncrementPerUnit : minimumProgrammableIncrementPerUnit
429+ volumeRounder : volumeRounder
429430 )
430431
431432 // Handle the "current BG below target" notice here
0 commit comments