Skip to content

Commit

Permalink
On pod fault display Pod expired/Empty reservoir/Occlusion detected/f…
Browse files Browse the repository at this point in the history
…ault code (#514)

* On pod fault say Pod expired/Empty reservoir/Occlusion detected/hex code

* Reworked to have PodReplacementReason.fault case contain the fault type

* Have .fault case now store FaultEventCode, print miscellaneous fault values in decimal

* Reworked to make rawType on FaultEventCode public so all pod faults can be simply printed, fix long-standing typo (setup -> set up)

* Use faultCode.localizedDescription to provide the fault code description for the user
  • Loading branch information
itsmojo authored and ps2 committed Apr 12, 2019
1 parent 8cd707a commit 60e3232
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
22 changes: 21 additions & 1 deletion OmniKit/Model/FaultEventCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation


public struct FaultEventCode: CustomStringConvertible, Equatable {
let rawValue: UInt8
public let rawValue: UInt8

public enum FaultEventType: UInt8 {
case noFaults = 0x00
Expand Down Expand Up @@ -387,4 +387,24 @@ public struct FaultEventCode: CustomStringConvertible, Equatable {
}
return String(format: "Fault Event Code 0x%02x: %@", rawValue, faultDescription)
}

public var localizedDescription: String {
if let faultType = faultType {
switch faultType {
case .reservoirEmpty:
return LocalizedString("Empty reservoir", comment: "Description for Empty reservoir pod fault")
case .exceededMaximumPodLife80Hrs:
return LocalizedString("Pod expired", comment: "Description for Pod expired pod fault")
case .occluded,
.occlusionCheckValueTooHigh, .occlusionCheckStartup1, .occlusionCheckStartup2,
.occlusionCheckTimeouts1, .occlusionCheckTimeouts2, .occlusionCheckTimeouts3,
.occlusionCheckPulseIssue, .occlusionCheckBolusProblem, .occlusionCheckAboveThreshold:
return LocalizedString("Occlusion detected", comment: "Description for Occlusion detected pod fault")
default:
return String(format: LocalizedString("Internal pod fault %1$03d", comment: "The format string for Internal pod fault (1: The fault code value)"), rawValue)
}
} else {
return String(format: LocalizedString("Unknown pod fault %1$03d", comment: "The format string for Unknown pod fault (1: The fault code value)"), rawValue)
}
}
}
31 changes: 14 additions & 17 deletions OmniKitUI/ViewControllers/ReplacePodViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,34 @@ class ReplacePodViewController: SetupTableViewController {

enum PodReplacementReason {
case normal
case fault
case fault(_ faultCode: FaultEventCode)
case canceledPairingBeforeApplication
case canceledPairing
}

var replacementReason: PodReplacementReason = .normal {
didSet {
if oldValue != replacementReason {
switch replacementReason {
case .normal:
break // Text set in interface builder
case .fault:
instructionsLabel.text = LocalizedString("The pod has detected an internal fault. Insulin delivery has stopped. Please remove pod and then deactivate it.", comment: "Instructions when replacing pod due to a fault")
case .canceledPairingBeforeApplication:
instructionsLabel.text = LocalizedString("Incompletely setup pod must be deactivated before pairing with a new one. Deactivate and discard pod.", comment: "Instructions when deactivating pod that has been paired, but not attached.")
case .canceledPairing:
instructionsLabel.text = LocalizedString("Incompletely setup pod must be deactivated before pairing with a new one. Please remove the pod and then deactivate it.", comment: "Instructions when deactivating pod that has been paired and possibly attached.")
break
}

tableView.reloadData()
switch replacementReason {
case .normal:
break // Text set in interface builder
case .fault(let faultCode):
instructionsLabel.text = String(format: LocalizedString("%1$@. Insulin delivery has stopped. Please deactivate and remove pod.", comment: "Format string providing instructions for replacing pod due to a fault. (1: The fault description)"), faultCode.localizedDescription)
case .canceledPairingBeforeApplication:
instructionsLabel.text = LocalizedString("Incompletely set up pod must be deactivated before pairing with a new one. Please deactivate and discard pod.", comment: "Instructions when deactivating pod that has been paired, but not attached.")
case .canceledPairing:
instructionsLabel.text = LocalizedString("Incompletely set up pod must be deactivated before pairing with a new one. Please deactivate and remove pod.", comment: "Instructions when deactivating pod that has been paired and possibly attached.")
}

tableView.reloadData()
}
}

var pumpManager: OmnipodPumpManager! {
didSet {
pumpManager.getPodState { (podState) in
DispatchQueue.main.async {
if podState?.fault != nil {
self.replacementReason = .fault
if let podFault = podState?.fault {
self.replacementReason = .fault(podFault.currentStatus)
} else if podState?.setupProgress.primingNeeded == true {
self.replacementReason = .canceledPairingBeforeApplication
} else if podState?.setupProgress.needsCannulaInsertion == true {
Expand Down

0 comments on commit 60e3232

Please sign in to comment.