Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Common/Models/StatusExtensionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct LoopContext {
struct NetBasalContext {
let rate: Double
let percentage: Double
let startDate: Date
let start: Date
let end: Date
}

struct SensorDisplayableContext: SensorDisplayable {
Expand Down Expand Up @@ -122,22 +123,25 @@ extension NetBasalContext: RawRepresentable {
return [
"rate": rate,
"percentage": percentage,
"startDate": startDate
"start": start,
"end": end
]
}

init?(rawValue: RawValue) {
guard
let rate = rawValue["rate"] as? Double,
let percentage = rawValue["percentage"] as? Double,
let startDate = rawValue["startDate"] as? Date
let start = rawValue["start"] as? Date,
let end = rawValue["end"] as? Date
else {
return nil
}

self.rate = rate
self.percentage = percentage
self.startDate = startDate
self.start = start
self.end = end
}
}

Expand Down
2 changes: 1 addition & 1 deletion Loop Status Extension/StatusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class StatusViewController: UIViewController, NCWidgetProviding {
}

if let netBasal = context.netBasal {
basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percentage, at: netBasal.startDate)
basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percentage, at: netBasal.start)
}

if let loop = context.loop {
Expand Down
4 changes: 4 additions & 0 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
432E73CB1D24B3D6009AD15D /* RemoteDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 432E73CA1D24B3D6009AD15D /* RemoteDataManager.swift */; };
433EA4C21D9F39C900CD78FB /* PumpIDTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433EA4C11D9F39C900CD78FB /* PumpIDTableViewController.swift */; };
433EA4C41D9F71C800CD78FB /* CommandResponseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */; };
43441A9C1EDB34810087958C /* StatusExtensionContext+LoopKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43441A9B1EDB34810087958C /* StatusExtensionContext+LoopKit.swift */; };
4346D1E71C77F5FE00ABAFE3 /* ChartTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4346D1E61C77F5FE00ABAFE3 /* ChartTableViewCell.swift */; };
4346D1F61C78501000ABAFE3 /* ChartPoint+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4346D1F51C78501000ABAFE3 /* ChartPoint+Loop.swift */; };
434F54571D287FDB002A9274 /* NibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 434F54561D287FDB002A9274 /* NibLoadable.swift */; };
Expand Down Expand Up @@ -377,6 +378,7 @@
4337615E1D52F487004A3647 /* GlucoseHUDView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlucoseHUDView.swift; sourceTree = "<group>"; };
433EA4C11D9F39C900CD78FB /* PumpIDTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PumpIDTableViewController.swift; sourceTree = "<group>"; };
433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandResponseViewController.swift; sourceTree = "<group>"; };
43441A9B1EDB34810087958C /* StatusExtensionContext+LoopKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatusExtensionContext+LoopKit.swift"; sourceTree = "<group>"; };
4346D1E61C77F5FE00ABAFE3 /* ChartTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartTableViewCell.swift; sourceTree = "<group>"; };
4346D1EF1C781BEA00ABAFE3 /* SwiftCharts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCharts.framework; path = Carthage/Build/iOS/SwiftCharts.framework; sourceTree = "<group>"; };
4346D1F51C78501000ABAFE3 /* ChartPoint+Loop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ChartPoint+Loop.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -676,6 +678,7 @@
438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */,
43D848AF1E7DCBE100DADCBC /* Result.swift */,
43C418B41CE0575200405B6A /* ShareGlucose+GlucoseKit.swift */,
43441A9B1EDB34810087958C /* StatusExtensionContext+LoopKit.swift */,
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
);
path = Models;
Expand Down Expand Up @@ -1429,6 +1432,7 @@
C17824A51E1AD4D100D9D25C /* BolusRecommendation.swift in Sources */,
4F70C2131DE90339006380B7 /* StatusExtensionContext.swift in Sources */,
434F54571D287FDB002A9274 /* NibLoadable.swift in Sources */,
43441A9C1EDB34810087958C /* StatusExtensionContext+LoopKit.swift in Sources */,
4FF4D1001E18374700846527 /* WatchContext.swift in Sources */,
4315D28A1CA5F45E00589052 /* DiagnosticLogger+LoopKit.swift in Sources */,
43C418B51CE0575200405B6A /* ShareGlucose+GlucoseKit.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ final class DeviceDataManager {
statusExtensionManager = StatusExtensionDataManager(deviceDataManager: self)
loopManager = LoopDataManager(
delegate: self,
lastLoopCompleted: statusExtensionManager.context?.loop?.lastCompleted
lastLoopCompleted: statusExtensionManager.context?.loop?.lastCompleted,
lastTempBasal: statusExtensionManager.context?.netBasal?.tempBasal
)
watchManager = WatchDataManager(deviceDataManager: self)
nightscoutDataManager = NightscoutDataManager(deviceDataManager: self)
Expand Down
2 changes: 2 additions & 0 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final class LoopDataManager {
init(
delegate: LoopDataManagerDelegate,
lastLoopCompleted: Date?,
lastTempBasal: DoseEntry?,
basalRateSchedule: BasalRateSchedule? = UserDefaults.standard.basalRateSchedule,
carbRatioSchedule: CarbRatioSchedule? = UserDefaults.standard.carbRatioSchedule,
insulinActionDuration: TimeInterval? = UserDefaults.standard.insulinActionDuration,
Expand All @@ -50,6 +51,7 @@ final class LoopDataManager {
) {
self.delegate = delegate
self.lastLoopCompleted = lastLoopCompleted
self.lastTempBasal = lastTempBasal
self.settings = settings

carbStore = CarbStore(
Expand Down
7 changes: 4 additions & 3 deletions Loop/Managers/StatusExtensionDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ final class StatusExtensionDataManager {
context.netBasal = NetBasalContext(
rate: 2.1,
percentage: 0.6,
startDate:
Date(timeIntervalSinceNow: -250)
start:
Date(timeIntervalSinceNow: -250),
end: Date(timeIntervalSinceNow: .minutes(30))
)
context.predictedGlucose = PredictedGlucoseContext(
values: (1...36).map { 89.123 + Double($0 * 5) }, // 3 hours of linear data
Expand Down Expand Up @@ -120,7 +121,7 @@ final class StatusExtensionDataManager {
scheduledBasal: scheduledBasal
)

context.netBasal = NetBasalContext(rate: netBasal.rate, percentage: netBasal.percent, startDate: netBasal.startDate)
context.netBasal = NetBasalContext(rate: netBasal.rate, percentage: netBasal.percent, start: netBasal.start, end: netBasal.end)
}

if let reservoir = manager.doseStore.lastReservoirValue,
Expand Down
12 changes: 8 additions & 4 deletions Loop/Models/NetBasal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import LoopKit
struct NetBasal {
let rate: Double
let percent: Double
let startDate: Date
let start: Date
let end: Date

init(lastTempBasal: DoseEntry?, maxBasal: Double?, scheduledBasal: AbsoluteScheduleValue<Double>) {
if let lastTempBasal = lastTempBasal, lastTempBasal.endDate > Date(), let maxBasal = maxBasal {
rate = lastTempBasal.unitsPerHour - scheduledBasal.value
startDate = lastTempBasal.startDate
start = lastTempBasal.startDate
end = lastTempBasal.endDate

if rate < 0 {
percent = rate / scheduledBasal.value
Expand All @@ -30,9 +32,11 @@ struct NetBasal {
percent = 0

if let lastTempBasal = lastTempBasal, lastTempBasal.endDate > scheduledBasal.startDate {
startDate = lastTempBasal.endDate
start = lastTempBasal.endDate
end = scheduledBasal.endDate
} else {
startDate = scheduledBasal.startDate
start = scheduledBasal.startDate
end = scheduledBasal.endDate
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions Loop/Models/StatusExtensionContext+LoopKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// StatusExtensionContext+LoopKit.swift
// Loop
//
// Copyright © 2017 LoopKit Authors. All rights reserved.
//

import InsulinKit

extension NetBasalContext {
var tempBasal: DoseEntry? {
guard rate != 0 else {
return nil
}

return DoseEntry(
type: .tempBasal,
startDate: start,
endDate: end,
value: rate,
unit: .unitsPerHour
)
}
}
2 changes: 1 addition & 1 deletion Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ final class StatusTableViewController: ChartsTableViewController {
scheduledBasal: scheduledBasal
)

self.hudView.basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percent, at: netBasal.startDate)
self.hudView.basalRateHUD.setNetBasalRate(netBasal.rate, percent: netBasal.percent, at: netBasal.start)
}

// Fetch the current IOB subtitle
Expand Down