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
43 changes: 35 additions & 8 deletions OmniKit/OmnipodCommon/Pod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public struct Pod {
public static let reservoirCapacity: Double = 200

// Supported basal rates
// Eros minimum scheduled basal rate is 0.05 U/H while for Dash supports 0 U/H.
// Would need to have this value based on productID to be able to share this with Eros.
// Eros minimum scheduled basal rate is 0.05 U/hr while Dash supports 0 U/hr.
public static let supportedBasalRates: [Double] = (1...600).map { Double($0) / Double(pulsesPerUnit) }

// Supported temp basal rates
// Both Eros and Dash support a minimum temp basal rate of 0 U/hr.
public static let supportedTempBasalRates: [Double] = (0...600).map { Double($0) / Double(pulsesPerUnit) }

// The internal basal rate used for non-Eros pods
// Would need to have this value based on productID to be able to share this file with Eros.
// The internal basal rate used for zero basal rates
// Eros uses 0.0 while Dash uses a near zero rate
public static let zeroBasalRate: Double = 0.0

// Maximum number of basal schedule entries supported
Expand Down Expand Up @@ -113,19 +113,46 @@ public enum DeliveryStatus: UInt8, CustomStringConvertible {
case extendedBolusAndTempBasal = 10

public var suspended: Bool {
return self == .suspended || self == .priming || self == .extendedBolusWhileSuspended
// returns true if both the tempBasal and basal bits are clear
let suspendedStates: Set<DeliveryStatus> = [
.suspended,
.priming,
.extendedBolusWhileSuspended,
]
return suspendedStates.contains(self)
}

public var bolusing: Bool {
return self == .bolusInProgress || self == .bolusAndTempBasal || self == .extendedBolusRunning || self == .extendedBolusAndTempBasal || self == .priming || self == .extendedBolusWhileSuspended
// returns true if either the immediateBolus or extendedBolus bits are set
let bolusingStates: Set<DeliveryStatus> = [
.priming,
.bolusInProgress,
.bolusAndTempBasal,
.extendedBolusWhileSuspended,
.extendedBolusRunning,
.extendedBolusAndTempBasal,
]
return bolusingStates.contains(self)
}

public var tempBasalRunning: Bool {
return self == .tempBasalRunning || self == .bolusAndTempBasal || self == .extendedBolusAndTempBasal
// returns true if the tempBasal bit is set
let tempBasalRunningStates: Set<DeliveryStatus> = [
.tempBasalRunning,
.bolusAndTempBasal,
.extendedBolusAndTempBasal,
]
return tempBasalRunningStates.contains(self)
}

public var extendedBolusRunning: Bool {
return self == .extendedBolusRunning || self == .extendedBolusAndTempBasal || self == .extendedBolusWhileSuspended
// returns true if the extendedBolus bit is set
let extendedBolusRunningStates: Set<DeliveryStatus> = [
.extendedBolusWhileSuspended,
.extendedBolusRunning,
.extendedBolusAndTempBasal,
]
return extendedBolusRunningStates.contains(self)
}

public var description: String {
Expand Down
6 changes: 2 additions & 4 deletions OmniKit/PumpManager/OmnipodPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ extension OmnipodPumpManager: PumpManager {
})

if let podState = self.state.podState, podState.isSuspended || podState.lastDeliveryStatusReceived?.suspended == true {
self.log.error("Not enacting bolus because podState or last status received indicates pod is suspended")
self.log.info("Not enacting bolus because podState or last status received indicates pod is suspended")
completion(.deviceState(PodCommsError.podSuspended))
return
}
Expand Down Expand Up @@ -2053,7 +2053,7 @@ extension OmnipodPumpManager: PumpManager {
return
}

guard status.deliveryStatus != .suspended else {
guard !status.deliveryStatus.suspended else {
self.log.info("Canceling temp basal because status return indicates pod is suspended!")
completion(.communication(PodCommsError.podSuspended))
return
Expand Down Expand Up @@ -2448,12 +2448,10 @@ extension OmnipodPumpManager: PumpManager {

extension OmnipodPumpManager: MessageLogger {
func didSend(_ message: Data) {
log.default("didSend: %{public}@", message.hexadecimalString)
self.logDeviceCommunication(message.hexadecimalString, type: .send)
}

func didReceive(_ message: Data) {
log.default("didReceive: %{public}@", message.hexadecimalString)
self.logDeviceCommunication(message.hexadecimalString, type: .receive)
}

Expand Down
6 changes: 4 additions & 2 deletions OmniKit/PumpManager/PodState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl
if deliveryStatus.tempBasalRunning && unfinalizedTempBasal == nil { // active temp basal that we aren't tracking
// unfinalizedTempBasal = UnfinalizedDose(tempBasalRate: 0, startTime: Date(), duration: .minutes(30), isHighTemp: false, scheduledCertainty: .certain, insulinType: insulinType)
}
if deliveryStatus != .suspended && isSuspended { // active basal that we aren't tracking
if !deliveryStatus.suspended && isSuspended { // active basal that we aren't tracking
let resumeStartTime = Date()
suspendState = .resumed(resumeStartTime)
unfinalizedResume = UnfinalizedDose(resumeStartTime: resumeStartTime, scheduledCertainty: .certain, insulinType: insulinType)
Expand Down Expand Up @@ -555,7 +555,7 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl
"* expiresAt: \(String(reflecting: expiresAt))",
"* podTime: \(podTime.timeIntervalStr)",
"* podTimeUpdated: \(String(reflecting: podTimeUpdated))",
"* setupUnitsDelivered: \(String(reflecting: setupUnitsDelivered))",
"* setupUnitsDelivered: \(setupUnitsDelivered == nil ? "?" : setupUnitsDelivered!.twoDecimals) U",
"* piVersion: \(piVersion)",
"* pmVersion: \(pmVersion)",
"* lot: \(lot)",
Expand All @@ -568,6 +568,8 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl
"* unfinalizedResume: \(String(describing: unfinalizedResume))",
"* finalizedDoses: \(String(describing: finalizedDoses))",
"* activeAlertsSlots: \(alertSetString(alertSet: activeAlertSlots))",
"* delivered: \(lastInsulinMeasurements == nil ? "?" : lastInsulinMeasurements!.delivered.twoDecimals) U",
"* reservoirLevel: \(lastInsulinMeasurements == nil || lastInsulinMeasurements!.reservoirLevel == nil || lastInsulinMeasurements!.reservoirLevel == Pod.reservoirLevelAboveThresholdMagicNumber ? "50+" : lastInsulinMeasurements!.reservoirLevel!.twoDecimals) U",
"* messageTransportState: \(String(describing: messageTransportState))",
"* setupProgress: \(setupProgress)",
"* primeFinishTime: \(String(describing: primeFinishTime))",
Expand Down