Skip to content

Commit

Permalink
Calculate insertion wait time from Pod cannulaInsertionUnits constant (
Browse files Browse the repository at this point in the history
…#567)

* Calculate insertion wait time from Pod cannulaInsertionUnits constant

* New primeDeliveryRate, secondsPerPrimePulse & secondsPerBolusPulse constants
  • Loading branch information
itsmojo authored and ps2 committed Dec 7, 2019
1 parent 26931d3 commit 31e8be4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct BolusExtraCommand : MessageBlock {
squareWaveDuration = timeBetweenExtendedPulses * Double(pulseCountX10) / 10
}

public init(units: Double, timeBetweenPulses: TimeInterval = 2, squareWaveUnits: Double = 0.0, squareWaveDuration: TimeInterval = 0, acknowledgementBeep: Bool = false, completionBeep: Bool = false, programReminderInterval: TimeInterval = 0) {
public init(units: Double, timeBetweenPulses: TimeInterval = Pod.secondsPerBolusPulse, squareWaveUnits: Double = 0.0, squareWaveDuration: TimeInterval = 0, acknowledgementBeep: Bool = false, completionBeep: Bool = false, programReminderInterval: TimeInterval = 0) {
self.acknowledgementBeep = acknowledgementBeep
self.completionBeep = completionBeep
self.programReminderInterval = programReminderInterval
Expand Down
15 changes: 12 additions & 3 deletions OmniKit/Model/Pod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ public struct Pod {
public static let pulseSize: Double = 0.05

// Number of pulses required to deliver one unit of insulin
public static let pulsesPerUnit: Double = 20
public static let pulsesPerUnit: Double = 1 / Pod.pulseSize

// Units per second
public static let bolusDeliveryRate: Double = 0.025
// Seconds per pulse for boluses
public static let secondsPerBolusPulse: Double = 2

// Units per second for boluses
public static let bolusDeliveryRate: Double = Pod.pulseSize / Pod.secondsPerBolusPulse

// Seconds per pulse for priming/cannula insertion
public static let secondsPerPrimePulse: Double = 1

// Units per second for priming/cannula insertion
public static let primeDeliveryRate: Double = Pod.pulseSize / Pod.secondsPerPrimePulse

// User configured time before expiration advisory (PDM allows 1-24 hours)
public static let expirationAlertWindow = TimeInterval(hours: 2)
Expand Down
12 changes: 6 additions & 6 deletions OmniKit/PumpManager/PodCommsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public class PodCommsSession {
public func prime() throws -> TimeInterval {
//4c00 00c8 0102

let primeDuration = TimeInterval(seconds: 55)
let primeDuration = TimeInterval(seconds: 55) // a bit more than (Pod.primeUnits / Pod.primeDeliveryRate)

// Skip following alerts if we've already done them before
if podState.setupProgress != .startingPrime {
Expand All @@ -281,7 +281,7 @@ public class PodCommsSession {
podState.primeFinishTime = primeFinishTime
podState.setupProgress = .startingPrime

let timeBetweenPulses = TimeInterval(seconds: 1)
let timeBetweenPulses = TimeInterval(seconds: Pod.secondsPerPrimePulse)
let bolusSchedule = SetInsulinScheduleCommand.DeliverySchedule.bolus(units: Pod.primeUnits, timeBetweenPulses: timeBetweenPulses)
let scheduleCommand = SetInsulinScheduleCommand(nonce: podState.currentNonce, deliverySchedule: bolusSchedule)
let bolusExtraCommand = BolusExtraCommand(units: Pod.primeUnits, timeBetweenPulses: timeBetweenPulses)
Expand Down Expand Up @@ -336,7 +336,7 @@ public class PodCommsSession {
}

public func insertCannula() throws -> TimeInterval {
let insertionWait: TimeInterval = .seconds(10)
let insertionWait: TimeInterval = .seconds(Pod.cannulaInsertionUnits / Pod.primeDeliveryRate)

guard let activatedAt = podState.activatedAt else {
throw PodCommsError.noPodPaired
Expand Down Expand Up @@ -366,7 +366,7 @@ public class PodCommsSession {

// Mark 0.5U delivery with 1 second between pulses for cannula insertion

let timeBetweenPulses = TimeInterval(seconds: 1)
let timeBetweenPulses = TimeInterval(seconds: Pod.secondsPerPrimePulse)
let bolusSchedule = SetInsulinScheduleCommand.DeliverySchedule.bolus(units: Pod.cannulaInsertionUnits, timeBetweenPulses: timeBetweenPulses)
let bolusScheduleCommand = SetInsulinScheduleCommand(nonce: podState.currentNonce, deliverySchedule: bolusSchedule)

Expand Down Expand Up @@ -405,7 +405,7 @@ public class PodCommsSession {

public func bolus(units: Double, acknowledgementBeep: Bool = false, completionBeep: Bool = false, programReminderInterval: TimeInterval = 0) -> DeliveryCommandResult {

let timeBetweenPulses = TimeInterval(seconds: 2)
let timeBetweenPulses = TimeInterval(seconds: Pod.secondsPerBolusPulse)
let bolusSchedule = SetInsulinScheduleCommand.DeliverySchedule.bolus(units: units, timeBetweenPulses: timeBetweenPulses)
let bolusScheduleCommand = SetInsulinScheduleCommand(nonce: podState.currentNonce, deliverySchedule: bolusSchedule)

Expand All @@ -416,7 +416,7 @@ public class PodCommsSession {
// Between bluetooth and the radio and firmware, about 1.2s on average passes before we start tracking
let commsOffset = TimeInterval(seconds: -1.5)

let bolusExtraCommand = BolusExtraCommand(units: units, acknowledgementBeep: acknowledgementBeep, completionBeep: completionBeep)
let bolusExtraCommand = BolusExtraCommand(units: units, timeBetweenPulses: timeBetweenPulses, acknowledgementBeep: acknowledgementBeep, completionBeep: completionBeep)
do {
let statusResponse: StatusResponse = try send([bolusScheduleCommand, bolusExtraCommand])
podState.unfinalizedBolus = UnfinalizedDose(bolusAmount: units, startTime: Date().addingTimeInterval(commsOffset), scheduledCertainty: .certain)
Expand Down

0 comments on commit 31e8be4

Please sign in to comment.