Parcourir la source

Add: enable/disable features or NS vs Dex

Jon Fawcett il y a 6 ans
Parent
commit
c40ab03794

+ 13 - 13
LoopFollow/Application/Base.lproj/Main.storyboard

@@ -17,25 +17,25 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <stackView opaque="NO" contentMode="scaleToFill" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="mJy-Ly-Jze">
-                                <rect key="frame" x="8" y="52.000000000000014" width="398" height="234.33333333333337"/>
+                                <rect key="frame" x="8" y="52" width="398" height="259.33333333333331"/>
                                 <subviews>
                                     <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="Ptf-fu-Ue4" userLabel="BGview">
-                                        <rect key="frame" x="0.0" y="0.0" width="144" height="234.33333333333334"/>
+                                        <rect key="frame" x="0.0" y="0.0" width="144" height="259.33333333333331"/>
                                         <subviews>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Server" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2mX-T9-SAm">
-                                                <rect key="frame" x="0.0" y="0.0" width="144" height="20.333333333333332"/>
+                                                <rect key="frame" x="0.0" y="0.0" width="144" height="15.666666666666666"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="BG" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vXU-IW-GOL">
-                                                <rect key="frame" x="0.0" y="20.333333333333321" width="144" height="101.66666666666669"/>
+                                                <rect key="frame" x="0.0" y="15.666666666666664" width="144" height="101.66666666666669"/>
                                                 <fontDescription key="fontDescription" type="system" weight="black" pointSize="85"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" translatesAutoresizingMaskIntoConstraints="NO" id="KZc-fa-qmt">
-                                                <rect key="frame" x="0.0" y="122" width="144" height="71.666666666666686"/>
+                                                <rect key="frame" x="0.0" y="117.33333333333334" width="144" height="71.666666666666657"/>
                                                 <subviews>
                                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="--" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4sd-6h-LSj" userLabel="Direction">
                                                         <rect key="frame" x="0.0" y="0.0" width="72" height="71.666666666666671"/>
@@ -52,22 +52,22 @@
                                                 </subviews>
                                             </stackView>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="MinAgo" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UkG-hw-DVo">
-                                                <rect key="frame" x="0.0" y="193.66666666666666" width="144" height="20.333333333333343"/>
+                                                <rect key="frame" x="0.0" y="189" width="144" height="20.333333333333343"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="TDG-yw-5fS">
-                                                <rect key="frame" x="0.0" y="214" width="144" height="20.333333333333343"/>
+                                                <rect key="frame" x="0.0" y="209.33333333333331" width="144" height="50"/>
                                                 <subviews>
-                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loop" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XEm-uK-Xui">
-                                                        <rect key="frame" x="0.0" y="0.0" width="68" height="20.333333333333332"/>
+                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XEm-uK-Xui">
+                                                        <rect key="frame" x="0.0" y="0.0" width="68" height="50"/>
                                                         <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                         <nil key="textColor"/>
                                                         <nil key="highlightedColor"/>
                                                     </label>
-                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Prediction" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oiR-SM-6sg">
-                                                        <rect key="frame" x="76" y="0.0" width="68" height="20.333333333333332"/>
+                                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oiR-SM-6sg">
+                                                        <rect key="frame" x="76" y="0.0" width="68" height="50"/>
                                                         <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                                         <nil key="textColor"/>
                                                         <nil key="highlightedColor"/>
@@ -77,7 +77,7 @@
                                         </subviews>
                                     </stackView>
                                     <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="kTs-7g-lp9">
-                                        <rect key="frame" x="154" y="0.0" width="244" height="234.33333333333334"/>
+                                        <rect key="frame" x="154" y="0.0" width="244" height="259.33333333333331"/>
                                         <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                                         <constraints>
                                             <constraint firstAttribute="width" priority="750" constant="250" id="Gxe-cX-1oe"/>
@@ -112,7 +112,7 @@
                                 </subviews>
                             </stackView>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="51B-JU-npv" customClass="LineChartView" customModule="Charts">
