Skip to content

Commit 4205e97

Browse files
committed
do not show bolus screen if microboluses is enabled
1 parent e40731e commit 4205e97

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Loop/Managers/LoopDataManager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class LoopDataManager {
3333

3434
private let logger: CategoryLogger
3535

36-
private var lastMicroBolusDate: Date? = Date()
36+
private var lastMicroBolusDate = Date(timeIntervalSinceNow: -(2 * 60)) // 2 minutes ago
3737

3838
// References to registered notification center observers
3939
private var notificationObservers: [Any] = []
@@ -1036,20 +1036,20 @@ extension LoopDataManager {
10361036

10371037
private func calculateAndEnactMicroBolusIfNeeded() {
10381038
guard settings.dosingEnabled && settings.microbolusesEnabled else {
1039-
logger.debug("Closed loop or microboluses disabled. Cancel micro bolus calculation.")
1039+
logger.debug("Closed loop or microboluses disabled. Cancel microbolus calculation.")
10401040
return
10411041
}
10421042

10431043
let startDate = Date()
10441044

1045-
guard let lastDate = lastMicroBolusDate, startDate.timeIntervalSince(lastDate) > 3 * 60 else {
1045+
guard startDate.timeIntervalSince(lastMicroBolusDate) >= 3 * 60 else {
10461046
logger.debug("Last microbolus enacted less then 3 min ago. Cancel calculation")
10471047
return
10481048
}
10491049

10501050
guard let currentBasalRate = basalRateScheduleApplyingOverrideHistory?.value(at: startDate)
10511051
else {
1052-
logger.debug("Basal rates not configured. Cancel micro bolus calculation.")
1052+
logger.debug("Basal rates not configured. Cancel microbolus calculation.")
10531053
return
10541054
}
10551055

@@ -1066,15 +1066,15 @@ extension LoopDataManager {
10661066

10671067
let microBolus = volumeRounder(min(insulinReq / 2, maxMicroBolus))
10681068
let recomendation = (amount: microBolus, date: startDate)
1069-
logger.debug("Enact micro bolus: \(String(describing: recommendedBolus))")
1069+
logger.debug("Enact microbolus: \(String(describing: recommendedBolus))")
10701070

10711071
lastMicroBolusDate = startDate
10721072
dataAccessQueue.async {
10731073
self.delegate?.loopDataManager(self, didRecommendMicroBolus: recomendation) { [weak self] error in
10741074
if let error = error {
1075-
self?.logger.debug("Micro bolus failed: \(error.localizedDescription)")
1075+
self?.logger.debug("Microbolus failed: \(error.localizedDescription)")
10761076
} else {
1077-
self?.logger.debug("Micro bolus enacted")
1077+
self?.logger.debug("Microbolus enacted")
10781078
}
10791079
}
10801080
}

Loop/View Controllers/StatusTableViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,16 @@ final class StatusTableViewController: ChartsTableViewController {
11141114
}
11151115
}
11161116
}
1117+
1118+
let allClosedLoopFeatures =
1119+
deviceManager.loopManager.settings.dosingEnabled
1120+
&& deviceManager.loopManager.settings.microbolusesEnabled
1121+
11171122
deviceManager.loopManager.addCarbEntryAndRecommendBolus(updatedEntry) { (result) -> Void in
11181123
DispatchQueue.main.async {
11191124
switch result {
11201125
case .success(let recommendation):
1126+
guard !allClosedLoopFeatures else { return }
11211127
if self.active && self.visible, let bolus = recommendation?.amount, bolus > 0 {
11221128
self.performSegue(withIdentifier: BolusViewController.className, sender: recommendation)
11231129
}

0 commit comments

Comments
 (0)