Skip to content

Conversation

@jlucasvt
Copy link
Contributor

Update to allow x22 pumps to display the Reservoir Status in the HUD. Added PumpModel.swift Extension, Updated Logic and Tested Values and Display.

jlucasvt added 2 commits July 17, 2016 06:19
This branch commit encapsulates the Update to allow x22 pumps to
display the Reservoir Status in the HUD.  Added PumpMode.swift
Extension, Updated Logic and tested values.
Added BIOB Value for x22 pumps from IOB Calculated Decay from dosestore.
@jlucasvt
Copy link
Contributor Author

I also added the x22 BIoB value from the Chart Decay

@loudnate
Copy link
Collaborator

That's not bolus IOB, that's net IOB.

@loudnate
Copy link
Collaborator

The first commit looks good, but the second one is displaying incorrect data. Please resubmit with just the reservoir change.

} else {
cell.detailTextLabel?.text = emptyValueString
//x22 BIoB Value from IOB Chart Decay Data
dataManager.doseStore.getInsulinOnBoardValues(startDate: NSDate(), endDate: NSDate().dateByAddingTimeInterval(300)) { (values, error) -> Void in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tip here: you don't usually want to make asynchronous calls in table data source methods, because you don't own the underlying cell views or control their mapping and reuse. By the time this completion closure executes, the system may have reused the cell for a completely different index path – and your call would be setting label text that's completely out-of-place.

Another issue is that the documentation for getInsulinOnBoardValues states that it executes your completion closure on an arbitrary background queue. You cannot use the vast majority of UIKit APIs (like setting label text) on any queue except the main one, so you'll need to create a dispatch call to the main queue. Using UIKit on a background queue can result in unexpected behavior. At best, that means the label text isn't drawn at all until someone else invokes a display call. At worst, the app can crash.

Finally,

NSDate().dateByAddingTimeInterval(300)

can be more expressively written as

NSDate(timeIntervalSinceNow: NSTimeInterval(minutes: 5))

@jlucasvt
Copy link
Contributor Author

I pulled the Net IOB Code out. Especially if the plan is to move away from text cells in future. Thanks again for the knowledge share.

@loudnate
Copy link
Collaborator

Awesome, thanks! I can squash the the multiple commits into one, single commit. Just be aware that you'll need to re-merge from Loop/dev into your own fork because the commit hash will change.

@loudnate loudnate merged commit 755b4d0 into LoopKit:dev Jul 17, 2016
@jlucasvt jlucasvt deleted the UpdateReservoirStatus branch July 17, 2016 17:36
erikdi pushed a commit to erikdi/Loop that referenced this pull request Feb 10, 2019
Moves the example app to the Carthage project
ps2 pushed a commit that referenced this pull request May 12, 2020
(Put back obsolescent DeviceManagerDelegate code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants