AlgorithmAdvancedSettingsRootView.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import SwiftUI
  2. import Swinject
  3. extension AlgorithmAdvancedSettings {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @State var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: AnyView?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. @EnvironmentObject var appIcons: Icons
  15. private var color: LinearGradient {
  16. colorScheme == .dark ? LinearGradient(
  17. gradient: Gradient(colors: [
  18. Color.bgDarkBlue,
  19. Color.bgDarkerDarkBlue
  20. ]),
  21. startPoint: .top,
  22. endPoint: .bottom
  23. )
  24. :
  25. LinearGradient(
  26. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  27. startPoint: .top,
  28. endPoint: .bottom
  29. )
  30. }
  31. var body: some View {
  32. List {
  33. Section(
  34. header: Text("DISCLAIMER"),
  35. content: {
  36. VStack(alignment: .leading) {
  37. Text(
  38. "The settings in this section typically do not require ANY modifications. Do not alter them without a solid understanding of what you are changing and the full impact it will have on the algorithm."
  39. ).bold()
  40. }
  41. }
  42. ).listRowBackground(Color.tabBar)
  43. SettingInputSection(
  44. decimalValue: $state.maxDailySafetyMultiplier,
  45. booleanValue: $booleanPlaceholder,
  46. shouldDisplayHint: $shouldDisplayHint,
  47. selectedVerboseHint: Binding(
  48. get: { selectedVerboseHint },
  49. set: {
  50. selectedVerboseHint = $0.map { AnyView($0) }
  51. hintLabel = NSLocalizedString("Max Daily Safety Multiplier", comment: "Max Daily Safety Multiplier")
  52. }
  53. ),
  54. units: state.units,
  55. type: .decimal("maxDailySafetyMultiplier"),
  56. label: NSLocalizedString("Max Daily Safety Multiplier", comment: "Max Daily Safety Multiplier"),
  57. miniHint: """
  58. Temporary basal rates cannot be set higher than this percentage of your LARGEST profile basal rate
  59. Default setting: 300%
  60. """,
  61. verboseHint: VStack {
  62. Text("Default: 300%").bold()
  63. Text("""
  64. This limits the automatic adjustment of the temporary basal rate to this value times the highest scheduled basal rate in your basal profile.
  65. """)
  66. Text("If Autotune is enabled, Trio uses Autotune basals instead of scheduled basals.").italic()
  67. Text("""
  68. Increasing this setting is not advised.
  69. """).bold().italic()
  70. }
  71. )
  72. SettingInputSection(
  73. decimalValue: $state.currentBasalSafetyMultiplier,
  74. booleanValue: $booleanPlaceholder,
  75. shouldDisplayHint: $shouldDisplayHint,
  76. selectedVerboseHint: Binding(
  77. get: { selectedVerboseHint },
  78. set: {
  79. selectedVerboseHint = $0.map { AnyView($0) }
  80. hintLabel = NSLocalizedString(
  81. "Current Basal Safety Multiplier",
  82. comment: "Current Basal Safety Multiplier"
  83. )
  84. }
  85. ),
  86. units: state.units,
  87. type: .decimal("currentBasalSafetyMultiplier"),
  88. label: NSLocalizedString("Current Basal Safety Multiplier", comment: "Current Basal Safety Multiplier"),
  89. miniHint: """
  90. Temporary basal rates cannot be set higher than this percentage of the profile basal rate at the time of the loop cycle
  91. Default: 400%
  92. """,
  93. verboseHint: VStack {
  94. Text("Default: 400%").bold()
  95. Text("""
  96. This limits the automatic adjustment of the temporary basal rate to this percentage of the current hourly basal rate at the time of the loop cycle.
  97. """)
  98. Text("If Autotune is enabled, Trio uses Autotune basals instead of scheduled basals.").italic()
  99. Text("""
  100. Increasing this setting is not advised.
  101. """).bold().italic()
  102. }
  103. )
  104. SettingInputSection(
  105. decimalValue: $state.insulinActionCurve,
  106. booleanValue: $booleanPlaceholder,
  107. shouldDisplayHint: $shouldDisplayHint,
  108. selectedVerboseHint: Binding(
  109. get: { selectedVerboseHint },
  110. set: {
  111. selectedVerboseHint = $0.map { AnyView($0) }
  112. hintLabel = "Duration of Insulin Action"
  113. }
  114. ),
  115. units: state.units,
  116. type: .decimal("dia"),
  117. label: "Duration of Insulin Action",
  118. miniHint: """
  119. Number of hours insulin is active in your body
  120. Default: 6 hours
  121. """,
  122. verboseHint: VStack {
  123. Text("Default: 6 hours").bold()
  124. Text("""
  125. Number of hours insulin will contribute to IOB after dosing.
  126. """)
  127. Text("It is better to use Custom Peak Timing rather than adjust your Duration of Insulin Action (DIA)")
  128. .italic()
  129. }
  130. )
  131. SettingInputSection(
  132. decimalValue: $state.insulinPeakTime,
  133. booleanValue: $state.useCustomPeakTime,
  134. shouldDisplayHint: $shouldDisplayHint,
  135. selectedVerboseHint: Binding(
  136. get: { selectedVerboseHint },
  137. set: {
  138. selectedVerboseHint = $0.map { AnyView($0) }
  139. hintLabel = NSLocalizedString("Use Custom Peak Time", comment: "Use Custom Peak Time")
  140. }
  141. ),
  142. units: state.units,
  143. type: .conditionalDecimal("insulinPeakTime"),
  144. label: NSLocalizedString("Use Custom Peak Time", comment: "Use Custom Peak Time"),
  145. conditionalLabel: NSLocalizedString("Insulin Peak Time", comment: "Insulin Peak Time"),
  146. miniHint: """
  147. Time that insulin effect is at it’s highest. Set in minutes since injection.
  148. Default: (Set by Insulin Type)
  149. """,
  150. verboseHint: VStack {
  151. Text("Default: Set by Insulin Type").bold()
  152. Text("""
  153. Time of maximum glucose lowering effect of insulin. Set in minutes since insulin administration.
  154. System-Determined Defaults:
  155. Ultra-Rapid: 55 minutes (permitted range 35-100 minutes)
  156. Rapid-Acting: 75 minutes (permitted range 50-120 minutes)
  157. """)
  158. }
  159. )
  160. SettingInputSection(
  161. decimalValue: $decimalPlaceholder,
  162. booleanValue: $state.skipNeutralTemps,
  163. shouldDisplayHint: $shouldDisplayHint,
  164. selectedVerboseHint: Binding(
  165. get: { selectedVerboseHint },
  166. set: {
  167. selectedVerboseHint = $0.map { AnyView($0) }
  168. hintLabel = NSLocalizedString("Skip Neutral Temps", comment: "Skip Neutral Temps")
  169. }
  170. ),
  171. units: state.units,
  172. type: .boolean,
  173. label: NSLocalizedString("Skip Neutral Temps", comment: "Skip Neutral Temps"),
  174. miniHint: """
  175. When on, Trio will not send a temp basal command to the pump if the determined basal rate is the same as the scheduled basal
  176. Default: OFF
  177. """,
  178. verboseHint: VStack {
  179. Text("Default: OFF").bold()
  180. Text("""
  181. When enabled, Trio will skip neutral temp basals (those that are the same as your default basal), if no adjustments are needed.
  182. When off, Trio will set temps whenever it can, so it will be easier to see if the system is working.
  183. """)
  184. }
  185. )
  186. SettingInputSection(
  187. decimalValue: $decimalPlaceholder,
  188. booleanValue: $state.unsuspendIfNoTemp,
  189. shouldDisplayHint: $shouldDisplayHint,
  190. selectedVerboseHint: Binding(
  191. get: { selectedVerboseHint },
  192. set: {
  193. selectedVerboseHint = $0.map { AnyView($0) }
  194. hintLabel = NSLocalizedString("Unsuspend If No Temp", comment: "Unsuspend If No Temp")
  195. }
  196. ),
  197. units: state.units,
  198. type: .boolean,
  199. label: NSLocalizedString("Unsuspend If No Temp", comment: "Unsuspend If No Temp"),
  200. miniHint: """
  201. Automatically resume your insulin pump if you forget to unsuspend it after a zero temp basal expires
  202. Default: OFF
  203. """,
  204. verboseHint: VStack {
  205. Text("Default: OFF").bold()
  206. Text("""
  207. Many people occasionally forget to resume / unsuspend their pump after reconnecting it. If you’re one of them, and you are willing to reliably set a zero temp basal whenever suspending and disconnecting your pump, this feature has your back. If enabled, it will automatically resume / unsuspend the pump if you forget to do so before your zero temp expires. As long as the zero temp is still running, it will leave the pump suspended.
  208. """)
  209. Text("Applies only to pumps with manual suspend options").italic()
  210. }
  211. )
  212. SettingInputSection(
  213. decimalValue: $decimalPlaceholder,
  214. booleanValue: $state.suspendZerosIOB,
  215. shouldDisplayHint: $shouldDisplayHint,
  216. selectedVerboseHint: Binding(
  217. get: { selectedVerboseHint },
  218. set: {
  219. selectedVerboseHint = $0.map { AnyView($0) }
  220. hintLabel = NSLocalizedString("Suspend Zeros IOB", comment: "Suspend Zeros IOB")
  221. }
  222. ),
  223. units: state.units,
  224. type: .boolean,
  225. label: NSLocalizedString("Suspend Zeros IOB", comment: "Suspend Zeros IOB"),
  226. miniHint: """
  227. Replaces any enacted temp basals prior to a pump suspend with a zero temp basal
  228. Default: OFF
  229. """,
  230. verboseHint: VStack {
  231. Text("Default: OFF").bold()
  232. Text("""
  233. Any existing temp basals during times the pump was suspended will be deleted and zero temp basals to negate the profile basal rates during times pump is suspended will be added.
  234. """)
  235. Text("Applies to only to pumps with manual suspend options").italic()
  236. }
  237. )
  238. SettingInputSection(
  239. decimalValue: $state.autotuneISFAdjustmentFraction,
  240. booleanValue: $booleanPlaceholder,
  241. shouldDisplayHint: $shouldDisplayHint,
  242. selectedVerboseHint: Binding(
  243. get: { selectedVerboseHint },
  244. set: {
  245. selectedVerboseHint = $0.map { AnyView($0) }
  246. hintLabel = NSLocalizedString(
  247. "Autotune ISF Adjustment Percent",
  248. comment: "Autotune ISF Adjustment Percent"
  249. )
  250. }
  251. ),
  252. units: state.units,
  253. type: .decimal("autotuneISFAdjustmentFraction"),
  254. label: NSLocalizedString("Autotune ISF Adjustment Percent", comment: "Autotune ISF Adjustment Percent"),
  255. miniHint: """
  256. Using Autotune is not advised
  257. Default: 50%
  258. """,
  259. verboseHint: Text(
  260. NSLocalizedString(
  261. "The default of 50% for this value keeps autotune ISF closer to pump ISF via a weighted average of fullNewISF and pumpISF. 100% allows full adjustment, 0% is no adjustment from pump ISF.",
  262. comment: "Autotune ISF Adjustment Percent"
  263. )
  264. )
  265. )
  266. SettingInputSection(
  267. decimalValue: $state.min5mCarbimpact,
  268. booleanValue: $booleanPlaceholder,
  269. shouldDisplayHint: $shouldDisplayHint,
  270. selectedVerboseHint: Binding(
  271. get: { selectedVerboseHint },
  272. set: {
  273. selectedVerboseHint = $0.map { AnyView($0) }
  274. hintLabel = NSLocalizedString("Min 5m Carb Impact", comment: "Min 5m Carb Impact")
  275. }
  276. ),
  277. units: state.units,
  278. type: .decimal("min5mCarbimpact"),
  279. label: NSLocalizedString("Min 5m Carb Impact", comment: "Min 5m Carb Impact"),
  280. miniHint: """
  281. Set the default rate of carb absorption when no clear impact on blood glucose is visible
  282. Default: 8 mg/dL/5min
  283. """,
  284. verboseHint: VStack {
  285. Text("Default: 8 mg/dL/5min").bold()
  286. Text("""
  287. The Min 5m Carbimpact setting determines the default expected glucose rise (in mg/dL) over a 5-minute period from carbs when the system cannot detect clear absorption from your blood glucose levels.
  288. The default value of 8 mg/dL per 5 minutes corresponds to an absorption rate of 24g of carbs per hour.
  289. This setting helps the system estimate how much glucose your body is absorbing, even when it’s not immediately visible in your glucose data, ensuring more accurate insulin dosing during carb absorption.
  290. """)
  291. }
  292. )
  293. SettingInputSection(
  294. decimalValue: $state.remainingCarbsFraction,
  295. booleanValue: $booleanPlaceholder,
  296. shouldDisplayHint: $shouldDisplayHint,
  297. selectedVerboseHint: Binding(
  298. get: { selectedVerboseHint },
  299. set: {
  300. selectedVerboseHint = $0.map { AnyView($0) }
  301. hintLabel = NSLocalizedString("Remaining Carbs Percentage", comment: "Remaining Carbs Percentage")
  302. }
  303. ),
  304. units: state.units,
  305. type: .decimal("remainingCarbsFraction"),
  306. label: NSLocalizedString("Remaining Carbs Percentage", comment: "Remaining Carbs Percentage"),
  307. miniHint: """
  308. Set the percentage of unabsorbed carbs that will be assumed to absorb over 4 hours if no absorption is detected
  309. Default: 100%
  310. """,
  311. verboseHint: VStack {
  312. Text("Default: 100%").bold()
  313. Text("""
  314. The Remaining Carbs Percentage setting helps estimate how many carbs from a meal will still be absorbed if your glucose readings don’t show clear carb absorption. This percentage, applied to the entered carbs, will be spread over 4 hours. It’s useful when the system can’t detect carb absorption from blood glucose data, providing a fallback estimate to prevent under-dosing.
  315. """)
  316. }
  317. )
  318. SettingInputSection(
  319. decimalValue: $state.remainingCarbsCap,
  320. booleanValue: $booleanPlaceholder,
  321. shouldDisplayHint: $shouldDisplayHint,
  322. selectedVerboseHint: Binding(
  323. get: { selectedVerboseHint },
  324. set: {
  325. selectedVerboseHint = $0.map { AnyView($0) }
  326. hintLabel = NSLocalizedString("Remaining Carbs Cap", comment: "Remaining Carbs Cap")
  327. }
  328. ),
  329. units: state.units,
  330. type: .decimal("remainingCarbsCap"),
  331. label: NSLocalizedString("Remaining Carbs Cap", comment: "Remaining Carbs Cap"),
  332. miniHint: """
  333. Set the maximum amount of carbs assumed to absorb over 4 hours if no absorption is detected
  334. Default: 90g
  335. """,
  336. verboseHint: VStack {
  337. Text("Default: 90g").bold()
  338. Text("""
  339. The Remaining Carbs Cap defines the upper limit for how many carbs the system will assume are absorbing over 4 hours, even when there’s no clear sign of absorption from your glucose readings.
  340. This cap prevents the system from overestimating how much insulin is needed when carb absorption isn’t visible, offering a safeguard for accurate dosing.
  341. """)
  342. }
  343. )
  344. SettingInputSection(
  345. decimalValue: $state.noisyCGMTargetMultiplier,
  346. booleanValue: $booleanPlaceholder,
  347. shouldDisplayHint: $shouldDisplayHint,
  348. selectedVerboseHint: Binding(
  349. get: { selectedVerboseHint },
  350. set: {
  351. selectedVerboseHint = $0.map { AnyView($0) }
  352. hintLabel = NSLocalizedString("Noisy CGM Target Multiplier", comment: "Noisy CGM Target Multiplier")
  353. }
  354. ),
  355. units: state.units,
  356. type: .decimal("noisyCGMTargetMultiplier"),
  357. label: NSLocalizedString("Noisy CGM Target Increase", comment: "Noisy CGM Target Increase"),
  358. miniHint: """
  359. Increase glucose target by this percent when relying on noisy CGM data
  360. Default: 130%
  361. """,
  362. verboseHint: VStack {
  363. Text("Default: 130%").bold()
  364. Text("""
  365. The Noisy CGM Target Multiplier increases your glucose target when the system detects noisy or raw CGM data. By default, the target is increased by 130% to account for the less reliable glucose readings.
  366. This helps reduce the risk of incorrect insulin dosing based on inaccurate sensor data, ensuring safer insulin adjustments during periods of poor CGM accuracy.
  367. """)
  368. }
  369. )
  370. }
  371. .sheet(isPresented: $shouldDisplayHint) {
  372. SettingInputHintView(
  373. hintDetent: $hintDetent,
  374. shouldDisplayHint: $shouldDisplayHint,
  375. hintLabel: hintLabel ?? "",
  376. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  377. sheetTitle: "Help"
  378. )
  379. }
  380. .scrollContentBackground(.hidden).background(color)
  381. .onAppear(perform: configureView)
  382. .navigationTitle("Additionals")
  383. .navigationBarTitleDisplayMode(.automatic)
  384. .onDisappear {
  385. state.saveIfChanged()
  386. }
  387. }
  388. }
  389. }