Skip to content

Commit

Permalink
Revert "Merge branch 'overrides' into dev+override"
Browse files Browse the repository at this point in the history
This reverts commit 0994ae3, reversing
changes made to aad337d.
  • Loading branch information
aug0211 committed Jul 7, 2024
1 parent 0994ae3 commit 75ef35b
Show file tree
Hide file tree
Showing 115 changed files with 692 additions and 8,003 deletions.
2 changes: 0 additions & 2 deletions .github/CODEOWNERS

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/add_to_project.yml

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/stale_issues.yml

This file was deleted.

39 changes: 19 additions & 20 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
[submodule "LoopKit"]
path = LoopKit
url = https://github.com/loopandlearn/LoopKit.git
branch = trio
url = https://github.com/LoopKit/LoopKit.git
branch = dev
[submodule "CGMBLEKit"]
path = CGMBLEKit
url = https://github.com/loopandlearn/CGMBLEKit.git
branch = trio
url = https://github.com/LoopKit/CGMBLEKit.git
branch = dev
[submodule "dexcom-share-client-swift"]
path = dexcom-share-client-swift
url = https://github.com/loopandlearn/dexcom-share-client-swift.git
branch = trio
url = https://github.com/LoopKit/dexcom-share-client-swift.git
branch = dev
[submodule "RileyLinkKit"]
path = RileyLinkKit
url = https://github.com/loopandlearn/RileyLinkKit
branch = trio
url = https://github.com/LoopKit/RileyLinkKit
branch = dev
[submodule "OmniBLE"]
path = OmniBLE
url = https://github.com/loopandlearn/OmniBLE.git
branch = trio
url = https://github.com/LoopKit/OmniBLE.git
branch = dev
[submodule "G7SensorKit"]
path = G7SensorKit
url = https://github.com/loopandlearn/G7SensorKit.git
branch = trio
url = https://github.com/LoopKit/G7SensorKit.git
branch = main
[submodule "OmniKit"]
path = OmniKit
url = https://github.com/loopandlearn/OmniKit.git
branch = trio
url = https://github.com/LoopKit/OmniKit.git
branch = main
[submodule "MinimedKit"]
path = MinimedKit
url = https://github.com/loopandlearn/MinimedKit.git
branch = trio
url = https://github.com/LoopKit/MinimedKit.git
branch = main
[submodule "LibreTransmitter"]
path = LibreTransmitter
url = https://github.com/loopandlearn/LibreTransmitter.git
branch = trio
url = https://github.com/LoopKit/LibreTransmitter.git
branch = main
[submodule "TidepoolService"]
path = TidepoolService
url = https://github.com/loopandlearn/TidepoolService.git
branch = trio
url = https://github.com/LoopKit/TidepoolService.git
156 changes: 4 additions & 152 deletions FreeAPS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/autosens.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/autotune-prep.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/iob.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/meal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FreeAPS/Resources/javascript/bundle/profile.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"oneDimensionalGraph" : false,
"rulerMarks" : true,
"maxCarbs": 250,
"maxFat": 250,
"maxProtein": 250,
"displayFatAndProteinOnWatch": false,
"confirmBolusFaster": false,
"lockScreenView": "simple"
}
2 changes: 1 addition & 1 deletion FreeAPS/Resources/json/defaults/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"tddAdjBasal" : false,
"enableSMB_high_bg" : false,
"enableSMB_high_bg_target" : 110,
"threshold_setting" : 60,
"threshold_setting" : 65,
"updateInterval" : 20
}
52 changes: 22 additions & 30 deletions FreeAPS/Sources/APS/CGM/PluginSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,7 @@ final class PluginSource: GlucoseSource {
cgmManager?.cgmManagerDelegate = self
}

/// Function that fetches blood glucose data
/// This function combines two data fetching mechanisms (`callBLEFetch` and `fetchIfNeeded`) into a single publisher.
/// It returns the first non-empty result from either of the sources within a 5-minute timeout period.
/// If no valid data is fetched within the timeout, it returns an empty array.
///
/// - Parameter timer: An optional `DispatchTimer` (not used in the function but can be used to trigger fetch logic).
/// - Returns: An `AnyPublisher` that emits an array of `BloodGlucose` values or an empty array if an error occurs or the timeout is reached.
func fetch(_: DispatchTimer?) -> AnyPublisher<[BloodGlucose], Never> {
Publishers.Merge(
callBLEFetch(),
fetchIfNeeded()
)
.filter { !$0.isEmpty }
.first()
.timeout(60 * 5, scheduler: processQueue, options: nil, customError: nil)
.replaceError(with: [])
.eraseToAnyPublisher()
}

