Skip to content

Commit

Permalink
Merge branch 'mods_from_iAPS' into trio-bo
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornoleh committed Jun 9, 2024
2 parents 4f092ec + 4a90686 commit 180d618
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"displayHR" : false,
"cgm" : "none",
"cgmManagerTypeByIdentifier":"",
"uploadGlucose" : true,
"uploadGlucose" : false,
"useCalendar" : false,
"glucoseBadge" : false,
"glucoseNotificationsAlways" : false,
Expand Down
26 changes: 13 additions & 13 deletions FreeAPS/Resources/json/defaults/preferences.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"max_iob" : 0,
"max_iob" : 6,
"max_daily_safety_multiplier" : 3,
"current_basal_safety_multiplier" : 4,
"autosens_max" : 1.2,
"autosens_min" : 0.7,
"smb_delivery_ratio" : 0.5,
"rewind_resets_autosens" : true,
"high_temptarget_raises_sensitivity" : false,
"low_temptarget_lowers_sensitivity" : false,
"high_temptarget_raises_sensitivity" : true,
"low_temptarget_lowers_sensitivity" : true,
"sensitivity_raises_target" : false,
"resistance_lowers_target" : false,
"adv_target_adjustments" : false,
Expand All @@ -21,31 +21,31 @@
"autotune_isf_adjustmentFraction" : 1,
"remainingCarbsFraction" : 1,
"remainingCarbsCap" : 90,
"enableUAM" : false,
"enableUAM" : true,
"A52_risk_enable" : false,
"enableSMB_with_COB" : false,
"enableSMB_with_temptarget" : false,
"enableSMB_always" : false,
"enableSMB_always" : true,
"enableSMB_after_carbs" : false,
"allowSMB_with_high_temptarget" : false,
"maxSMBBasalMinutes" : 30,
"maxUAMSMBBasalMinutes" : 30,
"SMBInterval" : 3,
"bolus_increment" : 0.1,
"maxSMBBasalMinutes" : 50,
"maxUAMSMBBasalMinutes" : 40,
"SMBInterval" : 2,
"bolus_increment" : 0.05,
"curve" : "rapid-acting",
"useCustomPeakTime" : false,
"insulinPeakTime" : 75,
"useCustomPeakTime" : true,
"insulinPeakTime" : 60,
"carbsReqThreshold" : 1,
"noisyCGMTargetMultiplier" : 1.3,
"suspend_zeros_iob" : false,
"maxDelta_bg_threshold" : 0.2,
"maxDelta_bg_threshold" : 0.3,
"adjustmentFactor" : 0.8,
"adjustmentFactorSigmoid" : 0.5,
"sigmoid" : false,
"enableDynamicCR" : false,
"useNewFormula" : false,
"useWeightedAverage" : false,
"weightPercentage" : 0.65,
"weightPercentage" : 0.3,
"tddAdjBasal" : false,
"enableSMB_high_bg" : false,
"enableSMB_high_bg_target" : 110,
Expand Down
33 changes: 32 additions & 1 deletion FreeAPS/Sources/APS/CGM/CGMType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
.none:
return nil
case .xdrip:
return URL(string: "xdripswift://")!
return getXdripURL()
case .glucoseDirect:
return URL(string: "libredirect://")!
case .simulator:
Expand All @@ -58,6 +58,37 @@ enum CGMType: String, JSON, CaseIterable, Identifiable {
}
}

func getXdripURL() -> URL {
guard let suiteName = Bundle.main.appGroupSuiteName else {
print("Could not find app group suite name for CGM type: \(rawValue)")
return URL(string: "xdripswift://")!
}

guard let sharedDefaults = UserDefaults(suiteName: suiteName) else {
print("Could not initialize shared user defaults for CGM type: \(rawValue)")
return URL(string: "xdripswift://")!
}

let defaultUrl = URL(string: "xdripswift://")!

if let urlScheme = sharedDefaults.string(forKey: "urlScheme") {
switch urlScheme {
case "xdripswiftLeft":
print("Setting URL scheme: \(urlScheme) for CGM type: \(rawValue)")
return URL(string: "xdripswiftLeft://") ?? defaultUrl
case "xdripswiftRight":
print("Setting URL scheme: \(urlScheme) for CGM type: \(rawValue)")
return URL(string: "xdripswiftRight://") ?? defaultUrl
default:
print("Invalid URL scheme: \(urlScheme) for CGM type: \(rawValue)")
}
} else {
print("URL scheme not found in shared user defaults for CGM type: \(rawValue)")
}

return defaultUrl
}

