@@ -14,10 +14,20 @@ import MinimedKit
1414
1515
1616class LoopDataManager {
17+ enum LoopUpdateContext : Int {
18+ case Bolus
19+ case Carbs
20+ case Glucose
21+ case Preferences
22+ case TempBasal
23+ }
24+
1725 static let LoopDataUpdatedNotification = " com.loudnate.Naterade.notification.LoopDataUpdated "
1826
1927 static let LoopRunningNotification = " com.loudnate.Naterade.notification.LoopRunning "
2028
29+ static let LoopUpdateContextKey = " com.loudnate.Loop.LoopDataManager.LoopUpdateContext "
30+
2131 typealias TempBasalRecommendation = ( recommendedDate: NSDate , rate: Double , duration: NSTimeInterval )
2232
2333 unowned let deviceDataManager : DeviceDataManager
@@ -26,7 +36,7 @@ class LoopDataManager {
2636 didSet {
2737 NSUserDefaults . standardUserDefaults ( ) . dosingEnabled = dosingEnabled
2838
29- notify ( )
39+ notify ( forChange : . Preferences )
3040 }
3141 }
3242
@@ -47,7 +57,7 @@ class LoopDataManager {
4757 center. addObserverForName ( DeviceDataManager . GlucoseUpdatedNotification, object: deviceDataManager, queue: nil ) { ( note) -> Void in
4858 dispatch_async ( self . dataAccessQueue) {
4959 self . glucoseMomentumEffect = nil
50- self . notify ( )
60+ self . notify ( forChange : . Glucose )
5161 }
5262 } ,
5363 center. addObserverForName ( DeviceDataManager . PumpStatusUpdatedNotification, object: deviceDataManager, queue: nil ) { ( note) -> Void in
@@ -61,7 +71,7 @@ class LoopDataManager {
6171 notificationObservers. append ( center. addObserverForName ( CarbStore . CarbEntriesDidUpdateNotification, object: nil , queue: nil ) { ( note) -> Void in
6272 dispatch_async ( self . dataAccessQueue) {
6373 self . carbEffect = nil
64- self . notify ( )
74+ self . notify ( forChange : . Carbs )
6575 }
6676 } )
6777 }
@@ -84,7 +94,7 @@ class LoopDataManager {
8494 self . lastLoopCompleted = NSDate ( )
8595 }
8696
87- self . notify ( )
97+ self . notify ( forChange : . TempBasal )
8898 }
8999
90100 // Delay the notification until we know the result of the temp basal
@@ -96,7 +106,7 @@ class LoopDataManager {
96106 lastLoopError = error
97107 }
98108
99- notify ( )
109+ notify ( forChange : . TempBasal )
100110 }
101111
102112 // References to registered notification center observers
@@ -160,8 +170,11 @@ class LoopDataManager {
160170 }
161171 }
162172
163- private func notify( ) {
164- NSNotificationCenter . defaultCenter ( ) . postNotificationName ( self . dynamicType. LoopDataUpdatedNotification, object: self )
173+ private func notify( forChange context: LoopUpdateContext ) {
174+ NSNotificationCenter . defaultCenter ( ) . postNotificationName ( self . dynamicType. LoopDataUpdatedNotification,
175+ object: self ,
176+ userInfo: [ self . dynamicType. LoopUpdateContextKey: context. rawValue]
177+ )
165178 }
166179
167180 /**
@@ -481,7 +494,7 @@ class LoopDataManager {
481494 func recordBolus( units: Double , atDate date: NSDate ) {
482495 dispatch_async ( dataAccessQueue) {
483496 self . lastBolus = ( units: units, date: date)
484- self . notify ( )
497+ self . notify ( forChange : . Bolus )
485498 }
486499 }
487500}
0 commit comments