Kaynağa Gözat

Updates:
Debug log, Advanced settings, iOS 13 style time picker,

Jon Fawcett 5 yıl önce
ebeveyn
işleme
b624871587

+ 11 - 0
LoopFollow/Application/Base.lproj/Main.storyboard

@@ -422,11 +422,21 @@
                                                     </stackView>
                                                 </subviews>
                                             </stackView>
+                                            <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="9ey-Az-e5u" userLabel="debugTextView">
+                                                <rect key="frame" x="8" y="8" width="382" height="336"/>
+                                                <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                <textInputTraits key="textInputTraits" autocapitalizationType="sentences" autocorrectionType="no"/>
+                                            </textView>
                                         </subviews>
                                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                         <constraints>
                                             <constraint firstItem="HFL-Ye-6HR" firstAttribute="centerY" secondItem="xzZ-jc-k2v" secondAttribute="centerY" id="7yv-SD-WC5"/>
+                                            <constraint firstItem="9ey-Az-e5u" firstAttribute="leading" secondItem="xzZ-jc-k2v" secondAttribute="leading" constant="8" id="8DB-3W-vzX"/>
                                             <constraint firstItem="HFL-Ye-6HR" firstAttribute="centerX" secondItem="xzZ-jc-k2v" secondAttribute="centerX" id="9b8-g8-Qgc"/>
+                                            <constraint firstAttribute="trailing" secondItem="9ey-Az-e5u" secondAttribute="trailing" constant="8" id="MdV-jD-BcV"/>
+                                            <constraint firstAttribute="bottom" secondItem="9ey-Az-e5u" secondAttribute="bottom" constant="8" id="rD1-uF-92v"/>
+                                            <constraint firstItem="9ey-Az-e5u" firstAttribute="top" secondItem="xzZ-jc-k2v" secondAttribute="top" constant="8" id="w6s-Ek-CoQ"/>
                                         </constraints>
                                     </view>
                                 </subviews>
@@ -451,6 +461,7 @@
                         <outlet property="MinAgoLabel" destination="HNC-P8-PbV" id="gLP-TD-hOq"/>
                         <outlet property="SnoozeButton" destination="Meu-VT-byv" id="Xnm-tj-t53"/>
                         <outlet property="clockLabel" destination="r85-eB-vVd" id="JTa-Uu-hdN"/>
+                        <outlet property="debugTextView" destination="9ey-Az-e5u" id="ycy-T9-ioF"/>
                         <outlet property="snoozeForMinuteLabel" destination="iC4-A1-q9b" id="Jvg-g0-bjs"/>
                         <outlet property="snoozeForMinuteStepper" destination="0cS-P2-Zus" id="ren-xl-jxN"/>
                     </connections>

+ 1 - 0
LoopFollow/Controllers/Alarms.swift

@@ -368,6 +368,7 @@ extension MainViewController {
         snoozer.SnoozeButton.isHidden = false
         snoozer.AlertLabel.isHidden = false
         snoozer.clockLabel.isHidden = true
+        snoozer.debugTextView.isHidden = true
         snoozer.snoozeForMinuteLabel.text = String(snoozeTime)
         snoozer.snoozeForMinuteStepper.value = Double(snoozeTime)
         snoozer.snoozeForMinuteStepper.stepValue = Double(snoozeIncrement)

+ 6 - 0
LoopFollow/Controllers/Graphs.swift

@@ -412,6 +412,7 @@ extension MainViewController {
     }
     
     func updateBGGraph() {
+        if UserDefaultsRepository.debugLog.value { writeDebugLog(value: "##### Start BG Graph #####") }
         let dataIndex = 0
         let entries = bgData
         if entries.count < 1 { return }
@@ -427,6 +428,7 @@ extension MainViewController {
                 topBG = Float(entries[i].sgv) + maxBGOffset
             }
             let value = ChartDataEntry(x: Double(entries[i].date), y: Double(entries[i].sgv), data: formatPillText(line1: bgUnits.toDisplayUnits(String(entries[i].sgv)), time: entries[i].date))
+            if UserDefaultsRepository.debugLog.value { writeDebugLog(value: "BG: " + value.description) }
             mainChart.addEntry(value)
             smallChart.addEntry(value)
             
@@ -439,6 +441,8 @@ extension MainViewController {
             }
         }
         
+        if UserDefaultsRepository.debugLog.value { writeDebugLog(value: "Total Graph BGs: " + mainChart.entries.count.description) }
+        
         
         // Set Colors
         let lineBG = BGChart.lineData!.dataSets[dataIndex] as! LineChartDataSet
@@ -458,6 +462,8 @@ extension MainViewController {
             }
         }
         
