Skip to content

Commit

Permalink
autoISF - display/edit settings in the preferred units (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurique authored Jan 9, 2025
1 parent 452fa10 commit 45615d6
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 23 deletions.
4 changes: 4 additions & 0 deletions FreeAPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
F2159A592BA78B7400A0B716 /* ContactTrickState.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2159A582BA78B7400A0B716 /* ContactTrickState.swift */; };
F2159A5B2BA7939C00A0B716 /* ContactPicture.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2159A5A2BA7939C00A0B716 /* ContactPicture.swift */; };
F270F68D2BAE374C00F6D8DD /* FontTracking.swift in Sources */ = {isa = PBXBuildFile; fileRef = F270F68C2BAE374C00F6D8DD /* FontTracking.swift */; };
F2FEE7042D2DB1A000A91BB2 /* BGTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2FEE7032D2DB1A000A91BB2 /* BGTextField.swift */; };
F5CA3DB1F9DC8B05792BBFAA /* CGMDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9B5C0607505A38F256BF99A /* CGMDataFlow.swift */; };
F5F7E6C1B7F098F59EB67EC5 /* TargetsEditorDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA49538D56989D8DA6FCF538 /* TargetsEditorDataFlow.swift */; };
F816825E28DB441200054060 /* HeartBeatManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F816825D28DB441200054060 /* HeartBeatManager.swift */; };
Expand Down Expand Up @@ -1062,6 +1063,7 @@
F2159A582BA78B7400A0B716 /* ContactTrickState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactTrickState.swift; sourceTree = "<group>"; };
F2159A5A2BA7939C00A0B716 /* ContactPicture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactPicture.swift; sourceTree = "<group>"; };
F270F68C2BAE374C00F6D8DD /* FontTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontTracking.swift; sourceTree = "<group>"; };
F2FEE7032D2DB1A000A91BB2 /* BGTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BGTextField.swift; sourceTree = "<group>"; };
F816825D28DB441200054060 /* HeartBeatManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeartBeatManager.swift; sourceTree = "<group>"; };
F816825F28DB441800054060 /* BluetoothTransmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BluetoothTransmitter.swift; sourceTree = "<group>"; };
F90692A9274B7AAE0037068D /* HealthKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1838,6 +1840,7 @@
3883582E25EEAFC000E024B2 /* Views */ = {
isa = PBXGroup;
children = (
F2FEE7032D2DB1A000A91BB2 /* BGTextField.swift */,
3811DE5925C9D4D500A708ED /* ViewModifiers.swift */,
3883581B25EE79BB00E024B2 /* DecimalTextField.swift */,
383420D825FFEB3F002D46C1 /* Popup.swift */,
Expand Down Expand Up @@ -3203,6 +3206,7 @@
CC6C406E2ACDD69E009B8058 /* RawFetchedProfile.swift in Sources */,
385CEA8225F23DFD002D6D5B /* NightscoutStatus.swift in Sources */,
F90692AA274B7AAE0037068D /* HealthKitManager.swift in Sources */,
F2FEE7042D2DB1A000A91BB2 /* BGTextField.swift in Sources */,
38887CCE25F5725200944304 /* IOBEntry.swift in Sources */,
38E98A2425F52C9300C0CED0 /* Logger.swift in Sources */,
198F67B62CFCBD5D00E538CB /* AutoISFDataFlow.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2316,19 +2316,19 @@ Enact a temp Basal or a temp target */
"Factor that multiplies your normal regular basal rate for B30. Max Basal rate enacted is the max of your pump max Basal setting. Default is 5." = "Factor that multiplies your normal regular basal rate for B30. Max Basal rate enacted is the max of your pump max Basal setting. Default is 5.";

/* */
"Upper Delta limit in mg/dl for B30" = "Upper Delta limit in mg/dl for B30";
"Upper Delta limit for B30" = "Upper Delta limit for B30";

/* */
"B30 will only run as long as BG delta stays below that level, if above regular autoISF takes over. Default is 8 mg/dl." = "B30 will only run as long as BG delta stays below that level, if above regular autoISF takes over. Default is 8 mg/dl.";

/* */
"Upper BG limit in mg/dl for B30" = "Upper BG limit in mg/dl for B30";
"Upper BG limit for B30" = "Upper BG limit for B30";

/* */
"B30 will only run as long as BG stays underneath that level, if above regular autoISF takes over. Default is 130 mg/dl." = "B30 will only run as long as BG stays underneath that level, if above regular autoISF takes over. Default is 130 mg/dl.";

/* */
"Target Level in mg/dl for B30 to be enacted" = "Target Level in mg/dl for B30 to be enacted";
"Target Level for B30 to be enacted" = "Target Level for B30 to be enacted";

/* */
"An EatingSoon Override Target (or a Temporary Target) needs to be activated to start the B30 adaption. Target needs to be below or equal this setting for B30 AIMI to start. Default is 90 mg/dl. If you cancel this EatingSoon Target, the B30 basal rate will stop." = "An EatingSoon Override Target (or a Temporary Target) needs to be activated to start the B30 adaption. Target needs to be below or equal this setting for B30 AIMI to start. Default is 90 mg/dl. If you cancel this EatingSoon Target, the B30 basal rate will stop.";
Expand Down Expand Up @@ -2397,7 +2397,7 @@ Enact a temp Basal or a temp target */
"SMB Delivery Ratio BG Range" = "SMB Delivery Ratio BG Range";

/* */
"Default value: 0, Sensible is bteween 40 and 120. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the fix smb_delivery_ratio is used." = "Default value: 0, Sensible is bteween 40 and 120. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the fix smb_delivery_ratio is used.";
"Default value: 0, Sensible is between 40 mg/dL and 120 mg/dL. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the fix smb_delivery_ratio is used." = "Default value: 0, Sensible is between 40 mg/dL and 120 mg/dL. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the fix smb_delivery_ratio is used.";

/* */
"SMB DeliveryRatio Maximum" = "SMB DeliveryRatio Maximum";
Expand Down
4 changes: 4 additions & 0 deletions FreeAPS/Sources/Models/BloodGlucose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ extension Decimal {
var asMgdL: Decimal {
self / GlucoseUnits.exchangeRate
}

var rounded: Decimal {
Decimal(round(Double(self)))
}
}

extension Double {
Expand Down
50 changes: 31 additions & 19 deletions FreeAPS/Sources/Modules/AutoISF/View/AutoISFRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ extension AutoISF {
.onTapGesture {
info(
header: "SMB Delivery Ratio BG Range",
body: "Default value: 0, Sensible is bteween 40 and 120. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the standard smb_delivery_ratio is used.",
body: "Default value: 0, Sensible is between 40 mg/dL and 120 mg/dL. The linearly increasing SMB delivery ratio is mapped to the glucose range [target_bg, target_bg+bg_range]. At target_bg the SMB ratio is smb_delivery_ratio_min, at target_bg+bg_range it is smb_delivery_ratio_max. With 0 the linearly increasing SMB ratio is disabled and the standard smb_delivery_ratio is used.",
useGraphics: nil
)
}
Spacer()
DecimalTextField("0", value: $state.smbDeliveryRatioBGrange, formatter: formatter)
.disabled(isPresented)
Text("mg/dl").foregroundStyle(.secondary)
BGTextField(
"0",
mgdlValue: $state.smbDeliveryRatioBGrange,
units: $state.units,
isDisabled: isPresented
)
}

HStack {
Expand Down Expand Up @@ -309,48 +312,57 @@ extension AutoISF {
}

HStack {
Text("Target Level in mg/dl for B30 to be enacted")
Text("Target Level for B30 to be enacted")
.onTapGesture {
info(
header: "Target Level in mg/dl for B30 to be enacted",
header: "Target Level for B30 to be enacted",
body: "An EatingSoon Override Target (or a Temporary Target) needs to be activated to start the B30 adaption. Target needs to be below or equal this setting for B30 AIMI to start. Default is 90 mg/dl. If you cancel this EatingSoon Target, the B30 basal rate will stop.",
useGraphics: nil
)
}
Spacer()
DecimalTextField("0", value: $state.b30targetLevel, formatter: formatter)
.disabled(isPresented)
Text("mg/dl").foregroundStyle(.secondary)
BGTextField(
"0",
mgdlValue: $state.b30targetLevel,
units: $state.units,
isDisabled: isPresented
)
}

HStack {
Text("Upper BG limit in mg/dl for B30")
Text("Upper BG limit for B30")
.onTapGesture {
info(
header: "Upper BG limit in mg/dl for B30",
header: "Upper BG limit for B30",
body: "B30 will only run as long as BG stays underneath that level, if above regular autoISF takes over. Default is 130 mg/dl.",
useGraphics: nil
)
}
Spacer()
DecimalTextField("0", value: $state.b30upperLimit, formatter: formatter)
.disabled(isPresented)
Text("mg/dl").foregroundStyle(.secondary)
BGTextField(
"0",
mgdlValue: $state.b30upperLimit,
units: $state.units,
isDisabled: isPresented
)
}

HStack {
Text("Upper Delta limit in mg/dl for B30")
Text("Upper Delta limit for B30")
.onTapGesture {
info(
header: "Upper Delta limit in mg/dl for B30",
header: "Upper Delta limit for B30",
body: "B30 will only run as long as BG delta stays below that level, if above regular autoISF takes over. Default is 8 mg/dl.",
useGraphics: nil
)
}
Spacer()
DecimalTextField("0", value: $state.b30upperdelta, formatter: formatter)
.disabled(isPresented)
Text("mg/dl").foregroundStyle(.secondary)
BGTextField(
"0",
mgdlValue: $state.b30upperdelta,
units: $state.units,
isDisabled: isPresented
)
}

HStack {
Expand Down
57 changes: 57 additions & 0 deletions FreeAPS/Sources/Views/BGTextField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import SwiftUI

struct BGTextField: View {
let placeholder: String
@Binding var mgdlValue: Decimal
@Binding var units: GlucoseUnits
var isDisabled: Bool

init(
_ placeholder: String,
mgdlValue: Binding<Decimal>,
units: Binding<GlucoseUnits>,
isDisabled: Bool
) {
self.placeholder = placeholder
_mgdlValue = mgdlValue
_units = units
self.isDisabled = isDisabled
}

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

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

private var displayValue: Binding<Decimal> {
Binding(
get: { units == .mmolL ? mgdlValue.asMmolL : mgdlValue },
set: { newValue in mgdlValue = units == .mmolL ? newValue.asMgdL : newValue }
)
}

var body: some View {
HStack {
if units == .mmolL {
DecimalTextField(placeholder, value: displayValue, formatter: mmolLFormatter)
.disabled(isDisabled)
} else {
DecimalTextField(placeholder, value: displayValue, formatter: mgdLFormatter)
.disabled(isDisabled)
}

Text(units == .mmolL ? LocalizedStringKey("mmol/L") : LocalizedStringKey("mg/dL"))
.foregroundStyle(.secondary)
}
}
}

0 comments on commit 45615d6

Please sign in to comment.