var externalLink: URL? {
switch self {
case .xdrip:
Expand Down
2 changes: 1 addition & 1 deletion FreeAPS/Sources/Models/FreeAPSSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct FreeAPSSettings: JSON, Equatable {
var displayHR: Bool = false
var cgm: CGMType = .none
var cgmPluginIdentifier: String = ""
var uploadGlucose: Bool = true
var uploadGlucose: Bool = false
var useCalendar: Bool = false
var glucoseBadge: Bool = false
var glucoseNotificationsAlways: Bool = false
Expand Down
26 changes: 13 additions & 13 deletions FreeAPS/Sources/Models/Preferences.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation

struct Preferences: JSON {
var maxIOB: Decimal = 0
var maxIOB: Decimal = 6
var maxDailySafetyMultiplier: Decimal = 3
var currentBasalSafetyMultiplier: Decimal = 4
var autosensMax: Decimal = 1.2
var autosensMin: Decimal = 0.7
var smbDeliveryRatio: Decimal = 0.5
var rewindResetsAutosens: Bool = true
var highTemptargetRaisesSensitivity: Bool = false
var lowTemptargetLowersSensitivity: Bool = false
var highTemptargetRaisesSensitivity: Bool = true
var lowTemptargetLowersSensitivity: Bool = true
var sensitivityRaisesTarget: Bool = false
var resistanceLowersTarget: Bool = false
var advTargetAdjustments: Bool = false
Expand All @@ -23,32 +23,32 @@ struct Preferences: JSON {
var autotuneISFAdjustmentFraction: Decimal = 1.0
var remainingCarbsFraction: Decimal = 1.0
var remainingCarbsCap: Decimal = 90
var enableUAM: Bool = false
var enableUAM: Bool = true
var a52RiskEnable: Bool = false
var enableSMBWithCOB: Bool = false
var enableSMBWithTemptarget: Bool = false
var enableSMBAlways: Bool = false
var enableSMBAlways: Bool = true
var enableSMBAfterCarbs: Bool = false
var allowSMBWithHighTemptarget: Bool = false
var maxSMBBasalMinutes: Decimal = 30
var maxUAMSMBBasalMinutes: Decimal = 30
var smbInterval: Decimal = 3
var bolusIncrement: Decimal = 0.1
var maxSMBBasalMinutes: Decimal = 50
var maxUAMSMBBasalMinutes: Decimal = 40
var smbInterval: Decimal = 2
var bolusIncrement: Decimal = 0.05
var curve: InsulinCurve = .rapidActing
var useCustomPeakTime: Bool = false
var insulinPeakTime: Decimal = 75
var useCustomPeakTime: Bool = true
var insulinPeakTime: Decimal = 60
var carbsReqThreshold: Decimal = 1.0
var noisyCGMTargetMultiplier: Decimal = 1.3
var suspendZerosIOB: Bool = false
var timestamp: Date?
var maxDeltaBGthreshold: Decimal = 0.2
var maxDeltaBGthreshold: Decimal = 0.3
var adjustmentFactor: Decimal = 0.8
var adjustmentFactorSigmoid: Decimal = 0.5
var sigmoid: Bool = false
var enableDynamicCR: Bool = false
var useNewFormula: Bool = false
var useWeightedAverage: Bool = false
var weightPercentage: Decimal = 0.65
var weightPercentage: Decimal = 0.3
var tddAdjBasal: Bool = false
var enableSMB_high_bg: Bool = false
var enableSMB_high_bg_target: Decimal = 110
Expand Down
13 changes: 7 additions & 6 deletions FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension AddCarbs {
.fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) ==
state
.protein
) ? .secondary : .orange
) ? .secondary : .gray
)
.disabled(
(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
Expand Down Expand Up @@ -138,11 +138,12 @@ extension AddCarbs {
.frame(maxWidth: .infinity, alignment: .center)
} footer: { Text(state.waitersNotepad().description) }

if !state.useFPUconversion {
Section {
mealPresets
}
}
/* Hide mealPresets unless enabling useFPUconversion
if !state.useFPUconversion {
Section {
mealPresets
}
} */
}
.onAppear(perform: configureView)
.navigationBarItems(leading: Button("Close", action: state.hideModal))
Expand Down
27 changes: 23 additions & 4 deletions FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ extension Bolus {
}
} else {
HStack {
Text("Insulin recommended")
Text("Insulin required")
Spacer()
Text(
formatter
.string(from: state.insulinRequired as NSNumber)! +
NSLocalizedString(" U", comment: "Insulin unit")
).foregroundColor(.secondary)
}.contentShape(Rectangle())
.onTapGesture {
if state.insulinRequired > 0 {
state.amount = state.insulinRequired }
}
HStack {
Text("Måltidsbolus")
Spacer()
Text(
formatter
Expand All @@ -58,12 +71,12 @@ extension Bolus {
}
}
}
header: { Text("Recommendation") }
// header: { Text("Recommendation") }

if !state.waitForSuggestion {
Section {
HStack {
Text("Amount")
Text("Bolus")
Spacer()
DecimalTextField(
"0",
Expand All @@ -75,7 +88,7 @@ extension Bolus {
Text(state.amount > state.maxBolus ? "⚠️" : "U").foregroundColor(.secondary)
}
}
header: { Text("Bolus") }
// header: { Text("Bolus") }
Section {
Button { state.add() }
label: {
Expand Down Expand Up @@ -173,6 +186,7 @@ extension Bolus {
.font(.footnote)
.padding(.top, 10)
Divider()

// Formula
VStack(spacing: 5) {
let unit = NSLocalizedString(
Expand All @@ -181,6 +195,11 @@ extension Bolus {
)
let color: Color = (state.percentage != 100 && state.insulin > 0) ? .secondary : .blue
let fontWeight: Font.Weight = (state.percentage != 100 && state.insulin > 0) ? .regular : .bold
HStack {
Text("oref0 insulinReq").font(.callout).foregroundColor(.secondary)
Text(state.insulinRequired.formatted() + unit).font(.callout).foregroundColor(.secondary)
}
Divider()
HStack {
Text(NSLocalizedString("Insulin recommended", comment: "") + ":").font(.callout)
Text(state.insulin.formatted() + unit).font(.callout).foregroundColor(color).fontWeight(fontWeight)
Expand Down
4 changes: 2 additions & 2 deletions FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ struct MainChartView: View {
private func tempTargetsView(fullSize: CGSize) -> some View {
ZStack {
tempTargetsPath
.fill(Color.tempBasal.opacity(0.5))
.fill(Color.loopGreen.opacity(0.4))
tempTargetsPath
.stroke(Color.basal.opacity(0.5), lineWidth: 1)
.stroke(Color.loopGreen.opacity(0.5), lineWidth: 1)
}
.onChange(of: glucose) { _ in
calculateTempTargetsRects(fullSize: fullSize)
Expand Down
54 changes: 32 additions & 22 deletions FreeAPS/Sources/Modules/Home/View/HomeRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ extension Home {
return formatter
}

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

private var targetFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
Expand Down Expand Up @@ -312,11 +319,11 @@ extension Home {
var legendPanel: some View {
ZStack {
HStack(alignment: .center) {
Group {
Circle().fill(Color.loopGreen).frame(width: 8, height: 8)
Text("BG")
.font(.system(size: 12, weight: .bold)).foregroundColor(.loopGreen)
}
/* Group {
Circle().fill(Color.loopGreen).frame(width: 8, height: 8)
Text("BG")
.font(.system(size: 12, weight: .bold)).foregroundColor(.loopGreen)
}*/ // hide BG from legend
Group {
Circle().fill(Color.insulin).frame(width: 8, height: 8)
.padding(.leading, 8)
Expand Down Expand Up @@ -344,7 +351,7 @@ extension Home {

if let eventualBG = state.eventualBG {
Text(
"" + numberFormatter.string(
"" + eventualBGFormatter.string(
from: (state.units == .mmolL ? eventualBG.asMmolL : Decimal(eventualBG)) as NSNumber
)!
)
Expand Down Expand Up @@ -560,23 +567,26 @@ extension Home {
.navigationBarHidden(true)
.ignoresSafeArea(.keyboard)
.popup(isPresented: isStatusPopupPresented, alignment: .top, direction: .top) {
popup
.padding()
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color(UIColor.darkGray))
)
.onTapGesture {
isStatusPopupPresented = false
}
.gesture(
DragGesture(minimumDistance: 10, coordinateSpace: .local)
.onEnded { value in
if value.translation.height < 0 {
isStatusPopupPresented = false
VStack {
Rectangle().opacity(0).frame(height: 90)
popup
.padding()
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color(UIColor.darkGray))
)
.onTapGesture {
isStatusPopupPresented = false
}
.gesture(
DragGesture(minimumDistance: 10, coordinateSpace: .local)
.onEnded { value in
if value.translation.height < 0 {
isStatusPopupPresented = false
}
}
}
)
)
}
}
}

Expand Down

0 comments on commit 180d618

Please sign in to comment.