+        if UserDefaultsRepository.debugLog.value { writeDebugLog(value: "Total Colors: " + mainChart.colors.count.description) }
+        
         BGChart.rightAxis.axisMaximum = Double(topBG)
         BGChart.setVisibleXRangeMinimum(600)
         BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()

+ 65 - 55
LoopFollow/Controllers/NightScout.swift

@@ -265,66 +265,73 @@ extension MainViewController {
     // NS BG Data Front end updater
     func viewUpdateNSBG (isNS: Bool) {
         DispatchQueue.main.async {
-            if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Display: BG") }
-            guard let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController else { return }
+            if UserDefaultsRepository.debugLog.value {
+                self.writeDebugLog(value: "Display: BG")
+                self.writeDebugLog(value: "Num BG: " + self.bgData.count.description)
+            }
             let entries = self.bgData
-            if entries.count > 0 {
-                let latestEntryi = entries.count - 1
-                let latestBG = entries[latestEntryi].sgv
-                let priorBG = entries[latestEntryi - 1].sgv
-                let deltaBG = latestBG - priorBG as Int
-                let lastBGTime = entries[latestEntryi].date
-                
-                let deltaTime = (TimeInterval(Date().timeIntervalSince1970)-lastBGTime) / 60
-                var userUnit = " mg/dL"
-                if self.mmol {
-                    userUnit = " mmol/L"
-                }
-                
-                // TODO: remove testing feature to color code arrow based on NS vs Dex
-                if isNS {
-                    self.serverText.text = "Nightscout"
-                } else {
-                    self.serverText.text = "Dexcom"
-                }
-                
-                self.BGText.text = bgUnits.toDisplayUnits(String(latestBG))
-                snoozer.BGLabel.text = bgUnits.toDisplayUnits(String(latestBG))
-                self.setBGTextColor()
-                
-                if let directionBG = entries[latestEntryi].direction {
-                    self.DirectionText.text = self.bgDirectionGraphic(directionBG)
-                    snoozer.DirectionLabel.text = self.bgDirectionGraphic(directionBG)
-                    self.latestDirectionString = self.bgDirectionGraphic(directionBG)
-                }
-                else
-                {
-                    self.DirectionText.text = ""
-                    snoozer.DirectionLabel.text = ""
-                    self.latestDirectionString = ""
-                }
-                
-                if deltaBG < 0 {
-                    self.DeltaText.text = bgUnits.toDisplayUnits(String(deltaBG))
-                    snoozer.DeltaLabel.text = bgUnits.toDisplayUnits(String(deltaBG))
-                    self.latestDeltaString = String(deltaBG)
-                }
-                else
-                {
-                    self.DeltaText.text = "+" + bgUnits.toDisplayUnits(String(deltaBG))
-                    snoozer.DeltaLabel.text = "+" + bgUnits.toDisplayUnits(String(deltaBG))
-                    self.latestDeltaString = "+" + String(deltaBG)
-                }
-                self.updateBadge(val: latestBG)
-                
+            if entries.count < 1 { return }
+            
+            self.updateBGGraph()
+            self.updateStats()
+            
+            let latestEntryi = entries.count - 1
+            let latestBG = entries[latestEntryi].sgv
+            let priorBG = entries[latestEntryi - 1].sgv
+            let deltaBG = latestBG - priorBG as Int
+            let lastBGTime = entries[latestEntryi].date
+            
+            let deltaTime = (TimeInterval(Date().timeIntervalSince1970)-lastBGTime) / 60
+            var userUnit = " mg/dL"
+            if self.mmol {
+                userUnit = " mmol/L"
+            }
+            
+            if isNS {
+                self.serverText.text = "Nightscout"
+            } else {
+                self.serverText.text = "Dexcom"
+            }
+            
+            var snoozerBG = ""
+            var snoozerDirection = ""
+            var snoozerDelta = ""
+            
+            self.BGText.text = bgUnits.toDisplayUnits(String(latestBG))
+            snoozerBG = bgUnits.toDisplayUnits(String(latestBG))
+            self.setBGTextColor()
+            
+            if let directionBG = entries[latestEntryi].direction {
+                self.DirectionText.text = self.bgDirectionGraphic(directionBG)
+                snoozerDirection = self.bgDirectionGraphic(directionBG)
+                self.latestDirectionString = self.bgDirectionGraphic(directionBG)
             }
             else
             {
-                
-                return
+                self.DirectionText.text = ""
+                snoozerDirection = ""
+                self.latestDirectionString = ""
             }
-            self.updateBGGraph()
-            self.updateStats()
+            
+            if deltaBG < 0 {
+                self.DeltaText.text = bgUnits.toDisplayUnits(String(deltaBG))
+                snoozerDelta = bgUnits.toDisplayUnits(String(deltaBG))
+                self.latestDeltaString = String(deltaBG)
+            }
+            else
+            {
+                self.DeltaText.text = "+" + bgUnits.toDisplayUnits(String(deltaBG))
+                snoozerDelta = "+" + bgUnits.toDisplayUnits(String(deltaBG))
+                self.latestDeltaString = "+" + String(deltaBG)
+            }
+            self.updateBadge(val: latestBG)
+            
+            // Snoozer Display
+            guard let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController else { return }
+            snoozer.BGLabel.text = snoozerBG
+            snoozer.DirectionLabel.text = snoozerDirection
+            snoozer.DeltaLabel.text = snoozerDelta
+            
         }
         
     }
@@ -1705,6 +1712,9 @@ extension MainViewController {
                 duration = duration * 60
             }
             
+            // Skip overrides that aren't 5 minutes long. This prevents overlapping that causes bars to not display.
+            if duration < 300 { continue }
+            
             guard let enteredBy = currentEntry?["enteredBy"] as? String else { continue }
             guard let reason = currentEntry?["reason"] as? String else { continue }
             

+ 2 - 0
LoopFollow/Controllers/Timers.swift

@@ -140,6 +140,8 @@ extension MainViewController {
             }
         }
         
+        if UserDefaultsRepository.alwaysDownloadAllBG.value { onlyPullLastRecord = false }
+        
         if UserDefaultsRepository.shareUserName.value != "" && UserDefaultsRepository.sharePassword.value != "" {
             webLoadDexShare(onlyPullLastRecord: onlyPullLastRecord)
         } else {

+ 17 - 0
LoopFollow/ViewControllers/AdvancedSettingsViewController.swift

@@ -90,6 +90,21 @@ class AdvancedSettingsViewController: FormViewController {
                     guard let value = row.value else { return }
                     UserDefaultsRepository.bgUpdateDelay.value = Int(value)
             }
+            <<< SwitchRow("alwaysDownloadAllBG"){ row in
+                row.title = "Allways Download All BG Values"
+                row.value = UserDefaultsRepository.alwaysDownloadAllBG.value
+            }.onChange { [weak self] row in
+                guard let value = row.value else { return }
+                UserDefaultsRepository.alwaysDownloadAllBG.value = value
+            }
+            <<< SwitchRow("debugLog"){ row in
+                row.title = "Show Debug Log"
+                row.value = UserDefaultsRepository.debugLog.value
+            }.onChange { [weak self] row in
+                guard let value = row.value else { return }
+                UserDefaultsRepository.debugLog.value = value
+            }
+
             
             
             
@@ -100,4 +115,6 @@ class AdvancedSettingsViewController: FormViewController {
                 self.dismiss(animated:true, completion: nil)
             }
     }
+    
+
 }

