PreferencesEditorStateModel.swift 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. import Foundation
  2. import SwiftUI
  3. extension PreferencesEditor {
  4. final class StateModel: BaseStateModel<Provider>, PreferencesSettable { private(set) var preferences = Preferences()
  5. @Published var unitsIndex = 1
  6. @Published var allowAnnouncements = false
  7. @Published var skipBolusScreenAfterCarbs = false
  8. @Published var sections: [FieldSection] = []
  9. @Published var useAlternativeBolusCalc: Bool = false
  10. @Published var units: GlucoseUnits = .mmolL
  11. override func subscribe() {
  12. preferences = provider.preferences
  13. useAlternativeBolusCalc = settingsManager.settings.useCalc
  14. units = settingsManager.settings.units
  15. subscribeSetting(\.allowAnnouncements, on: $allowAnnouncements) { allowAnnouncements = $0 }
  16. subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) {
  17. unitsIndex = $0 == .mgdL ? 0 : 1
  18. } didSet: { [weak self] _ in
  19. self?.provider.migrateUnits()
  20. }
  21. let mainFields = [
  22. Field(
  23. displayName: NSLocalizedString("Max IOB", comment: "Max IOB"),
  24. type: .decimal(keypath: \.maxIOB),
  25. infoText: NSLocalizedString(
  26. "Max IOB is the maximum amount of insulin on board from all sources – both basal (or SMB correction) and bolus insulin – that your loop is allowed to accumulate to treat higher-than-target BG. Unlike the other two OpenAPS safety settings (max_daily_safety_multiplier and current_basal_safety_multiplier), max_iob is set as a fixed number of units of insulin. As of now manual boluses are NOT limited by this setting. \n\n To test your basal rates during nighttime, you can modify the Max IOB setting to zero while in Closed Loop. This will enable low glucose suspend mode while testing your basal rates settings\n\n(Tip from https://www.loopandlearn.org/freeaps-x/#open-loop).",
  27. comment: "Max IOB"
  28. ),
  29. settable: self
  30. ),
  31. Field(
  32. displayName: NSLocalizedString("Max COB", comment: "Max COB"),
  33. type: .decimal(keypath: \.maxCOB),
  34. infoText: NSLocalizedString(
  35. "The default of maxCOB is 120. (If someone enters more carbs in one or multiple entries, iAPS will cap COB to maxCOB and keep it at maxCOB until the carbs entered above maxCOB have shown to be absorbed. Essentially, this just limits UAM as a safety cap against weird COB calculations due to fluky data.)",
  36. comment: "Max COB"
  37. ),
  38. settable: self
  39. ),
  40. Field(
  41. displayName: NSLocalizedString("Max Daily Safety Multiplier", comment: "Max Daily Safety Multiplier"),
  42. type: .decimal(keypath: \.maxDailySafetyMultiplier),
  43. infoText: NSLocalizedString(
  44. "This is an important OpenAPS safety limit. The default setting (which is unlikely to need adjusting) is 3. This means that OpenAPS will never be allowed to set a temporary basal rate that is more than 3x the highest hourly basal rate programmed in a user’s pump, or, if enabled, determined by autotune.",
  45. comment: "Max Daily Safety Multiplier"
  46. ),
  47. settable: self
  48. ),
  49. Field(
  50. displayName: NSLocalizedString("Current Basal Safety Multiplier", comment: "Current Basal Safety Multiplier"),
  51. type: .decimal(keypath: \.currentBasalSafetyMultiplier),
  52. infoText: NSLocalizedString(
  53. "This is another important OpenAPS safety limit. The default setting (which is also unlikely to need adjusting) is 4. This means that OpenAPS will never be allowed to set a temporary basal rate that is more than 4x the current hourly basal rate programmed in a user’s pump, or, if enabled, determined by autotune.",
  54. comment: "Current Basal Safety Multiplier"
  55. ),
  56. settable: self
  57. ),
  58. Field(
  59. displayName: NSLocalizedString("Autosens Max", comment: "Autosens Max"),
  60. type: .decimal(keypath: \.autosensMax),
  61. infoText: NSLocalizedString(
  62. "This is a multiplier cap for autosens (and autotune) to set a 20% max limit on how high the autosens ratio can be, which in turn determines how high autosens can adjust basals, how low it can adjust ISF, and how low it can set the BG target.",
  63. comment: "Autosens Max"
  64. ),
  65. settable: self
  66. ),
  67. Field(
  68. displayName: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  69. type: .decimal(keypath: \.autosensMin),
  70. infoText: NSLocalizedString(
  71. "The other side of the autosens safety limits, putting a cap on how low autosens can adjust basals, and how high it can adjust ISF and BG targets.",
  72. comment: "Autosens Min"
  73. ),
  74. settable: self
  75. )
  76. ]
  77. let dynamicISF = [
  78. Field(
  79. displayName: NSLocalizedString("Enable Dynamic ISF", comment: "Enable Dynamic ISF"),
  80. type: .boolean(keypath: \.useNewFormula),
  81. infoText: NSLocalizedString(
  82. "Calculate a new ISF with every loop cycle. New ISF will be based on current BG, TDD of insulin (past 24 hours or a weighted average) and an Adjustment Factor (default is 1).\n\nDynamic ISF and CR ratios will be limited by your autosens.min/max limits.\n\nDynamic ratio replaces the autosens.ratio:\n\nNew ISF = Static ISF / Dynamic ratio,\n\nDynamic ratio = profile.sens * adjustmentFactor * tdd * Math.log(BG/insulinFactor+1) / 1800,\n\ninsulinFactor = 120 - InsulinPeakTimeInMinutes",
  83. comment: "Enable Dynamic ISF"
  84. ),
  85. settable: self
  86. ),
  87. Field(
  88. displayName: NSLocalizedString("Enable Dynamic CR", comment: "Use Dynamic CR together with Dynamic ISF"),
  89. type: .boolean(keypath: \.enableDynamicCR),
  90. infoText: NSLocalizedString(
  91. "Use Dynamic CR. The dynamic ratio will be used for CR as follows:\n\n When ratio > 1: dynCR = (newRatio - 1) / 2 + 1.\nWhen ratio < 1: dynCR = CR/dynCR.\n\nDon't use toghether with a high Insulin Fraction (> 2)",
  92. comment: "Use Dynamic CR together with Dynamic ISF"
  93. ),
  94. settable: self
  95. ),
  96. Field(
  97. displayName: NSLocalizedString("Adjustment Factor", comment: "Adjust Dynamic ISF constant"),
  98. type: .decimal(keypath: \.adjustmentFactor),
  99. infoText: NSLocalizedString(
  100. "Adjust Dynamic ratios by a constant. Default is 0.5. The higher the value, the larger the correction of your ISF will be for a high or a low BG. Maximum correction is determined by the Autosens min/max settings. For Sigmoid function an adjustment factor of 0.4 - 0.5 is recommended to begin with. For the logaritmic formula threre is less consensus, but starting with 0.5 - 0.8 is more appropiate for most users",
  101. comment: "Adjust Dynamic ISF constant"
  102. ),
  103. settable: self
  104. ),
  105. Field(
  106. displayName: NSLocalizedString("Use Sigmoid Function", comment: "Use Sigmoid Function"),
  107. type: .boolean(keypath: \.sigmoid),
  108. infoText: NSLocalizedString(
  109. "Use a sigmoid function for ISF (and for CR, when enabled), instead of the default Logarithmic formula. Requires the Dynamic ISF setting to be enabled in settings\n\nThe Adjustment setting adjusts the slope of the curve (Y: Dynamic ratio, X: Blood Glucose). A lower value ==> less steep == less aggressive.\n\nThe autosens.min/max settings determines both the max/min limits for the dynamic ratio AND how much the dynamic ratio is adjusted. If AF is the slope of the curve, the autosens.min/max is the height of the graph, the Y-interval, where Y: dynamic ratio. The curve will always have a sigmoid shape, no matter which autosens.min/max settings are used, meaning these settings have big consequences for the outcome of the computed dynamic ISF. Please be careful setting a too high autosens.max value. With a proper profile ISF setting, you will probably never need it to be higher than 1.5\n\nAn Autosens.max limit > 1.5 is not advisable when using the sigmoid function.",
  110. comment: "Use Sigmoid Function"
  111. ),
  112. settable: self
  113. ),
  114. Field(
  115. displayName: NSLocalizedString(
  116. "Weighted Average of TDD. Weight of past 24 hours:",
  117. comment: "Weight of past 24 hours of insulin"
  118. ),
  119. type: .decimal(keypath: \.weightPercentage),
  120. infoText: NSLocalizedString(
  121. "Has to be > 0 and <= 1.\nDefault is 0.65 (65 %) * TDD. The rest will be from average of total data (up to 14 days) of all TDD calculations (35 %). To only use past 24 hours, set this to 1.\n\nTo avoid sudden fluctuations, for instance after a big meal, an average of the past 2 hours of TDD calculations is used instead of just the current TDD (past 24 hours at this moment).",
  122. comment: "Weight of past 24 hours of insulin"
  123. ),
  124. settable: self
  125. ),
  126. Field(
  127. displayName: NSLocalizedString("Adjust basal", comment: "Enable adjustment of basal profile"),
  128. type: .boolean(keypath: \.tddAdjBasal),
  129. infoText: NSLocalizedString(
  130. "Enable adjustment of basal based on the ratio of current TDD / 7 day average TDD",
  131. comment: "Enable adjustment of basal profile"
  132. ),
  133. settable: self
  134. ),
  135. Field(
  136. displayName: NSLocalizedString("Threshold Setting (mg/dl)", comment: "Threshold Setting"),
  137. type: .decimal(keypath: \.threshold_setting),
  138. infoText: NSLocalizedString(
  139. "The default threshold in FAX depends on your current minimum BG target, as follows:\n\nIf your minimum BG target = 90 mg/dl -> threshold = 65 mg/dl,\n\nif minimum BG target = 100 mg/dl -> threshold = 70 mg/dl,\n\nminimum BG target = 110 mg/dl -> threshold = 75 mg/dl,\n\nand if minimum BG target = 130 mg/dl -> threshold = 85 mg/dl.\n\nThis setting allows you to change the default to a higher threshold for looping with dynISF. Valid values are 65 mg/dl<= Threshold Setting <= 120 mg/dl.",
  140. comment: "Threshold Setting"
  141. ),
  142. settable: self
  143. )
  144. ]
  145. let smbFields = [
  146. Field(
  147. displayName: NSLocalizedString("Enable SMB Always", comment: "Enable SMB Always"),
  148. type: .boolean(keypath: \.enableSMBAlways),
  149. infoText: NSLocalizedString(
  150. "Defaults to false. When true, always enable supermicrobolus (unless disabled by high temptarget).",
  151. comment: "Enable SMB Always"
  152. ),
  153. settable: self
  154. ),
  155. Field(
  156. displayName: NSLocalizedString("Max Delta-BG Threshold SMB", comment: "Max Delta-BG Threshold"),
  157. type: .decimal(keypath: \.maxDeltaBGthreshold),
  158. infoText: NSLocalizedString(
  159. "Defaults to 0.2 (20%). Maximum positive percentual change of BG level to use SMB, above that will disable SMB. Hardcoded cap of 40%. For UAM fully-closed-loop 30% is advisable. Observe in log and popup (maxDelta 27 > 20% of BG 100 - disabling SMB!).",
  160. comment: "Max Delta-BG Threshold"
  161. ),
  162. settable: self
  163. ),
  164. Field(
  165. displayName: NSLocalizedString("Enable SMB With COB", comment: "Enable SMB With COB"),
  166. type: .boolean(keypath: \.enableSMBWithCOB),
  167. infoText: NSLocalizedString(
  168. "This enables supermicrobolus (SMB) while carbs on board (COB) are positive.",
  169. comment: "Enable SMB With COB"
  170. ),
  171. settable: self
  172. ),
  173. Field(
  174. displayName: NSLocalizedString("Enable SMB With Temptarget", comment: "Enable SMB With Temptarget"),
  175. type: .boolean(keypath: \.enableSMBWithTemptarget),
  176. infoText: NSLocalizedString(
  177. "This enables supermicrobolus (SMB) with eating soon / low temp targets. With this feature enabled, any temporary target below 100mg/dL, such as a temp target of 99 (or 80, the typical eating soon target) will enable SMB.",
  178. comment: "Enable SMB With Temptarget"
  179. ),
  180. settable: self
  181. ),
  182. Field(
  183. displayName: NSLocalizedString("Enable SMB After Carbs", comment: "Enable SMB After Carbs"),
  184. type: .boolean(keypath: \.enableSMBAfterCarbs),
  185. infoText: NSLocalizedString(
  186. "Defaults to false. When true, enables supermicrobolus (SMB) for 6h after carbs, even with 0 carbs on board (COB).",
  187. comment: "Enable SMB After Carbs"
  188. ),
  189. settable: self
  190. ),
  191. Field(
  192. displayName: NSLocalizedString(
  193. "Allow SMB With High Temptarget",
  194. comment: "Allow SMB With High Temptarget"
  195. ),
  196. type: .boolean(keypath: \.allowSMBWithHighTemptarget),
  197. infoText: NSLocalizedString(
  198. "Defaults to false. When true, allows supermicrobolus (if otherwise enabled) even with high temp targets (> 100 mg/dl).",
  199. comment: "Allow SMB With High Temptarget"
  200. ),
  201. settable: self
  202. ),
  203. Field(
  204. displayName: NSLocalizedString("Enable SMB With High BG", comment: "Enable SMB With High BG"),
  205. type: .boolean(keypath: \.enableSMB_high_bg),
  206. infoText: NSLocalizedString(
  207. "Enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile)",
  208. comment: "Enable SMB With High BG"
  209. ),
  210. settable: self
  211. ),
  212. Field(
  213. displayName: NSLocalizedString(
  214. "... When Blood Glucose Is Over (mg/dl):",
  215. comment: "... When Blood Glucose Is Over (mg/dl):"
  216. ),
  217. type: .decimal(keypath: \.enableSMB_high_bg_target),
  218. infoText: NSLocalizedString(
  219. "Set the value enableSMB_high_bg will compare against to enable SMB. If BG > than this value, SMBs should enable.",
  220. comment: "... When Blood Glucose Is Over (mg/dl):"
  221. ),
  222. settable: self
  223. ),
  224. Field(
  225. displayName: NSLocalizedString("Enable UAM", comment: "Enable UAM"),
  226. type: .boolean(keypath: \.enableUAM),
  227. infoText: NSLocalizedString(
  228. "With this option enabled, the SMB algorithm can recognize unannounced meals. This is helpful, if you forget to tell iAPS about your carbs or estimate your carbs wrong and the amount of entered carbs is wrong or if a meal with lots of fat and protein has a longer duration than expected. Without any carb entry, UAM can recognize fast glucose increasments caused by carbs, adrenaline, etc, and tries to adjust it with SMBs. This also works the opposite way: if there is a fast glucose decreasement, it can stop SMBs earlier.",
  229. comment: "Enable UAM"
  230. ),
  231. settable: self
  232. ),
  233. Field(
  234. displayName: NSLocalizedString("Max SMB Basal Minutes", comment: "Max SMB Basal Minutes"),
  235. type: .decimal(keypath: \.maxSMBBasalMinutes),
  236. infoText: NSLocalizedString(
  237. "Defaults to start at 30. This is the maximum minutes of basal that can be delivered as a single SMB with uncovered COB. This gives the ability to make SMB more aggressive if you choose. It is recommended that the value is set to start at 30, in line with the default, and if you choose to increase this value, do so in no more than 15 minute increments, keeping a close eye on the effects of the changes. It is not recommended to set this value higher than 90 mins, as this may affect the ability for the algorithm to safely zero temp. It is also recommended that pushover is used when setting the value to be greater than default, so that alerts are generated for any predicted lows or highs.",
  238. comment: "Max SMB Basal Minutes"
  239. ),
  240. settable: self
  241. ),
  242. Field(
  243. displayName: NSLocalizedString("Max UAM SMB Basal Minutes", comment: "Max UAM SMB Basal Minutes"),
  244. type: .decimal(keypath: \.maxUAMSMBBasalMinutes),
  245. infoText: NSLocalizedString(
  246. "Defaults to start at 30. This is the maximum minutes of basal that can be delivered by UAM as a single SMB when IOB exceeds COB. This gives the ability to make UAM more or less aggressive if you choose. It is recommended that the value is set to start at 30, in line with the default, and if you choose to increase this value, do so in no more than 15 minute increments, keeping a close eye on the effects of the changes. Reducing the value will cause UAM to dose less insulin for each SMB. It is not recommended to set this value higher than 60 mins, as this may affect the ability for the algorithm to safely zero temp. It is also recommended that pushover is used when setting the value to be greater than default, so that alerts are generated for any predicted lows or highs.",
  247. comment: "Max UAM SMB Basal Minutes"
  248. ),
  249. settable: self
  250. ),
  251. Field(
  252. displayName: NSLocalizedString("SMB DeliveryRatio", comment: "SMB DeliveryRatio"),
  253. type: .decimal(keypath: \.smbDeliveryRatio),
  254. infoText: NSLocalizedString(
  255. "Default value: 0.5 This is another key OpenAPS safety cap, and specifies what share of the total insulin required can be delivered as SMB. Increase this experimental value slowly and with caution.",
  256. comment: "SMB DeliveryRatio"
  257. ),
  258. settable: self
  259. ),
  260. Field(
  261. displayName: NSLocalizedString("SMB Interval", comment: "SMB Interval"),
  262. type: .decimal(keypath: \.smbInterval),
  263. infoText: NSLocalizedString(
  264. "Minimum duration in minutes for new SMB since last SMB or manual bolus",
  265. comment: "SMB Interval"
  266. ),
  267. settable: self
  268. ),
  269. Field(
  270. displayName: NSLocalizedString("Bolus Increment", comment: "Bolus Increment"),
  271. type: .decimal(keypath: \.bolusIncrement),
  272. infoText: NSLocalizedString(
  273. "Smallest enacted SMB amount. Minimum amount for Omnipod pumps is 0.05 U, whereas for Medtronic pumps it differs for various models, from 0.025 U to 0.10 U. Please check the minimum bolus amount which can be delivered by your pump. The default value is 0.1.",
  274. comment: "Bolus Increment"
  275. ),
  276. settable: self
  277. )
  278. ]
  279. // MARK: - Targets fields
  280. let targetSettings = [
  281. Field(
  282. displayName: NSLocalizedString(
  283. "High Temptarget Raises Sensitivity",
  284. comment: "High Temptarget Raises Sensitivity"
  285. ),
  286. type: .boolean(keypath: \.highTemptargetRaisesSensitivity),
  287. infoText: NSLocalizedString(
  288. "Defaults to false. When set to true, raises sensitivity (lower sensitivity ratio) for temp targets set to >= 111. Synonym for exercise_mode. The higher your temp target above 110 will result in more sensitive (lower) ratios, e.g., temp target of 120 results in sensitivity ratio of 0.75, while 140 results in 0.6 (with default halfBasalTarget of 160).",
  289. comment: "High Temptarget Raises Sensitivity"
  290. ),
  291. settable: self
  292. ),
  293. Field(
  294. displayName: NSLocalizedString(
  295. "Low Temptarget Lowers Sensitivity",
  296. comment: "Low Temptarget Lowers Sensitivity"
  297. ),
  298. type: .boolean(keypath: \.lowTemptargetLowersSensitivity),
  299. infoText: NSLocalizedString(
  300. "Defaults to false. When set to true, can lower sensitivity (higher sensitivity ratio) for temptargets <= 99. The lower your temp target below 100 will result in less sensitive (higher) ratios, e.g., temp target of 95 results in sensitivity ratio of 1.09, while 85 results in 1.33 (with default halfBasalTarget of 160).",
  301. comment: "Low Temptarget Lowers Sensitivity"
  302. ),
  303. settable: self
  304. ),
  305. Field(
  306. displayName: NSLocalizedString("Sensitivity Raises Target", comment: "Sensitivity Raises Target"),
  307. type: .boolean(keypath: \.sensitivityRaisesTarget),
  308. infoText: NSLocalizedString(
  309. "When true, raises BG target when autosens detects sensitivity",
  310. comment: "Sensitivity Raises Target"
  311. ),
  312. settable: self
  313. ),
  314. Field(
  315. displayName: NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target"),
  316. type: .boolean(keypath: \.resistanceLowersTarget),
  317. infoText: NSLocalizedString(
  318. "Defaults to false. When true, will lower BG target when autosens detects resistance",
  319. comment: "Resistance Lowers Target"
  320. ),
  321. settable: self
  322. ),
  323. Field(
  324. displayName: NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  325. type: .decimal(keypath: \.halfBasalExerciseTarget),
  326. infoText: NSLocalizedString(
  327. "Set to a number, e.g. 160, which means when temp target is 160 mg/dL, run 50% basal at this level (120 = 75%; 140 = 60%). This can be adjusted, to give you more control over your exercise modes.",
  328. comment: "Half Basal Exercise Target"
  329. ),
  330. settable: self
  331. )
  332. ]
  333. // MARK: - Other fields
  334. let otherSettings = [
  335. Field(
  336. displayName: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  337. type: .boolean(keypath: \.rewindResetsAutosens),
  338. infoText: NSLocalizedString(
  339. "This feature, enabled by default, resets the autosens ratio to neutral when you rewind your pump, on the assumption that this corresponds to a probable site change. Autosens will begin learning sensitivity anew from the time of the rewind, which may take up to 6 hours. If you usually rewind your pump independently of site changes, you may want to consider disabling this feature.",
  340. comment: "Rewind Resets Autosens"
  341. ),
  342. settable: self
  343. ),
  344. Field(
  345. displayName: NSLocalizedString("Use Custom Peak Time", comment: "Use Custom Peak Time"),
  346. type: .boolean(keypath: \.useCustomPeakTime),
  347. infoText: NSLocalizedString(
  348. "Defaults to false. Setting to true allows changing insulinPeakTime", comment: "Use Custom Peak Time"
  349. ),
  350. settable: self
  351. ),
  352. Field(
  353. displayName: NSLocalizedString("Insulin Peak Time", comment: "Insulin Peak Time"),
  354. type: .decimal(keypath: \.insulinPeakTime),
  355. infoText: NSLocalizedString(
  356. "Time of maximum blood glucose lowering effect of insulin, in minutes. Beware: Oref assumes for ultra-rapid (Lyumjev) & rapid-acting (Fiasp) curves minimal (35 & 50 min) and maximal (100 & 120 min) applicable insulinPeakTimes. Using a custom insulinPeakTime outside these bounds will result in issues with iAPS, longer loop calculations and possible red loops.",
  357. comment: "Insulin Peak Time"
  358. ),
  359. settable: self
  360. ),
  361. Field(
  362. displayName: NSLocalizedString("Skip Neutral Temps", comment: "Skip Neutral Temps"),
  363. type: .boolean(keypath: \.skipNeutralTemps),
  364. infoText: NSLocalizedString(
  365. "Defaults to false, so that iAPS will set temps whenever it can, so it will be easier to see if the system is working, even when you are offline. This means iAPS will set a “neutral” temp (same as your default basal) if no adjustments are needed. This is an old setting for OpenAPS to have the options to minimise sounds and notifications from the 'rig', that may wake you up during the night.",
  366. comment: "Skip Neutral Temps"
  367. ),
  368. settable: self
  369. ),
  370. Field(
  371. displayName: NSLocalizedString("Unsuspend If No Temp", comment: "Unsuspend If No Temp"),
  372. type: .boolean(keypath: \.unsuspendIfNoTemp),
  373. infoText: NSLocalizedString(
  374. "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.",
  375. comment: "Unsuspend If No Temp"
  376. ),
  377. settable: self
  378. ),
  379. Field(
  380. displayName: NSLocalizedString("Suspend Zeros IOB", comment: "Suspend Zeros IOB"),
  381. type: .boolean(keypath: \.suspendZerosIOB),
  382. infoText: NSLocalizedString(
  383. "Default is false. Any existing temp basals during times the pump was suspended will be deleted and 0 temp basals to negate the profile basal rates during times pump is suspended will be added.",
  384. comment: "Suspend Zeros IOB"
  385. ),
  386. settable: self
  387. ),
  388. Field(
  389. displayName: NSLocalizedString("Min 5m Carbimpact", comment: "Min 5m Carbimpact"),
  390. type: .decimal(keypath: \.min5mCarbimpact),
  391. infoText: NSLocalizedString(
  392. "This is a setting for default carb absorption impact per 5 minutes. The default is an expected 8 mg/dL/5min. This affects how fast COB is decayed in situations when carb absorption is not visible in BG deviations. The default of 8 mg/dL/5min corresponds to a minimum carb absorption rate of 24g/hr at a CSF of 4 mg/dL/g.",
  393. comment: "Min 5m Carbimpact"
  394. ),
  395. settable: self
  396. ),
  397. Field(
  398. displayName: NSLocalizedString(
  399. "Autotune ISF Adjustment Fraction",
  400. comment: "Autotune ISF Adjustment Fraction"
  401. ),
  402. type: .decimal(keypath: \.autotuneISFAdjustmentFraction),
  403. infoText: NSLocalizedString(
  404. "The default of 0.5 for this value keeps autotune ISF closer to pump ISF via a weighted average of fullNewISF and pumpISF. 1.0 allows full adjustment, 0 is no adjustment from pump ISF.",
  405. comment: "Autotune ISF Adjustment Fraction"
  406. ),
  407. settable: self
  408. ),
  409. Field(
  410. displayName: NSLocalizedString("Remaining Carbs Fraction", comment: "Remaining Carbs Fraction"),
  411. type: .decimal(keypath: \.remainingCarbsFraction),
  412. infoText: NSLocalizedString(
  413. "This is the fraction of carbs we’ll assume will absorb over 4h if we don’t yet see carb absorption.",
  414. comment: "Remaining Carbs Fraction"
  415. ),
  416. settable: self
  417. ),
  418. Field(
  419. displayName: NSLocalizedString("Remaining Carbs Cap", comment: "Remaining Carbs Cap"),
  420. type: .decimal(keypath: \.remainingCarbsCap),
  421. infoText: NSLocalizedString(
  422. "This is the amount of the maximum number of carbs we’ll assume will absorb over 4h if we don’t yet see carb absorption.",
  423. comment: "Remaining Carbs Cap"
  424. ),
  425. settable: self
  426. ),
  427. Field(
  428. displayName: NSLocalizedString("Noisy CGM Target Multiplier", comment: "Noisy CGM Target Multiplier"),
  429. type: .decimal(keypath: \.noisyCGMTargetMultiplier),
  430. infoText: NSLocalizedString(
  431. "Defaults to 1.3. Increase target by this amount when looping off raw/noisy CGM data",
  432. comment: "Noisy CGM Target Multiplier"
  433. ),
  434. settable: self
  435. )
  436. ]
  437. sections = [
  438. FieldSection(
  439. displayName: NSLocalizedString("OpenAPS main settings", comment: "OpenAPS main settings"), fields: mainFields
  440. ),
  441. FieldSection(
  442. displayName: NSLocalizedString("Dynamic settings", comment: "Dynamic settings"),
  443. fields: dynamicISF
  444. ),
  445. FieldSection(
  446. displayName: NSLocalizedString("OpenAPS SMB settings", comment: "OpenAPS SMB settings"),
  447. fields: smbFields
  448. ),
  449. FieldSection(
  450. displayName: NSLocalizedString("OpenAPS targets settings", comment: "OpenAPS targets settings"),
  451. fields: targetSettings
  452. ),
  453. FieldSection(
  454. displayName: NSLocalizedString("OpenAPS other settings", comment: "OpenAPS other settings"),
  455. fields: otherSettings
  456. )
  457. ]
  458. }
  459. func set<T>(_ keypath: WritableKeyPath<Preferences, T>, value: T) {
  460. preferences[keyPath: keypath] = value
  461. save()
  462. }
  463. func get<T>(_ keypath: WritableKeyPath<Preferences, T>) -> T {
  464. preferences[keyPath: keypath]
  465. }
  466. func save() {
  467. provider.savePreferences(preferences)
  468. }
  469. }
  470. }