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
12 changes: 10 additions & 2 deletions LoopFollow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
656F8C102E49F36F0008DC1D /* QRCodeDisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656F8C0F2E49F36F0008DC1D /* QRCodeDisplayView.swift */; };
656F8C122E49F3780008DC1D /* QRCodeGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656F8C112E49F3780008DC1D /* QRCodeGenerator.swift */; };
656F8C142E49F3D20008DC1D /* RemoteCommandSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656F8C132E49F3D20008DC1D /* RemoteCommandSettings.swift */; };
65E153C32E4BB69100693A4F /* URLTokenValidationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E153C22E4BB69100693A4F /* URLTokenValidationView.swift */; };
6584B1012E4A263900135D4D /* TOTPService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6584B1002E4A263900135D4D /* TOTPService.swift */; };
65E153C32E4BB69100693A4F /* URLTokenValidationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E153C22E4BB69100693A4F /* URLTokenValidationView.swift */; };
65E8A2862E44B0300065037B /* VolumeButtonHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E8A2852E44B0300065037B /* VolumeButtonHandler.swift */; };
DD0247592DB2E89600FCADF6 /* AlarmCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0247582DB2E89600FCADF6 /* AlarmCondition.swift */; };
DD0247712DB4337700FCADF6 /* BuildExpireCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD02475B2DB2E8FB00FCADF6 /* BuildExpireCondition.swift */; };
DD026E592EA2C8A200A39CB5 /* InsulinPrecisionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD026E582EA2C8A200A39CB5 /* InsulinPrecisionManager.swift */; };
DD026E5B2EA2C9C300A39CB5 /* InsulinFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD026E5A2EA2C9C300A39CB5 /* InsulinFormatter.swift */; };
DD0650A92DCA8A10004D3B41 /* AlarmBGSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0650A82DCA8A10004D3B41 /* AlarmBGSection.swift */; };
DD0650EB2DCE8385004D3B41 /* LowBGCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0650EA2DCE8385004D3B41 /* LowBGCondition.swift */; };
DD0650ED2DCE9371004D3B41 /* HighBgAlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0650EC2DCE9371004D3B41 /* HighBgAlarmEditor.swift */; };
Expand Down Expand Up @@ -408,12 +410,14 @@
656F8C0F2E49F36F0008DC1D /* QRCodeDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeDisplayView.swift; sourceTree = "<group>"; };
656F8C112E49F3780008DC1D /* QRCodeGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeGenerator.swift; sourceTree = "<group>"; };
656F8C132E49F3D20008DC1D /* RemoteCommandSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteCommandSettings.swift; sourceTree = "<group>"; };
65E153C22E4BB69100693A4F /* URLTokenValidationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLTokenValidationView.swift; sourceTree = "<group>"; };
6584B1002E4A263900135D4D /* TOTPService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TOTPService.swift; sourceTree = "<group>"; };
65E153C22E4BB69100693A4F /* URLTokenValidationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLTokenValidationView.swift; sourceTree = "<group>"; };
65E8A2852E44B0300065037B /* VolumeButtonHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VolumeButtonHandler.swift; sourceTree = "<group>"; };
A7D55B42A22051DAD69E89D0 /* Pods_LoopFollow.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LoopFollow.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DD0247582DB2E89600FCADF6 /* AlarmCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmCondition.swift; sourceTree = "<group>"; };
DD02475B2DB2E8FB00FCADF6 /* BuildExpireCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildExpireCondition.swift; sourceTree = "<group>"; };
DD026E582EA2C8A200A39CB5 /* InsulinPrecisionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsulinPrecisionManager.swift; sourceTree = "<group>"; };
DD026E5A2EA2C9C300A39CB5 /* InsulinFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsulinFormatter.swift; sourceTree = "<group>"; };
DD0650A82DCA8A10004D3B41 /* AlarmBGSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmBGSection.swift; sourceTree = "<group>"; };
DD0650EA2DCE8385004D3B41 /* LowBGCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LowBGCondition.swift; sourceTree = "<group>"; };
DD0650EC2DCE9371004D3B41 /* HighBgAlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighBgAlarmEditor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1505,6 +1509,8 @@
FCC688542489367300A0279D /* Helpers */ = {
isa = PBXGroup;
children = (
DD026E5A2EA2C9C300A39CB5 /* InsulinFormatter.swift */,
DD026E582EA2C8A200A39CB5 /* InsulinPrecisionManager.swift */,
656F8C112E49F3780008DC1D /* QRCodeGenerator.swift */,
DD4A407D2E6AFEE6007B318B /* AuthService.swift */,
DD1D52B82E1EB5DC00432050 /* TabPosition.swift */,
Expand Down Expand Up @@ -1971,6 +1977,7 @@
DD48780E2C7B74A40048F05C /* TrioRemoteControlViewModel.swift in Sources */,
DDEF503A2D31615000999A5D /* LogManager.swift in Sources */,
DD4878172C7B75350048F05C /* BolusView.swift in Sources */,
DD026E592EA2C8A200A39CB5 /* InsulinPrecisionManager.swift in Sources */,
DD493AE72ACF23CF009A6922 /* DeviceStatus.swift in Sources */,
DDC7E5162DBCFA7F00EB1127 /* SnoozerView.swift in Sources */,
FCFEECA2248857A600402A7F /* SettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -2085,6 +2092,7 @@
DD0C0C662C46E54C00DBADDF /* InfoDataSeparator.swift in Sources */,
DD58171C2D299F940041FB98 /* BluetoothDevice.swift in Sources */,
DD7E198A2ACDA62600DBD158 /* SensorStart.swift in Sources */,
DD026E5B2EA2C9C300A39CB5 /* InsulinFormatter.swift in Sources */,
DD5334B02D1447C500CDD6EA /* BLEManager.swift in Sources */,
DD4878032C7B297E0048F05C /* StorageValue.swift in Sources */,
DD4878192C7C56D60048F05C /* TrioNightscoutRemoteController.swift in Sources */,
Expand Down
59 changes: 40 additions & 19 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import Charts
import Foundation
import HealthKit
import UIKit

extension MainViewController {
Expand Down Expand Up @@ -95,36 +96,56 @@ extension MainViewController {
.withTime,
.withDashSeparatorInDate,
.withColonSeparatorInTime]

Observable.shared.previousAlertLastLoopTime.value = Observable.shared.alertLastLoopTime.value

if let lastPumpRecord = lastDeviceStatus?["pump"] as! [String: AnyObject]? {
if let lastPumpTime = formatter.date(from: (lastPumpRecord["clock"] as! String))?.timeIntervalSince1970 {
if let bolusIncrement = lastPumpRecord["bolusIncrement"] as? Double, bolusIncrement > 0 {
Storage.shared.bolusIncrement.value = HKQuantity(unit: .internationalUnit(), doubleValue: bolusIncrement)
Storage.shared.bolusIncrementDetected.value = true
} else if let model = lastPumpRecord["model"] as? String, model == "Dash" {
Storage.shared.bolusIncrement.value = HKQuantity(unit: .internationalUnit(), doubleValue: 0.05)
Storage.shared.bolusIncrementDetected.value = true
} else {
Storage.shared.bolusIncrementDetected.value = false
}

if let clockString = lastPumpRecord["clock"] as? String,
let lastPumpTime = formatter.date(from: clockString)?.timeIntervalSince1970
{
let storedTime = Observable.shared.alertLastLoopTime.value ?? 0
if lastPumpTime > storedTime {
Observable.shared.alertLastLoopTime.value = lastPumpTime
}

if let reservoirData = lastPumpRecord["reservoir"] as? Double {
latestPumpVolume = reservoirData
infoManager.updateInfoData(type: .pump, value: String(format: "%.0f", reservoirData) + "U")
} else {
latestPumpVolume = 50.0
infoManager.updateInfoData(type: .pump, value: "50+U")
}
}

if let uploader = lastDeviceStatus?["uploader"] as? [String: AnyObject],
let upbat = uploader["battery"] as? Double
{
let batteryText: String
if let isCharging = uploader["isCharging"] as? Bool, isCharging {
batteryText = "⚡️ " + String(format: "%.0f", upbat) + "%"
} else {
batteryText = String(format: "%.0f", upbat) + "%"
}
infoManager.updateInfoData(type: .battery, value: batteryText)
Observable.shared.deviceBatteryLevel.value = upbat
if let uploader = lastDeviceStatus?["uploader"] as? [String: AnyObject],
let upbat = uploader["battery"] as? Double
{
let batteryText: String
if let isCharging = uploader["isCharging"] as? Bool, isCharging {
batteryText = "⚡️ " + String(format: "%.0f", upbat) + "%"
} else {
batteryText = String(format: "%.0f", upbat) + "%"
}
infoManager.updateInfoData(type: .battery, value: batteryText)
Observable.shared.deviceBatteryLevel.value = upbat

let timestamp = uploader["timestamp"] as? Date ?? Date()
let currentBattery = DataStructs.batteryStruct(batteryLevel: upbat, timestamp: timestamp)
deviceBatteryData.append(currentBattery)
let timestamp = uploader["timestamp"] as? Date ?? Date()
let currentBattery = DataStructs.batteryStruct(batteryLevel: upbat, timestamp: timestamp)
deviceBatteryData.append(currentBattery)

// store only the last 30 battery readings
if deviceBatteryData.count > 30 {
deviceBatteryData.removeFirst()
}
// store only the last 30 battery readings
if deviceBatteryData.count > 30 {
deviceBatteryData.removeFirst()
}
}
}
Expand Down
Loading