+ 15 - 0
LoopFollow/ViewControllers/AlarmViewController.swift

@@ -329,6 +329,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -494,6 +495,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -599,6 +601,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -719,6 +722,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -823,6 +827,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -964,6 +969,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1105,6 +1111,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1211,6 +1218,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1353,6 +1361,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1521,6 +1530,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1647,6 +1657,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1759,6 +1770,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1843,6 +1855,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -1928,6 +1941,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in
@@ -2043,6 +2057,7 @@ class AlarmViewController: FormViewController {
             .onExpandInlineRow { [weak self] cell, row, inlineRow in
                 inlineRow.cellUpdate() { cell, row in
                     cell.datePicker.datePickerMode = .dateAndTime
+                    cell.datePicker.preferredDatePickerStyle = .wheels
                 }
                 let color = cell.detailTextLabel?.textColor
                 row.onCollapseInlineRow { cell, _, _ in

+ 11 - 2
LoopFollow/ViewControllers/MainViewController.swift

@@ -707,8 +707,17 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
     }
     
     func writeDebugLog(value: String) {
-        var logText = "\n" + dateTimeUtils.printNow() + " - " + value
-        print(logText)
+        DispatchQueue.main.async {
+            var logText = "\n" + dateTimeUtils.printNow() + " - " + value
+            print(logText)
+            guard let debug = self.tabBarController!.viewControllers?[2] as? SnoozeViewController else { return }
+            if debug.debugTextView.text.lengthOfBytes(using: .utf8) > 20000 {
+                debug.debugTextView.text = ""
+                    }
+            debug.debugTextView.text += logText
+        }
+        
+        
         
     }
     

+ 11 - 0
LoopFollow/ViewControllers/SettingsViewController.swift

@@ -197,12 +197,23 @@ class SettingsViewController: FormViewController {
            ), onDismiss: nil)
             
         }
