Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updating LoopKit to 0.6.0.
Preventing a loop from starting if reservoir data is bad and history fetch fails.

Fixes #142
Fixes #134
Fixes #24
  • Loading branch information
loudnate committed Aug 31, 2016
commit 47c8ba92a89d14f3c3c7bdaba46fec63866ba2d4
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "loudnate/LoopKit" ~> 0.5.1
github "loudnate/LoopKit" ~> 0.6.0
github "loudnate/xDripG5" ~> 0.6.0
github "loudnate/SwiftCharts" "loudnate/naterade"
github "mddub/dexcom-share-client-swift" ~> 0.1
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "amplitude/Amplitude-iOS" "v3.8.4"
github "loudnate/Crypto" "13fee45175b88629aeabe60b4b4fc3daf86fa0a3"
github "mddub/G4ShareSpy" "v0.2.2"
github "loudnate/LoopKit" "v0.5.1"
github "loudnate/LoopKit" "v0.6.0"
github "loudnate/SwiftCharts" "8671287afb29640f9cffced6521b1098b7aac085"
github "mddub/dexcom-share-client-swift" "v0.1.3"
github "loudnate/xDripG5" "v0.6.0"
Expand Down
Binary file modified Carthage/Build/iOS/CarbKit.framework/CarbKit
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Carthage/Build/iOS/CarbKit.framework/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Carthage/Build/iOS/GlucoseKit.framework/GlucoseKit
Binary file not shown.
Binary file modified Carthage/Build/iOS/GlucoseKit.framework/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Carthage/Build/iOS/InsulinKit.framework/Info.plist
Binary file not shown.
Binary file modified Carthage/Build/iOS/InsulinKit.framework/InsulinKit
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Carthage/Build/iOS/LoopKit.framework/Assets.car
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions Carthage/Build/iOS/LoopKit.framework/Headers/LoopKit-Swift.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Carthage/Build/iOS/LoopKit.framework/Info.plist
Binary file not shown.
Binary file modified Carthage/Build/iOS/LoopKit.framework/LoopKit
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Carthage/Build/iOS/LoopKit.framework/TextFieldTableViewCell.nib
Binary file not shown.
4 changes: 2 additions & 2 deletions Loop/Extensions/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
extension UIColor {
@nonobjc static var tintColor: UIColor? = nil

@nonobjc static let secondaryLabelColor = UIColor(red: 142 / 255, green: 142 / 255, blue: 147 / 255, alpha: 1)
@nonobjc static let secondaryLabelColor = UIColor.HIGGrayColor()

@nonobjc static let gridColor = UIColor(white: 193 / 255, alpha: 1)

Expand All @@ -30,7 +30,7 @@ extension UIColor {

@nonobjc static let staleColor = UIColor.HIGRedColor()

@nonobjc static let unknownColor = UIColor.HIGGrayColor().colorWithAlphaComponent(0.5)
@nonobjc static let unknownColor = UIColor(red: 198 / 255, green: 199 / 255, blue: 201 / 255, alpha: 1)

@nonobjc static let deleteColor = UIColor.HIGRedColor()

Expand Down
68 changes: 38 additions & 30 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter
}

if self.preferredInsulinDataSource == .pumpHistory || !areStoredValuesContinuous {
self.fetchPumpHistory()
self.fetchPumpHistory { (error) in
// Notify and trigger a loop as long as we have fresh, reliable pump data.
if error == nil || areStoredValuesContinuous {
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
}
}
} else {
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
}
Expand All @@ -263,6 +268,38 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter
}
}


/**
Polls the pump for new history events and stores them.

- parameter completion: A closure called after the fetch is complete. This closure takes a single argument:
- error: An error describing why the fetch and/or store failed
*/
private func fetchPumpHistory(completionHandler: (error: ErrorType?) -> Void) {
guard let device = rileyLinkManager.firstConnectedDevice else {
return
}

let startDate = doseStore.pumpEventQueryAfterDate

device.ops?.getHistoryEventsSinceDate(startDate) { (result) in
switch result {
case let .Success(events, _):
self.doseStore.add(events) { (error) in
if let error = error {
self.logger.addError("Failed to store history: \(error)", fromSource: "DoseStore")
}

completionHandler(error: error)
}
case .Failure(let error):
self.logger.addError("Failed to fetch history: \(error)", fromSource: "RileyLink")

completionHandler(error: error)
}
}
}

/**
Read the pump's current state, including reservoir and clock

Expand Down Expand Up @@ -326,35 +363,6 @@ final class DeviceDataManager: CarbStoreDelegate, DoseStoreDelegate, Transmitter
}
}

/**
Polls the pump for new history events
*/
private func fetchPumpHistory() {
guard let device = rileyLinkManager.firstConnectedDevice else {
return
}

let startDate = doseStore.pumpEventQueryAfterDate

device.ops?.getHistoryEventsSinceDate(startDate) { (result) in
switch result {
case let .Success(events, _):
self.doseStore.add(events) { (error) in
if let error = error {
self.logger.addError("Failed to store history: \(error)", fromSource: "DoseStore")
}
}

NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
case .Failure(let error):
self.logger.addError("Failed to fetch history: \(error)", fromSource: "RileyLink")

// Continue with the loop anyway
NSNotificationCenter.defaultCenter().postNotificationName(self.dynamicType.PumpStatusUpdatedNotification, object: self)
}
}
}

/**
Send a bolus command and handle the result

Expand Down