func callBLEFetch() -> AnyPublisher<[BloodGlucose], Never> {
Future<[BloodGlucose], Error> { [weak self] promise in
self?.promise = promise
}
Expand All @@ -54,15 +35,17 @@ final class PluginSource: GlucoseSource {
}

func fetchIfNeeded() -> AnyPublisher<[BloodGlucose], Never> {
Future<[BloodGlucose], Error> { [weak self] promise in
guard let self = self else { return }
Future<[BloodGlucose], Error> { _ in
self.processQueue.async {
guard let cgmManager = self.cgmManager else { return }
cgmManager.fetchNewDataIfNeeded { result in
promise(self.readCGMResult(readingResult: result))
self.processCGMReadingResult(cgmManager, readingResult: result) {
// nothing to do
}
}
}
}
.timeout(60, scheduler: processQueue, options: nil, customError: nil)
.replaceError(with: [])
.replaceEmpty(with: [])
.eraseToAnyPublisher()
Expand Down Expand Up @@ -109,10 +92,11 @@ extension PluginSource: CGMManagerDelegate {
glucoseManager?.cgmGlucoseSourceType = .none
}

func cgmManager(_: CGMManager, hasNew readingResult: CGMReadingResult) {
func cgmManager(_ manager: CGMManager, hasNew readingResult: CGMReadingResult) {
dispatchPrecondition(condition: .onQueue(processQueue))
promise?(readCGMResult(readingResult: readingResult))
debug(.deviceManager, "CGM PLUGIN - Direct return done")
processCGMReadingResult(manager, readingResult: readingResult) {
debug(.deviceManager, "CGM PLUGIN - Direct return done")
}
}

func cgmManager(_: LoopKit.CGMManager, hasNew events: [LoopKit.PersistedCgmEvent]) {
Expand Down Expand Up @@ -156,7 +140,11 @@ extension PluginSource: CGMManagerDelegate {
}
}

private func readCGMResult(readingResult: CGMReadingResult) -> Result<[BloodGlucose], Error> {
private func processCGMReadingResult(
_: CGMManager,
readingResult: CGMReadingResult,
completion: @escaping () -> Void
) {
debug(.deviceManager, "PLUGIN CGM - Process CGM Reading Result launched with \(readingResult)")
switch readingResult {
case let .newData(values):
Expand Down Expand Up @@ -189,14 +177,18 @@ extension PluginSource: CGMManagerDelegate {
transmitterID: sensorTransmitterID
)
}
return .success(bloodGlucose)
promise?(.success(bloodGlucose))
completion()
case .unreliableData:
// loopManager.receivedUnreliableCGMReading()
return .failure(GlucoseDataError.unreliableData)
promise?(.failure(GlucoseDataError.unreliableData))
completion()
case .noData:
return .failure(GlucoseDataError.noData)
promise?(.failure(GlucoseDataError.noData))
completion()
case let .error(error):
return .failure(error)
promise?(.failure(error))
completion()
}
}
}
Expand Down
66 changes: 49 additions & 17 deletions FreeAPS/Sources/APS/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ private let staticPumpManagersByIdentifier: [String: PumpManagerUI.Type] = [
MockPumpManager.pluginIdentifier: MockPumpManager.self
]

// private let staticPumpManagersByIdentifier: [String: PumpManagerUI.Type] = staticPumpManagers.reduce(into: [:]) { map, Type in
// map[Type.managerIdentifier] = Type
// }

private let accessLock = NSRecursiveLock(label: "BaseDeviceDataManager.accessLock")

final class BaseDeviceDataManager: DeviceDataManager, Injectable {
Expand Down Expand Up @@ -74,8 +78,7 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
didSet {
pumpManager?.pumpManagerDelegate = self
pumpManager?.delegateQueue = processQueue
rawPumpManager = pumpManager?.rawValue
UserDefaults.standard.clearLegacyPumpManagerRawValue()
UserDefaults.standard.pumpManagerRawValue = pumpManager?.rawValue
if let pumpManager = pumpManager {
pumpDisplayState.value = PumpDisplayState(name: pumpManager.localizedTitle, image: pumpManager.smallImage)
pumpName.send(pumpManager.localizedTitle)
Expand All @@ -102,8 +105,6 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
}
}

@PersistedProperty(key: "PumpManagerState") var rawPumpManager: PumpManager.RawValue?

var bluetoothManager: BluetoothStateManager { bluetoothProvider }

var hasBLEHeartbeat: Bool {
Expand All @@ -122,11 +123,7 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
}

func setupPumpManager() {
if let pumpManagerRawValue = rawPumpManager ?? UserDefaults.standard.legacyPumpManagerRawValue {
pumpManager = pumpManagerFromRawValue(pumpManagerRawValue)
} else {
pumpManager = nil
}
pumpManager = UserDefaults.standard.pumpManagerRawValue.flatMap { pumpManagerFromRawValue($0) }
}

func createBolusProgressReporter() -> DoseProgressReporter? {
Expand Down Expand Up @@ -166,6 +163,20 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
self.updateUpdateFinished(true)
}
}

// pumpUpdateCancellable = Future<Bool, Never> { [unowned self] promise in
// pumpUpdatePromise = promise
// debug(.deviceManager, "Waiting for pump update and loop recommendation")
// processQueue.safeSync {
// pumpManager.ensureCurrentPumpData { _ in
// debug(.deviceManager, "Pump data updated.")
// }
// }
// }
// .timeout(30, scheduler: processQueue)
// .replaceError(with: false)
// .replaceEmpty(with: false)
// .sink(receiveValue: updateUpdateFinished)
}

private func updateUpdateFinished(_ recommendsLoop: Bool) {
Expand All @@ -175,6 +186,11 @@ final class BaseDeviceDataManager: DeviceDataManager, Injectable {
warning(.deviceManager, "Loop recommendation time out or got error. Trying to loop right now.")
}

// directly in loop() function
// guard !loopInProgress else {
// warning(.deviceManager, "Loop already in progress. Skip recommendation.")
// return
// }
self.recommendsLoop.send()
}

Expand Down Expand Up @@ -303,7 +319,7 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
}

func pumpManagerDidUpdateState(_ pumpManager: PumpManager) {
rawPumpManager = pumpManager.rawValue
UserDefaults.standard.pumpManagerRawValue = pumpManager.rawValue
if self.pumpManager == nil, let newPumpManager = pumpManager as? PumpManagerUI {
self.pumpManager = newPumpManager
}
Expand Down Expand Up @@ -415,9 +431,6 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
func pumpManagerWillDeactivate(_: PumpManager) {
dispatchPrecondition(condition: .onQueue(processQueue))
pumpManager = nil
broadcaster.notify(PumpDeactivatedObserver.self, on: processQueue) {
$0.pumpDeactivatedDidChange()
}
}

func pumpManager(_: PumpManager, didUpdatePumpRecordsBasalProfileStartEvents _: Bool) {}
Expand Down Expand Up @@ -524,6 +537,29 @@ extension BaseDeviceDataManager: DeviceManagerDelegate {

func recordRetractedAlert(_: Alert, at _: Date) {}

// func scheduleNotification(
// for _: DeviceManager,
// identifier: String,
// content: UNNotificationContent,
// trigger: UNNotificationTrigger?
// ) {
// let request = UNNotificationRequest(
// identifier: identifier,
// content: content,
// trigger: trigger
// )
//
// DispatchQueue.main.async {
// UNUserNotificationCenter.current().add(request)
// }
// }
//
// func clearNotification(for _: DeviceManager, identifier: String) {
// DispatchQueue.main.async {
// UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [identifier])
// }
// }

func removeNotificationRequests(for _: DeviceManager, identifiers: [String]) {
DispatchQueue.main.async {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
Expand Down Expand Up @@ -631,7 +667,3 @@ protocol PumpReservoirObserver {
protocol PumpBatteryObserver {
func pumpBatteryDidChange(_ battery: Battery)
}

protocol PumpDeactivatedObserver {
func pumpDeactivatedDidChange()
}
Loading

0 comments on commit 75ef35b

Please sign in to comment.