+            <<< LabelRow("Refresh Graph"){ row in
+                row.title = "Refresh Graph"
+            }.onCellSelection{ cell,row  in
+                if UserDefaultsRepository.saveImage.value {
+                    guard let mainScreen = self.tabBarController!.viewControllers?[0] as? MainViewController else { return }
+                    
+                    mainScreen.updateBGGraphSettings()
+                    self.tabBarController?.selectedIndex = 0
+                }
+            }
   
     
             +++ Section(header: "App Expiration", footer: String(expiration.description))
     
         showHideNSDetails()
       
+    
     }
     
     

+ 10 - 0
LoopFollow/ViewControllers/SnoozeViewController.swift

@@ -28,6 +28,7 @@ class SnoozeViewController: UIViewController, UNUserNotificationCenterDelegate {
     @IBOutlet weak var clockLabel: UILabel!
     @IBOutlet weak var snoozeForMinuteLabel: UILabel!
     @IBOutlet weak var snoozeForMinuteStepper: UIStepper!
+    @IBOutlet weak var debugTextView: UITextView!
     
     @IBAction func SnoozeButton(_ sender: Any) {
         AlarmSound.stop()
@@ -49,6 +50,10 @@ class SnoozeViewController: UIViewController, UNUserNotificationCenterDelegate {
         snoozeForMinuteStepper.isHidden = true
         snoozeForMinuteLabel.isHidden = true
         
+        if UserDefaultsRepository.debugLog.value {
+            debugTextView.isHidden = false
+        }
+        
     }
     
     @IBAction func snoozeForMinuteValChanged(_ sender: UIStepper) {
@@ -256,6 +261,11 @@ class SnoozeViewController: UIViewController, UNUserNotificationCenterDelegate {
         SnoozeButton.contentEdgeInsets = UIEdgeInsets(top: 10,left: 10,bottom: 10,right: 10)
         clockLabel.text = ""
         startClockTimer(time: 1)
+        
+        if UserDefaultsRepository.debugLog.value {
+            debugTextView.isHidden = false
+            clockLabel.isHidden = true
+        }
     }
 
 

+ 3 - 0
LoopFollow/helpers/Globals.swift

@@ -10,6 +10,8 @@ import Foundation
 
 
 struct globalVariables {
+    static var debugLog = ""
+    
     static var dexVerifiedAlert: TimeInterval = 0
     static var nsVerifiedAlert: TimeInterval = 0
     
@@ -19,4 +21,5 @@ struct globalVariables {
     static let dotBolus: Float = 5
     static let dotOther: Float = 5
     
+    
 }

+ 1 - 0
LoopFollow/repository/UserDefaults.swift

@@ -83,6 +83,7 @@ class UserDefaultsRepository {
     static let graphBolus = UserDefaultsValue<Bool>(key: "graphBolus", default: true)
     static let graphCarbs = UserDefaultsValue<Bool>(key: "graphCarbs", default: true)
     static let debugLog = UserDefaultsValue<Bool>(key: "debugLog", default: false)
+    static let alwaysDownloadAllBG = UserDefaultsValue<Bool>(key: "alwaysDownloadAllBG", default: false)
     static let bgUpdateDelay = UserDefaultsValue<Int>(key: "bgUpdateDelay", default: 10)