Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ extension MainViewController {
{
infoManager.updateInfoData(type: .pumpBattery, value: String(format: "%.0f", pumpBatteryPercent) + "%", numericValue: pumpBatteryPercent)
Observable.shared.pumpBatteryLevel.value = pumpBatteryPercent
latestPumpBatteryDate = Date()
} else if let lastPercent = Observable.shared.pumpBatteryLevel.value,
let lastDate = latestPumpBatteryDate,
Date().timeIntervalSince(lastDate) <= 60 * 60
{
// Some records leave out the pump battery, and the level changes
// slowly, so the last reading is shown for up to an hour.
infoManager.updateInfoData(type: .pumpBattery, value: String(format: "%.0f", lastPercent) + "%", numericValue: lastPercent)
}

if let uploader = lastDeviceStatus?["uploader"] as? [String: AnyObject],
Expand Down
30 changes: 15 additions & 15 deletions LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ extension MainViewController {
let previousLastLoopTime = Observable.shared.previousAlertLastLoopTime.value ?? 0
let lastLoopTime = Observable.shared.alertLastLoopTime.value ?? 0

// Loop reports IOB and COB even when the loop failed.
if let insulinMetric = InsulinMetric(from: lastLoopRecord["iob"], key: "iob") {
infoManager.updateInfoData(type: .iob, value: insulinMetric)
latestIOB = insulinMetric
Observable.shared.iobText.value = insulinMetric.formattedValue()
}

if let cobMetric = CarbMetric(from: lastLoopRecord["cob"], key: "cob") {
infoManager.updateInfoData(type: .cob, value: cobMetric)
latestCOB = cobMetric
}

Storage.shared.lastIOB.value = latestIOB?.value
Storage.shared.lastCOB.value = latestCOB?.value

if lastLoopRecord["failureReason"] != nil {
Observable.shared.loopStatusText.value = "X"
latestLoopStatusString = "X"
Expand Down Expand Up @@ -52,19 +67,6 @@ extension MainViewController {
Storage.shared.lastTargetLowMgdl.value = profileTargetLow?.doubleValue(for: .milligramsPerDeciliter)
Storage.shared.lastTargetHighMgdl.value = profileTargetHigh?.doubleValue(for: .milligramsPerDeciliter)

// IOB
if let insulinMetric = InsulinMetric(from: lastLoopRecord["iob"], key: "iob") {
infoManager.updateInfoData(type: .iob, value: insulinMetric)
latestIOB = insulinMetric
Observable.shared.iobText.value = insulinMetric.formattedValue()
}

// COB
if let cobMetric = CarbMetric(from: lastLoopRecord["cob"], key: "cob") {
infoManager.updateInfoData(type: .cob, value: cobMetric)
latestCOB = cobMetric
}

if let predictdata = lastLoopRecord["predicted"] as? [String: AnyObject],
let prediction = predictdata["values"] as? [Double],
let lastPrediction = prediction.last
Expand Down Expand Up @@ -132,8 +134,6 @@ extension MainViewController {
}

// Live Activity storage
Storage.shared.lastIOB.value = latestIOB?.value
Storage.shared.lastCOB.value = latestCOB?.value
if let predictdata = lastLoopRecord["predicted"] as? [String: AnyObject],
let values = predictdata["values"] as? [Double]
{
Expand Down
1 change: 1 addition & 0 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class MainViewController: UIViewController, UNUserNotificationCenterDelegate {
var latestCOB: CarbMetric?
var latestBasal = ""
var latestPumpVolume: Double?
var latestPumpBatteryDate: Date?
var latestIOB: InsulinMetric?
var lastOverrideStartTime: TimeInterval = 0
var lastOverrideEndTime: TimeInterval = 0
Expand Down