Procházet zdrojové kódy

Not Looping Alert - In Testing

Jon Fawcett před 6 roky
rodič
revize
55a750f93c

+ 0 - 18
LoopFollow.xcworkspace/xcuserdata/jon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -3,22 +3,4 @@
    uuid = "35B1BDC7-1374-42B0-9D79-1E7D694F0434"
    type = "0"
    version = "2.0">
-   <Breakpoints>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "8B56A574-7A41-46D1-8F41-5B934902B46D"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "LoopFollow/Controllers/MainViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "200"
-            endingLineNumber = "200"
-            landmarkName = "appMovedToBackground()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-   </Breakpoints>
 </Bucket>

+ 1 - 1
LoopFollow/Controllers/AlarmViewController.swift

@@ -164,7 +164,7 @@ class AlarmViewController: FormViewController {
         buildFastDropAlert()
         buildFastRiseAlert()
         buildMissedReadings()
-  //      buildNotLooping()
+        buildNotLooping()
  //       buildMissedBolus()
   //      buildAppInactive()
         buildSage()

+ 27 - 2
LoopFollow/Controllers/MainViewController.swift

@@ -422,6 +422,8 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         // Loop
         if let lastLoopRecord = lastDeviceStatus?["loop"] as! [String : AnyObject]? {
             if let lastLoopTime = formatter.date(from: (lastLoopRecord["timestamp"] as! String))?.timeIntervalSince1970  {
+
+                UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
                 
                 if let failure = lastLoopRecord["failureReason"] {
                     LoopStatusLabel.text = "⚠"
@@ -468,8 +470,13 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
                     }
                     
                 }
+                if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 10 {
+                    LoopStatusLabel.text = "⚠"
+                }
             }
             
+            
+            
         }
         
         var oText = "" as String
@@ -1067,8 +1074,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
                 // write old BG reading and continue pushing out end date to show last entry
                 eventTitle += ": " + String(Int(deltaTime)) + " min"
                 eventEndDate = eventStartDate.addingTimeInterval((60 * 10) + (deltaTime * 60))
-            } else {
-                
             }
             
             eventTitle += "\n"
@@ -1233,6 +1238,26 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         }
         
         // These only get checked and fire if a BG reading doesn't fire
+        if UserDefaultsRepository.alertNotLoopingActive.value
+            && !UserDefaultsRepository.alertNotLoopingIsSnoozed.value
+            && (Double(now - UserDefaultsRepository.alertLastLoopTime.value) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))
+            && UserDefaultsRepository.alertLastLoopTime.value > 0 {
+            
+            var trigger = true
+            if (UserDefaultsRepository.alertNotLoopingUseLimits.value
+                && (
+                    (currentBG <= UserDefaultsRepository.alertNotLoopingUpperLimit.value
+                    && currentBG >= UserDefaultsRepository.alertNotLoopingLowerLimit.value) ||
+                    // Ignore Limits if BG reading is older than non looping time
+                    (Double(now - currentBGTime) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))
+                ) ||
+                !UserDefaultsRepository.alertNotLoopingUseLimits.value) {
+                    AlarmSound.whichAlarm = "Not Looping Alert"
+                    triggerAlarm(sound: UserDefaultsRepository.alertNotLoopingSound.value, snooozedBGReadingTime: nil)
+                    return
+            }
+        }
+        
         //check for missed reading alert
         if UserDefaultsRepository.alertMissedReadingActive.value && !UserDefaultsRepository.alertMissedReadingIsSnoozed.value && (Double(now - currentBGTime) >= Double(UserDefaultsRepository.alertMissedReading.value * 60)) {
             AlarmSound.whichAlarm = "Missed Reading Alert"

+ 7 - 1
LoopFollow/Controllers/SnoozeViewController.swift

@@ -112,7 +112,13 @@ class SnoozeViewController: UIViewController {
                        guard let alarms = self.tabBarController!.viewControllers?[1] as? AlarmViewController else { return }
                        alarms.reloadIsSnoozed(key: "alertCAGEIsSnoozed", value: true)
                        alarms.reloadSnoozeTime(key: "alertCAGESnoozedTime", setNil: false, value: Date().addingTimeInterval(TimeInterval(UserDefaultsRepository.alertCAGESnooze.value * 60 * 60)))
-                   }
+       } else if AlarmSound.whichAlarm == "Not Looping Alert" {
+                       UserDefaultsRepository.alertNotLoopingIsSnoozed.value = true
+                       UserDefaultsRepository.alertNotLoopingSnoozedTime.value = Date().addingTimeInterval(TimeInterval(UserDefaultsRepository.alertNotLoopingSnooze.value * 60 * 60))
+                       guard let alarms = self.tabBarController!.viewControllers?[1] as? AlarmViewController else { return }
+                       alarms.reloadIsSnoozed(key: "alertNotLoopingIsSnoozed", value: true)
+                       alarms.reloadSnoozeTime(key: "alertNotLoopingSnoozedTime", setNil: false, value: Date().addingTimeInterval(TimeInterval(UserDefaultsRepository.alertNotLoopingSnooze.value * 60 * 60)))
+       }
     }
     
     override func viewDidLoad() {

+ 2 - 0
LoopFollow/repository/UserDefaults.swift

@@ -52,6 +52,7 @@ class UserDefaultsRepository {
     
     
     // Alerts
+    
     static let snoozedBGReadingTime = UserDefaultsValue<TimeInterval?>(key: "snoozedBGReadingTime", default: 0)
     
     static let alertCageInsertTime = UserDefaultsValue<TimeInterval>(key: "alertCageInsertTime", default: 0)
@@ -129,6 +130,7 @@ class UserDefaultsRepository {
     static let alertNotLoopingSnoozedTime = UserDefaultsValue<Date?>(key: "alertNotLoopingSnoozedTime", default: nil)
     static let alertNotLoopingIsSnoozed = UserDefaultsValue<Bool>(key: "alertNotLoopingIsSnoozed", default: false)
     static let alertNotLoopingSound = UserDefaultsValue<String>(key: "alertNotLoopingSound", default: "Indeed")
+    static let alertLastLoopTime = UserDefaultsValue<TimeInterval>(key: "alertLastLoopTime", default: 0)
     
     static let alertMissedBolusActive = UserDefaultsValue<Bool>(key: "alertMissedBolusActive", default: false)
     static let alertMissedBolus = UserDefaultsValue<Int>(key: "alertMissedBolus", default: 10)