Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mountrcg committed Nov 7, 2024
1 parent 0eadbf3 commit 005e419
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
16 changes: 15 additions & 1 deletion FreeAPS/Sources/APS/APSManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ enum APSError: LocalizedError {
case apsError(message: String)
case deviceSyncError(message: String)
case manualBasalTemp(message: String)

case activeBolusViewBolus
case activeBolusViewBasal
case activeBolusViewBasalandBolus

var errorDescription: String? {
switch self {
case let .pumpError(error):
Expand All @@ -56,6 +59,12 @@ enum APSError: LocalizedError {
return "Sync error: \(message)"
case let .manualBasalTemp(message):
return "Manual Basal Temp : \(message)"
case .activeBolusViewBolus:
return "Suggested SMB not enacted while in Bolus View"
case .activeBolusViewBasal:
return "Suggested Temp Basal (when > 0) not enacted while in Bolus View"
case .activeBolusViewBasalandBolus:
return "Suggested Temp Basal (when > 0) and SMB not enacted while in Bolus View"
}
}
}
Expand Down Expand Up @@ -1299,6 +1308,11 @@ final class BaseAPSManager: APSManager, Injectable {
}
}
}

private func activeBolusView() -> Bool {
let defaults = UserDefaults.standard
return defaults.bool(forKey: IAPSconfig.inBolusView)
}

private func loopStats(loopStatRecord: LoopStats) {
coredataContext.perform {
Expand Down
14 changes: 14 additions & 0 deletions FreeAPS/Sources/Application/FreeAPSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ import Swinject
default: break
}
}

private func isNewVersion() {
let userDefaults = UserDefaults.standard
var version = userDefaults.string(forKey: IAPSconfig.version) ?? ""
userDefaults.set(false, forKey: IAPSconfig.inBolusView)

guard version.count > 1, version == (Bundle.main.releaseVersionNumber ?? "") else {
version = Bundle.main.releaseVersionNumber ?? ""
userDefaults.set(version, forKey: IAPSconfig.version)
userDefaults.set(true, forKey: IAPSconfig.newVersion)
debug(.default, "Running new version: \(version)")
return
}
}
}
5 changes: 5 additions & 0 deletions FreeAPS/Sources/Models/Configs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public enum IAPSconfig {
static let glassShadowOpacity: CGFloat = 0.6
static let shadowFraction: CGFloat = 2
static let minimumCarbEquivalent: Decimal = 0.6
static let id = "iAPS.identifier"
static let version = "iAPS.version"
static let newVersion = "iAPS.newVersion"
static let inBolusView = "iAPS.inBolusView"
static let statURL = URL(string: "https://submit.open-iaps.app")!
}

extension Font {
Expand Down
44 changes: 44 additions & 0 deletions FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ extension Bolus {
@Published var fat: Decimal = 0
@Published var protein: Decimal = 0
@Published var note: String = ""
@Published var eventualBG: Bool = false
@Published var bolusIncrement: Decimal = 0.1
@Published var closedLoop: Bool = false
@Published var loopDate: Date = .distantFuture
@Published var now = Date.now


let loopReminder: CGFloat = 20

private var loopFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 0
return formatter
}


override func subscribe() {
setupInsulinRequired()
Expand All @@ -80,6 +96,8 @@ extension Bolus {
fattyMeals = settings.settings.fattyMeals
fattyMealFactor = settings.settings.fattyMealFactor
displayPredictions = settings.settings.displayPredictions
bolusIncrement = settings.preferences.bolusIncrement
closedLoop = settings.settings.closedLoop

if waitForSuggestionInitial {
apsManager.determineBasal()
Expand Down Expand Up @@ -285,6 +303,32 @@ extension Bolus {
}
return nil
}

func notActive() {
let defaults = UserDefaults.standard
defaults.set(false, forKey: IAPSconfig.inBolusView)
// print("Active: NO") // For testing
}

func viewActive() {
let defaults = UserDefaults.standard
defaults.set(true, forKey: IAPSconfig.inBolusView)
// print("Active: YES") // For testing
}

func lastLoop() -> String? {
guard closedLoop else { return nil }
guard abs(now.timeIntervalSinceNow / 60) > loopReminder else { return nil }
let minAgo = abs(loopDate.timeIntervalSinceNow / 60)

let stringAgo = loopFormatter.string(from: minAgo as NSNumber) ?? ""
return "Last loop \(stringAgo) minutes ago. Complete or cancel this meal/bolus transaction to allow for next loop cycle to run"
}

private func roundBolus(_ amount: Decimal) -> Decimal {
// Account for increments (don't use the APSManager function as that gets too slow)
Decimal(round(Double(amount / bolusIncrement))) * bolusIncrement
}
}
}

Expand Down

0 comments on commit 005e419

Please sign in to comment.