-                                <rect key="frame" x="8" y="294.33333333333326" width="398" height="334.66666666666674"/>
+                                <rect key="frame" x="8" y="319.33333333333326" width="398" height="309.66666666666674"/>
                                 <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
                             </view>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ikj-at-auF">

+ 99 - 91
LoopFollow/Controllers/Alarms.swift

@@ -160,115 +160,123 @@ extension MainViewController {
         }
         
         // These only get checked and fire if a BG reading doesn't fire
-        if UserDefaultsRepository.alertNotLoopingActive.value
-            && !UserDefaultsRepository.alertNotLoopingIsSnoozed.value
-            && (Double(dateTimeUtils.getNowTimeIntervalUTC() - UserDefaultsRepository.alertLastLoopTime.value) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))
-            && UserDefaultsRepository.alertLastLoopTime.value > 0 {
-            
-            var trigger = true
-            if (UserDefaultsRepository.alertNotLoopingUseLimits.value
-                && (
-                    (Float(currentBG) >= UserDefaultsRepository.alertNotLoopingUpperLimit.value
-                        && Float(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"
-                if UserDefaultsRepository.alertNotLoopingRepeat.value { numLoops = -1 }
-                triggerAlarm(sound: UserDefaultsRepository.alertNotLoopingSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
-                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"
+            if UserDefaultsRepository.alertMissedReadingRepeat.value { numLoops = -1 }
+            triggerAlarm(sound: UserDefaultsRepository.alertMissedReadingSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+            return
         }
         
-        // check for missed bolus - Only checks within 1 hour of carb entry
-        // Only continue if alert is active, not snooozed, we have carb data, and bg is over the ignore limit
-        if UserDefaultsRepository.alertMissedBolusActive.value
-            && !UserDefaultsRepository.alertMissedBolusIsSnoozed.value
-            && carbData.count > 0
-            && Float(currentBG) > UserDefaultsRepository.alertMissedBolusLowGramsBG.value {
-            
-            // Grab the latest carb entry
-            let lastCarb = carbData[carbData.count - 1].value
-            let lastCarbTime = carbData[carbData.count - 1].date
-            let now = dateTimeUtils.getNowTimeIntervalUTC()
+        
+        if UserDefaultsRepository.url.value != "" {
             
-            //Make sure carb entry is newer than 1 hour, has reached the time length, and is over the ignore limit
-            if lastCarbTime > (now - (60 * 60))
-                && lastCarbTime < (now - Double((UserDefaultsRepository.alertMissedBolus.value * 60)))
-                && lastCarb > Double(UserDefaultsRepository.alertMissedBolusLowGrams.value) {
+            if UserDefaultsRepository.alertNotLoopingActive.value
+                && !UserDefaultsRepository.alertNotLoopingIsSnoozed.value
+                && (Double(dateTimeUtils.getNowTimeIntervalUTC() - UserDefaultsRepository.alertLastLoopTime.value) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))
+                && UserDefaultsRepository.alertLastLoopTime.value > 0 {
                 
-                // There is a current carb but no boluses data at all
-                if bolusData.count < 1 {
-                    AlarmSound.whichAlarm = "Missed Bolus Alert"
-                    if UserDefaultsRepository.alertMissedBolusRepeat.value { numLoops = -1 }
-                    triggerAlarm(sound: UserDefaultsRepository.alertMissedBolusSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+                var trigger = true
+                if (UserDefaultsRepository.alertNotLoopingUseLimits.value
+                    && (
+                        (Float(currentBG) >= UserDefaultsRepository.alertNotLoopingUpperLimit.value
+                            && Float(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"
+                    if UserDefaultsRepository.alertNotLoopingRepeat.value { numLoops = -1 }
+                    triggerAlarm(sound: UserDefaultsRepository.alertNotLoopingSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
                     return
                 }
+            }
+            
+            // check for missed bolus - Only checks within 1 hour of carb entry
+            // Only continue if alert is active, not snooozed, we have carb data, and bg is over the ignore limit
+            if UserDefaultsRepository.alertMissedBolusActive.value
+                && !UserDefaultsRepository.alertMissedBolusIsSnoozed.value
+                && carbData.count > 0
+                && Float(currentBG) > UserDefaultsRepository.alertMissedBolusLowGramsBG.value {
                 
-                // Get the latest bolus over the small bolus exclusion
-                // Start with 0.0 bolus assuming there isn't one to cause a trigger and only add one if found
-                var lastBolus = 0.0
-                var lastBolusTime = 0.0
-                var i = 1
-                // check the boluses in reverse order setting it only if the time is after the carb time minus prebolus time.
-                // This will make the loop stop at the most recent bolus that is over the minimum value or continue through all boluses
-                while lastBolus < UserDefaultsRepository.alertMissedBolusIgnoreBolus.value && i <= bolusData.count {
-                    // Set the bolus if it's after the carb time minus prebolus time
-                    if (bolusData[bolusData.count - i].date >= lastCarbTime - Double(UserDefaultsRepository.alertMissedBolusPrebolus.value * 60)) {
-                        lastBolus = bolusData[bolusData.count - i].value
-                        lastBolusTime = bolusData[bolusData.count - i].date
+                // Grab the latest carb entry
+                let lastCarb = carbData[carbData.count - 1].value
+                let lastCarbTime = carbData[carbData.count - 1].date
+                let now = dateTimeUtils.getNowTimeIntervalUTC()
+                
+                //Make sure carb entry is newer than 1 hour, has reached the time length, and is over the ignore limit
+                if lastCarbTime > (now - (60 * 60))
+                    && lastCarbTime < (now - Double((UserDefaultsRepository.alertMissedBolus.value * 60)))
+                    && lastCarb > Double(UserDefaultsRepository.alertMissedBolusLowGrams.value) {
+                    
+                    // There is a current carb but no boluses data at all
+                    if bolusData.count < 1 {
+                        AlarmSound.whichAlarm = "Missed Bolus Alert"
+                        if UserDefaultsRepository.alertMissedBolusRepeat.value { numLoops = -1 }
+                        triggerAlarm(sound: UserDefaultsRepository.alertMissedBolusSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+                        return
+                    }
+                    
+                    // Get the latest bolus over the small bolus exclusion
+                    // Start with 0.0 bolus assuming there isn't one to cause a trigger and only add one if found
+                    var lastBolus = 0.0
+                    var lastBolusTime = 0.0
+                    var i = 1
+                    // check the boluses in reverse order setting it only if the time is after the carb time minus prebolus time.
+                    // This will make the loop stop at the most recent bolus that is over the minimum value or continue through all boluses
+                    while lastBolus < UserDefaultsRepository.alertMissedBolusIgnoreBolus.value && i <= bolusData.count {
+                        // Set the bolus if it's after the carb time minus prebolus time
+                        if (bolusData[bolusData.count - i].date >= lastCarbTime - Double(UserDefaultsRepository.alertMissedBolusPrebolus.value * 60)) {
+                            lastBolus = bolusData[bolusData.count - i].value
+                            lastBolusTime = bolusData[bolusData.count - i].date
+                        }
+                        i += 1
+                    }
+                    
+                    // This will trigger is no boluses were set above
+                    if (lastBolus == 0.0) {
+                        AlarmSound.whichAlarm = "Missed Bolus Alert"
+                        if UserDefaultsRepository.alertMissedBolusRepeat.value { numLoops = -1 }
+                        triggerAlarm(sound: UserDefaultsRepository.alertMissedBolusSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+                        return
                     }
-                    i += 1
+                    
                 }
                 
-                // This will trigger is no boluses were set above
-                if (lastBolus == 0.0) {
-                    AlarmSound.whichAlarm = "Missed Bolus Alert"
-                    if UserDefaultsRepository.alertMissedBolusRepeat.value { numLoops = -1 }
-                    triggerAlarm(sound: UserDefaultsRepository.alertMissedBolusSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+            }
+            
+            // Check Sage
+            if UserDefaultsRepository.alertSAGEActive.value && !UserDefaultsRepository.alertSAGEIsSnoozed.value {
+                let insertTime = Double(UserDefaultsRepository.alertSageInsertTime.value)
+                let alertDistance = Double(UserDefaultsRepository.alertSAGE.value * 60 * 60)
+                let delta = now - insertTime
+                let tenDays = 10 * 24 * 60 * 60
+                if Double(tenDays) - Double(delta) <= alertDistance {
+                    AlarmSound.whichAlarm = "Sensor Change Alert"
+                    if UserDefaultsRepository.alertSAGERepeat.value { numLoops = -1 }
+                    triggerAlarm(sound: UserDefaultsRepository.alertSAGESound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
                     return
                 }
-                
             }
             
+            // Check Cage
+            if UserDefaultsRepository.alertCAGEActive.value && !UserDefaultsRepository.alertCAGEIsSnoozed.value {
+                let insertTime = Double(UserDefaultsRepository.alertCageInsertTime.value)
+                let alertDistance = Double(UserDefaultsRepository.alertCAGE.value * 60 * 60)
+                let delta = now - insertTime
+                let tenDays = 3 * 24 * 60 * 60
+                if Double(tenDays) - Double(delta) <= alertDistance {
+                    AlarmSound.whichAlarm = "Pump Change Alert"
+                    if UserDefaultsRepository.alertCAGERepeat.value { numLoops = -1 }
+                    triggerAlarm(sound: UserDefaultsRepository.alertCAGESound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
+                    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"
-            if UserDefaultsRepository.alertMissedReadingRepeat.value { numLoops = -1 }
-            triggerAlarm(sound: UserDefaultsRepository.alertMissedReadingSound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
-            return
-        }
         
-        // Check Sage
-        if UserDefaultsRepository.alertSAGEActive.value && !UserDefaultsRepository.alertSAGEIsSnoozed.value {
-            let insertTime = Double(UserDefaultsRepository.alertSageInsertTime.value)
-            let alertDistance = Double(UserDefaultsRepository.alertSAGE.value * 60 * 60)
-            let delta = now - insertTime
-            let tenDays = 10 * 24 * 60 * 60
-            if Double(tenDays) - Double(delta) <= alertDistance {
-                AlarmSound.whichAlarm = "Sensor Change Alert"
-                if UserDefaultsRepository.alertSAGERepeat.value { numLoops = -1 }
-                triggerAlarm(sound: UserDefaultsRepository.alertSAGESound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
-                return
-            }
-        }
         
-        // Check Cage
-        if UserDefaultsRepository.alertCAGEActive.value && !UserDefaultsRepository.alertCAGEIsSnoozed.value {
-            let insertTime = Double(UserDefaultsRepository.alertCageInsertTime.value)
-            let alertDistance = Double(UserDefaultsRepository.alertCAGE.value * 60 * 60)
-            let delta = now - insertTime
-            let tenDays = 3 * 24 * 60 * 60
-            if Double(tenDays) - Double(delta) <= alertDistance {
-                AlarmSound.whichAlarm = "Pump Change Alert"
-                if UserDefaultsRepository.alertCAGERepeat.value { numLoops = -1 }
-                triggerAlarm(sound: UserDefaultsRepository.alertCAGESound.value, snooozedBGReadingTime: nil, overrideVolume: UserDefaultsRepository.overrideSystemOutputVolume.value, numLoops: numLoops)
-                return
-            }
-        }
         
         // still send persistent notification if no alarms trigger and persistent notification is on
         persistentNotification(bgTime: currentBGTime)

+ 35 - 18
LoopFollow/Controllers/NightScout.swift

@@ -70,11 +70,19 @@ extension MainViewController {
         if forceLoad { needsLoaded = true}
         // Only update if we don't have a current reading or forced to load
         if needsLoaded {
-            webLoadNSDeviceStatus()
-            webLoadDexShare(onlyPullLastRecord: onlyPullLastRecord)
-            //webLoadNSBGData(onlyPullLastRecord: onlyPullLastRecord)
             
-            if !staleData {
+            if UserDefaultsRepository.url.value != "" {
+                webLoadNSDeviceStatus()
+            }
+            
+            if UserDefaultsRepository.shareUserName.value != "" && UserDefaultsRepository.sharePassword.value != "" {
+                webLoadDexShare(onlyPullLastRecord: onlyPullLastRecord)
+            } else {
+                webLoadNSBGData(onlyPullLastRecord: onlyPullLastRecord)
+            }
+
+            
+            if !staleData && UserDefaultsRepository.url.value != "" {
                 webLoadNSProfile()
                 if UserDefaultsRepository.downloadBasal.value {
                     WebLoadNSTempBasals()
@@ -88,27 +96,36 @@ extension MainViewController {
                 webLoadNSCage()
                 webLoadNSSage()
             }
-            
-            
+
             // Give the alarms and calendar 15 seconds delay to allow time for data to compile
-//            if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Start view timer") }
             self.startViewTimer(time: viewTimeInterval)
         } else {
-            // Things to do if we already have data and don't need a network call
-            // Leaving all downloads off for right now.
-            /*
-             webLoadNSDeviceStatus()
-             
-             if UserDefaultsRepository.downloadBolus.value {
-                webLoadNSBoluses()
-             }
-             if UserDefaultsRepository.downloadCarbs.value {
-                webLoadNSCarbs()
-             }*/
+
             if bgData.count > 0 {
                 self.checkAlarms(bgs: bgData)
             }
             
+            if UserDefaultsRepository.url.value != ""  {
+                if latestLoopTime == 0 {
+                    webLoadNSDeviceStatus()
+               
+                    webLoadNSBGData(onlyPullLastRecord: onlyPullLastRecord)
+           
+                    webLoadNSProfile()
+                    if UserDefaultsRepository.downloadBasal.value {
+                        WebLoadNSTempBasals()
+                    }
+                    if UserDefaultsRepository.downloadBolus.value {
+                        webLoadNSBoluses()
+                    }
+                    if UserDefaultsRepository.downloadCarbs.value {
+                        webLoadNSCarbs()
+                    }
+                    webLoadNSCage()
+                    webLoadNSSage()
+                }
+            }
+            
         }
     }
     

+ 52 - 1
LoopFollow/ViewControllers/AlarmViewController.swift

@@ -144,6 +144,8 @@ class AlarmViewController: FormViewController {
             }
     }
     
+    
+    
    // static let shared = AlarmViewController()
 
     @IBAction func unwindToAlarms(sender: UIStoryboardSegue)
@@ -196,6 +198,10 @@ class AlarmViewController: FormViewController {
             <<< SegmentedRow<String>("otherAlerts"){ row in
                 row.title = ""
                 row.options = ["Not Looping", "Missed Bolus", "SAGE", "CAGE"]
+                if UserDefaultsRepository.url.value == "" {
+                    row.hidden = true
+                }
+                
                 //row.value = "Not Looping"
         }.onChange { [weak self] row in
              guard let value = row.value else { return }
@@ -213,6 +219,9 @@ class AlarmViewController: FormViewController {
         <<< SegmentedRow<String>("overrideAlerts"){ row in
                 row.title = ""
                 row.options = ["Override Start", "Override End"]
+                if UserDefaultsRepository.url.value == "" {
+                    row.hidden = true
+                }
                 //row.value = "Not Looping"
         }.onChange { [weak self] row in
              guard let value = row.value else { return }
@@ -258,6 +267,42 @@ class AlarmViewController: FormViewController {
         buildAlarmSettings()
         
     }
+    
+    override func viewDidAppear(_ animated: Bool) {
+        showHideNSDetails()
+    }
+    
+    func showHideNSDetails() {
+        var isHidden = false
+        var isEnabled = true
+        if UserDefaultsRepository.url.value == "" {
+            isHidden = true
+            isEnabled = false
+        }
+        
+        if let row1 = form.rowBy(tag: "otherAlerts") as? SegmentedRow<String> {
+            row1.hidden = .function(["hide"],  {form in
+                return isHidden
+            })
+            row1.evaluateHidden()
+        }
+        if let row2 = form.rowBy(tag: "overrideAlerts") as? SegmentedRow<String> {
+            row2.hidden = .function(["hide"],  {form in
+                return isHidden
+            })
+            row2.evaluateHidden()
+        }
+        if let row3 = form.sectionBy(tag: "quietHourSection") as? Section {
+            row3.hidden = .function(["hide"],  {form in
+                return isHidden
+            })
+            row3.evaluateHidden()
+        }
+        
+        guard let nightscoutTab = self.tabBarController?.tabBar.items![3] else { return }
+        nightscoutTab.isEnabled = isEnabled
+        
+    }
 
     func buildSnoozeAll(){
         form
@@ -1907,7 +1952,7 @@ class AlarmViewController: FormViewController {
 
     func buildAlarmSettings() {
            form
-            +++ Section(header: "Alarm Sound Settings", footer: "Quiet hours can be used to automatically snooze non-critical alerts that you do not wish to be awakened for such as a sensor change pre-alert that may happen during the night.")
+            +++ Section(header: "Alarm Sound Settings", footer: "")
            
             <<< SwitchRow("overrideSystemOutputVolume"){ row in
                 row.title = "Override System Volume"
@@ -1931,9 +1976,14 @@ class AlarmViewController: FormViewController {
                       guard let value = row.value else { return }
                       UserDefaultsRepository.forcedOutputVolume.value = Float(value)
               }
+            
+             +++ Section(header: "Quiet Hour Settings", footer: "Quiet hours can be used to automatically snooze non-critical alerts that you do not wish to be awakened for such as a sensor change pre-alert that may happen during the night.")  { row in
+                row.tag = "quietHourSection"
+                        }
             <<< TimeInlineRow("quietHourStart") { row in
                 row.title = "Quiet Hours Start Today"
                 row.value = UserDefaultsRepository.quietHourStart.value
+                
         }.onChange { [weak self] row in
                 guard let value = row.value else { return }
                 UserDefaultsRepository.quietHourStart.value = value
@@ -1941,6 +1991,7 @@ class AlarmViewController: FormViewController {
         <<< TimeInlineRow("quietHourEnd") { row in
                 row.title = "Quiet Hours End Tomorrow"
                 row.value = UserDefaultsRepository.quietHourEnd.value
+                
         }.onChange { [weak self] row in
                 guard let value = row.value else { return }
                 UserDefaultsRepository.quietHourEnd.value = value

+ 22 - 1
LoopFollow/ViewControllers/MainViewController.swift

@@ -174,6 +174,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
             createSmallBGGraph()
         }
         
+        // setup display for NS vs Dex
+        showHideNSDetails()
+        
         // Load Data
         if (UserDefaultsRepository.url.value != "" || (UserDefaultsRepository.shareUserName.value != "" && UserDefaultsRepository.sharePassword.value != "")) && firstGraphLoad {
             nightscoutLoader()
@@ -295,6 +298,10 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         
     }
     
+    @objc override func viewDidAppear(_ animated: Bool) {
+        showHideNSDetails()
+    }
+    
     // Check for new data when timer ends
     @objc func timerDidEnd(_ timer:Timer) {
 //        if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Main timer ended") }
@@ -332,7 +339,21 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         return String(format: "%02d:%02d", hours, minutes)
     }
 
-    
+    func showHideNSDetails() {
+        var isHidden = false
+        var isEnabled = true
+        if UserDefaultsRepository.url.value == "" {
+            isHidden = true
+            isEnabled = false
+        }
+        
+        LoopStatusLabel.isHidden = isHidden
+        PredictionLabel.isHidden = isHidden
+        infoTable.isHidden = isHidden
+        guard let nightscoutTab = self.tabBarController?.tabBar.items![3] else { return }
+        nightscoutTab.isEnabled = isEnabled
+        
+    }
     
     func updateBadge(val: Int) {
         if UserDefaultsRepository.appBadge.value {