diff --git a/Common/HKUnit.swift b/Common/HKUnit.swift deleted file mode 100644 index 69e6f9a..0000000 --- a/Common/HKUnit.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// HKUnit.swift -// xDripG5 -// -// Created by Nate Racklyeft on 8/6/16. -// Copyright © 2016 Nathan Racklyeft. All rights reserved. -// - -import HealthKit - - -extension HKUnit { - static let milligramsPerDeciliter: HKUnit = { - return HKUnit.gramUnit(with: .milli).unitDivided(by: HKUnit.literUnit(with: .deci)) - }() - - static let milligramsPerDeciliterPerMinute: HKUnit = { - return HKUnit.milligramsPerDeciliter.unitDivided(by: .minute()) - }() -} diff --git a/G7SensorKit.xcodeproj/project.pbxproj b/G7SensorKit.xcodeproj/project.pbxproj index 9868d2d..e7c0f76 100644 --- a/G7SensorKit.xcodeproj/project.pbxproj +++ b/G7SensorKit.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ C10760812F05B41B008B2B39 /* ExtendedVersionMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C10760802F05B412008B2B39 /* ExtendedVersionMessageTests.swift */; }; C109F14A291ECCE2008EA5B6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C109F149291ECCE2008EA5B6 /* Assets.xcassets */; }; C109F14C291ED66F008EA5B6 /* G7GlucoseMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C109F14B291ED66F008EA5B6 /* G7GlucoseMessageTests.swift */; }; - C139829829295D7D0047DB5F /* HKUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F514A291EB6F000555EB5 /* HKUnit.swift */; }; C1409A07291EC21C006BE8D0 /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F5126291EAF2F00555EB5 /* OSLog.swift */; }; C1409A09291EC22F006BE8D0 /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1409A08291EC22F006BE8D0 /* OSLog.swift */; }; C1409A0B291EC258006BE8D0 /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1409A0A291EC258006BE8D0 /* OSLog.swift */; }; @@ -54,7 +53,6 @@ C17F5145291EB45900555EB5 /* CBPeripheral.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F5144291EB45900555EB5 /* CBPeripheral.swift */; }; C17F5147291EB57700555EB5 /* SensorMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F5146291EB57700555EB5 /* SensorMessage.swift */; }; C17F5149291EB6B600555EB5 /* LocalizedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F5148291EB6B600555EB5 /* LocalizedString.swift */; }; - C17F514B291EB6F000555EB5 /* HKUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F514A291EB6F000555EB5 /* HKUnit.swift */; }; C17F514D291EB79E00555EB5 /* AlgorithmError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F514C291EB79E00555EB5 /* AlgorithmError.swift */; }; C17F514F291EB87600555EB5 /* G7SensorKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C17F50C6291EAC3800555EB5 /* G7SensorKit.framework */; }; C17F5156291EBD8600555EB5 /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = C17F5155291EBD8600555EB5 /* Image.swift */; }; @@ -155,7 +153,6 @@ C17F5144291EB45900555EB5 /* CBPeripheral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CBPeripheral.swift; sourceTree = ""; }; C17F5146291EB57700555EB5 /* SensorMessage.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; path = SensorMessage.swift; sourceTree = ""; }; C17F5148291EB6B600555EB5 /* LocalizedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalizedString.swift; sourceTree = ""; }; - C17F514A291EB6F000555EB5 /* HKUnit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HKUnit.swift; sourceTree = ""; }; C17F514C291EB79E00555EB5 /* AlgorithmError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlgorithmError.swift; sourceTree = ""; }; C17F5155291EBD8600555EB5 /* Image.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = ""; }; C17F5158291EBE7500555EB5 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -315,7 +312,6 @@ C17F5137291EB0A800555EB5 /* Data.swift */, C17F5148291EB6B600555EB5 /* LocalizedString.swift */, C17F513B291EB13D00555EB5 /* Locked.swift */, - C17F514A291EB6F000555EB5 /* HKUnit.swift */, C17F513F291EB27D00555EB5 /* TimeInterval.swift */, ); path = Common; @@ -585,7 +581,6 @@ C17F5135291EB06A00555EB5 /* AlgorithmState.swift in Sources */, C17F50F1291EAC6500555EB5 /* G7BluetoothManager.swift in Sources */, C17F5138291EB0A800555EB5 /* Data.swift in Sources */, - C17F514B291EB6F000555EB5 /* HKUnit.swift in Sources */, C17F50EC291EAC6500555EB5 /* G7LastReading.swift in Sources */, C17F513C291EB13D00555EB5 /* Locked.swift in Sources */, C17F513E291EB1A500555EB5 /* BluetoothServices.swift in Sources */, @@ -616,7 +611,6 @@ C17F5157291EBD9900555EB5 /* TimeInterval.swift in Sources */, C19C9F4E29C91C4C00A6D3D0 /* LocalizedString.swift in Sources */, C17F5156291EBD8600555EB5 /* Image.swift in Sources */, - C139829829295D7D0047DB5F /* HKUnit.swift in Sources */, C1409A07291EC21C006BE8D0 /* OSLog.swift in Sources */, C17F510A291EAC9D00555EB5 /* G7UICoordinator.swift in Sources */, C17F5109291EAC9D00555EB5 /* G7CGMManager+UI.swift in Sources */, @@ -712,7 +706,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.1; + IPHONEOS_DEPLOYMENT_TARGET = 17.6; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; LOCALIZED_STRING_MACRO_NAMES = ( NSLocalizedString, @@ -775,7 +769,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.1; + IPHONEOS_DEPLOYMENT_TARGET = 17.6; LOCALIZATION_PREFERS_STRING_CATALOGS = YES; LOCALIZED_STRING_MACRO_NAMES = ( NSLocalizedString, diff --git a/G7SensorKit/G7CGMManager/G7BackfillMessage.swift b/G7SensorKit/G7CGMManager/G7BackfillMessage.swift index 90cc3eb..75d6099 100644 --- a/G7SensorKit/G7CGMManager/G7BackfillMessage.swift +++ b/G7SensorKit/G7CGMManager/G7BackfillMessage.swift @@ -8,6 +8,7 @@ import Foundation import LoopKit +import LoopAlgorithm public struct G7BackfillMessage: Equatable { diff --git a/G7SensorKit/G7CGMManager/G7CGMManager.swift b/G7SensorKit/G7CGMManager/G7CGMManager.swift index 3fdc27b..d940208 100644 --- a/G7SensorKit/G7CGMManager/G7CGMManager.swift +++ b/G7SensorKit/G7CGMManager/G7CGMManager.swift @@ -7,9 +7,10 @@ // import Foundation +import HealthKit +import LoopAlgorithm import LoopKit import os.log -import HealthKit @@ -19,6 +20,12 @@ public protocol G7StateObserver: AnyObject { } public class G7CGMManager: CGMManager { + public var inSignalLoss: Bool = false + + public var isInoperable: Bool { + cgmManagerStatus.isInoperable + } + private let log = OSLog(category: "G7CGMManager") public var state: G7CGMManagerState { @@ -233,14 +240,12 @@ public class G7CGMManager: CGMManager { return lines.joined(separator: "\n") } - public func acknowledgeAlert(alertIdentifier: LoopKit.Alert.AlertIdentifier, completion: @escaping (Error?) -> Void) { - completion(nil) - } + public func acknowledgeAlert(alertIdentifier: Alert.AlertIdentifier) async throws { } public func getSoundBaseURL() -> URL? { return nil } public func getSounds() -> [Alert.Sound] { return [] } - public static let pluginIdentifier: String = "G7CGMManager" + public let pluginIdentifier: String = "G7CGMManager" public let localizedTitle = LocalizedString("Dexcom G7", comment: "CGM display title") @@ -395,8 +400,8 @@ extension G7CGMManager: G7SensorDelegate { return } - let unit = HKUnit.milligramsPerDeciliter - let quantity = HKQuantity(unit: unit, doubleValue: Double(min(max(glucose, GlucoseLimits.minimum), GlucoseLimits.maximum))) + let unit = LoopUnit.milligramsPerDeciliter + let quantity = LoopQuantity(unit: unit, doubleValue: Double(min(max(glucose, GlucoseLimits.minimum), GlucoseLimits.maximum))) updateDelegate(with: .newData([ NewGlucoseSample( @@ -431,7 +436,7 @@ extension G7CGMManager: G7SensorDelegate { return } - let unit = HKUnit.milligramsPerDeciliter + let unit = LoopUnit.milligramsPerDeciliter let samples = backfill.compactMap { entry -> NewGlucoseSample? in guard let glucose = entry.glucose else { @@ -443,7 +448,7 @@ extension G7CGMManager: G7SensorDelegate { return nil } - let quantity = HKQuantity(unit: unit, doubleValue: Double(min(max(glucose, GlucoseLimits.minimum), GlucoseLimits.maximum))) + let quantity = LoopQuantity(unit: unit, doubleValue: Double(min(max(glucose, GlucoseLimits.minimum), GlucoseLimits.maximum))) return NewGlucoseSample( date: activationDate.addingTimeInterval(TimeInterval(entry.timestamp)), @@ -469,11 +474,11 @@ extension G7CGMManager: G7SensorDelegate { } extension G7BackfillMessage { - public var trendRate: HKQuantity? { + public var trendRate: LoopQuantity? { guard let trend = trend else { return nil } - return HKQuantity(unit: .milligramsPerDeciliterPerMinute, doubleValue: trend) + return LoopQuantity(unit: .milligramsPerDeciliterPerMinute, doubleValue: trend) } } @@ -482,18 +487,18 @@ extension G7GlucoseMessage: GlucoseDisplayable { return hasReliableGlucose } - public var trendRate: HKQuantity? { + public var trendRate: LoopQuantity? { guard let trend = trend else { return nil } - return HKQuantity(unit: .milligramsPerDeciliterPerMinute, doubleValue: trend) + return LoopQuantity(unit: .milligramsPerDeciliterPerMinute, doubleValue: trend) } - public var glucoseQuantity: HKQuantity? { + public var glucoseQuantity: LoopQuantity? { guard let glucose = glucose else { return nil } - return HKQuantity(unit: .milligramsPerDeciliter, doubleValue: Double(glucose)) + return LoopQuantity(unit: .milligramsPerDeciliter, doubleValue: Double(glucose)) } public var isLocal: Bool { diff --git a/G7SensorKit/G7CGMManager/G7Sensor.swift b/G7SensorKit/G7CGMManager/G7Sensor.swift index b7c7023..3507d17 100644 --- a/G7SensorKit/G7CGMManager/G7Sensor.swift +++ b/G7SensorKit/G7CGMManager/G7Sensor.swift @@ -8,7 +8,6 @@ import Foundation import CoreBluetooth -import HealthKit import os.log diff --git a/G7SensorKit/Messages/G7GlucoseMessage.swift b/G7SensorKit/Messages/G7GlucoseMessage.swift index e0594a3..93cbd10 100644 --- a/G7SensorKit/Messages/G7GlucoseMessage.swift +++ b/G7SensorKit/Messages/G7GlucoseMessage.swift @@ -8,6 +8,7 @@ import Foundation import LoopKit +import LoopAlgorithm public struct G7GlucoseMessage: SensorMessage, Equatable { //public let status: UInt8 diff --git a/G7SensorKitUI/Views/G7SettingsViewModel.swift b/G7SensorKitUI/Views/G7SettingsViewModel.swift index cef7a29..5db9064 100644 --- a/G7SensorKitUI/Views/G7SettingsViewModel.swift +++ b/G7SensorKitUI/Views/G7SettingsViewModel.swift @@ -10,7 +10,6 @@ import Foundation import G7SensorKit import LoopKit import LoopKitUI -import HealthKit public enum ColorStyle { case glucose, warning, critical, normal, dimmed @@ -191,7 +190,7 @@ class G7SettingsViewModel: ObservableObject { var lastGlucoseTrendString: String { if let lastReading = lastReading, lastReading.hasReliableGlucose, let trendRate = lastReading.trendRate { - return displayGlucosePreference.minuteRateFormatter.string(from: trendRate)! + return displayGlucosePreference.formatMinuteRate(trendRate) } else { return "" }