Pod.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Pod.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 4/4/18.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct Pod {
  10. // Volume of U100 insulin in one motor pulse
  11. // Must agree with value returned by pod during the pairing process.
  12. public static let pulseSize: Double = 0.05
  13. // Number of pulses required to deliver one unit of U100 insulin
  14. public static let pulsesPerUnit: Double = 1 / Pod.pulseSize
  15. // Seconds per pulse for boluses
  16. // Checked to verify it agrees with value returned by pod during the pairing process.
  17. public static let secondsPerBolusPulse: Double = 2
  18. // Units per second for boluses
  19. public static let bolusDeliveryRate: Double = Pod.pulseSize / Pod.secondsPerBolusPulse
  20. // Seconds per pulse for priming/cannula insertion
  21. // Checked to verify it agrees with value returned by pod during the pairing process.
  22. public static let secondsPerPrimePulse: Double = 1
  23. // Units per second for priming/cannula insertion
  24. public static let primeDeliveryRate: Double = Pod.pulseSize / Pod.secondsPerPrimePulse
  25. // User configured time before expiration advisory (PDM allows 1-24 hours)
  26. public static let expirationAlertWindow = TimeInterval(hours: 2)
  27. // Expiration advisory window: time after expiration alert, and end of service imminent alarm
  28. public static let expirationAdvisoryWindow = TimeInterval(hours: 7)
  29. // End of service imminent window, relative to pod end of service
  30. public static let endOfServiceImminentWindow = TimeInterval(hours: 1)
  31. // Total pod service time. A fault is triggered if this time is reached before pod deactivation.
  32. // Checked to verify it agrees with value returned by pod during the pairing process.
  33. public static let serviceDuration = TimeInterval(hours: 80)
  34. // Nomimal pod life (72 hours)
  35. public static let nominalPodLife = Pod.serviceDuration - Pod.endOfServiceImminentWindow - Pod.expirationAdvisoryWindow
  36. // Maximum reservoir level reading
  37. public static let maximumReservoirReading: Double = 50
  38. // Reservoir Capacity
  39. public static let reservoirCapacity: Double = 200
  40. // Supported basal rates
  41. public static let supportedBasalRates: [Double] = (1...600).map { Double($0) / Double(pulsesPerUnit) }
  42. // Maximum number of basal schedule entries supported
  43. public static let maximumBasalScheduleEntryCount: Int = 24
  44. // Minimum duration of a single basal schedule entry
  45. public static let minimumBasalScheduleEntryDuration = TimeInterval.minutes(30)
  46. // Default amount for priming bolus using secondsPerPrimePulse timing.
  47. // Checked to verify it agrees with value returned by pod during the pairing process.
  48. public static let primeUnits = 2.6
  49. // Default amount for cannula insertion bolus using secondsPerPrimePulse timing.
  50. // Checked to verify it agrees with value returned by pod during the pairing process.
  51. public static let cannulaInsertionUnits = 0.5
  52. public static let cannulaInsertionUnitsExtra = 0.0 // edit to add a fixed additional amount of insulin during cannula insertion
  53. // Default and limits for expiration reminder alerts
  54. public static let expirationReminderAlertDefaultTimeBeforeExpiration = TimeInterval.hours(2)
  55. public static let expirationReminderAlertMinTimeBeforeExpiration = TimeInterval.hours(1)
  56. public static let expirationReminderAlertMaxTimeBeforeExpiration = TimeInterval.hours(24)
  57. }
  58. // DeliveryStatus used in StatusResponse and DetailedStatus
  59. public enum DeliveryStatus: UInt8, CustomStringConvertible {
  60. case suspended = 0
  61. case scheduledBasal = 1
  62. case tempBasalRunning = 2
  63. case priming = 4
  64. case bolusInProgress = 5
  65. case bolusAndTempBasal = 6
  66. public var bolusing: Bool {
  67. return self == .bolusInProgress || self == .bolusAndTempBasal
  68. }
  69. public var tempBasalRunning: Bool {
  70. return self == .tempBasalRunning || self == .bolusAndTempBasal
  71. }
  72. public var description: String {
  73. switch self {
  74. case .suspended:
  75. return LocalizedString("Suspended", comment: "Delivery status when insulin delivery is suspended")
  76. case .scheduledBasal:
  77. return LocalizedString("Scheduled basal", comment: "Delivery status when scheduled basal is running")
  78. case .tempBasalRunning:
  79. return LocalizedString("Temp basal running", comment: "Delivery status when temp basal is running")
  80. case .priming:
  81. return LocalizedString("Priming", comment: "Delivery status when pod is priming")
  82. case .bolusInProgress:
  83. return LocalizedString("Bolusing", comment: "Delivery status when bolusing")
  84. case .bolusAndTempBasal:
  85. return LocalizedString("Bolusing with temp basal", comment: "Delivery status when bolusing and temp basal is running")
  86. }
  87. }
  88. }