Skip to content

Commit

Permalink
Modified Not Looping handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorkert committed Jan 31, 2025
1 parent 3c99690 commit b1bec48
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
11 changes: 7 additions & 4 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ extension MainViewController {
DispatchQueue.main.async {
TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(10))
}

evaluateNotLooping()
}

func evaluateNotLooping(lastLoopTime: TimeInterval) {
func evaluateNotLooping() {
if let statusStackView = LoopStatusLabel.superview as? UIStackView {
if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 15 {
if ((TimeInterval(Date().timeIntervalSince1970) - UserDefaultsRepository.alertLastLoopTime.value) / 60) > 15 {
IsNotLooping = true
// Change the distribution to 'fill' to allow manual resizing of arranged subviews
statusStackView.distribution = .fill
Expand Down Expand Up @@ -70,7 +72,6 @@ extension MainViewController {
}
}
}
latestLoopTime = lastLoopTime
}

// NS Device Status Response Processor
Expand Down Expand Up @@ -145,7 +146,7 @@ extension MainViewController {

// Start the timer based on the timestamp
let now = dateTimeUtils.getNowTimeIntervalUTC()
let secondsAgo = now - latestLoopTime
let secondsAgo = now - UserDefaultsRepository.alertLastLoopTime.value

DispatchQueue.main.async {
if secondsAgo >= (20 * 60) {
Expand Down Expand Up @@ -179,6 +180,8 @@ extension MainViewController {
)
}
}

evaluateNotLooping()
LogManager.shared.log(category: .deviceStatus, message: "Update Device Status done", isDebug: true)
}
}
5 changes: 2 additions & 3 deletions LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension MainViewController {
func DeviceStatusLoop(formatter: ISO8601DateFormatter, lastLoopRecord: [String: AnyObject]) {
ObservableUserDefaults.shared.device.value = "Loop"
if let lastLoopTime = formatter.date(from: (lastLoopRecord["timestamp"] as! String))?.timeIntervalSince1970 {
let previousLastLoopTime = UserDefaultsRepository.alertLastLoopTime.value
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
if let failure = lastLoopRecord["failureReason"] {
LoopStatusLabel.text = "X"
Expand Down Expand Up @@ -66,7 +67,7 @@ extension MainViewController {
let prediction = predictdata["values"] as! [Double]
PredictionLabel.text = Localizer.toDisplayUnits(String(Int(prediction.last!)))
PredictionLabel.textColor = UIColor.systemPurple
if UserDefaultsRepository.downloadPrediction.value && latestLoopTime < lastLoopTime {
if UserDefaultsRepository.downloadPrediction.value && previousLastLoopTime < lastLoopTime {
predictionData.removeAll()
var predictionTime = lastLoopTime
let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
Expand Down Expand Up @@ -123,8 +124,6 @@ extension MainViewController {
}

}

evaluateNotLooping(lastLoopTime: lastLoopTime)
}
}
}
4 changes: 0 additions & 4 deletions LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ extension MainViewController {
if lastLoopRecord["failureReason"] != nil {
LoopStatusLabel.text = "X"
latestLoopStatusString = "X"
evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
} else {
guard let enactedOrSuggested = lastLoopRecord["suggested"] as? [String: AnyObject] ?? lastLoopRecord["enacted"] as? [String: AnyObject] else {
LoopStatusLabel.text = ""
latestLoopStatusString = ""
evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
return
}

Expand All @@ -34,8 +32,6 @@ extension MainViewController {
wasEnacted = false
LogManager.shared.log(category: .deviceStatus, message: "Last devicestatus is missing enacted")
}
evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)


var updatedTime: TimeInterval?

Expand Down
1 change: 0 additions & 1 deletion LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
var latestMinAgoString = ""
var latestDeltaString = ""
var latestLoopStatusString = ""
var latestLoopTime: Double = 0
var latestCOB: CarbMetric?
var latestBasal = ""
var latestPumpVolume: Double = 50.0
Expand Down

0 comments on commit b1bec48

Please sign in to comment.