PreferencesEditorStateModel.swift 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 insulinReqFraction: Decimal = 2.0
  8. @Published var skipBolusScreenAfterCarbs = false
  9. @Published var displayStatistics = false
  10. @Published var sections: [FieldSection] = []
  11. override func subscribe() {
  12. preferences = provider.preferences
  13. subscribeSetting(\.allowAnnouncements, on: $allowAnnouncements) { allowAnnouncements = $0 }
  14. subscribeSetting(\.insulinReqFraction, on: $insulinReqFraction) { insulinReqFraction = $0 }
  15. subscribeSetting(\.displayStatistics, on: $displayStatistics) { displayStatistics = $0 }
  16. subscribeSetting(\.skipBolusScreenAfterCarbs, on: $skipBolusScreenAfterCarbs) { skipBolusScreenAfterCarbs = $0 }
  17. subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) {
  18. unitsIndex = $0 == .mgdL ? 0 : 1
  19. } didSet: { [weak self] _ in
  20. self?.provider.migrateUnits()
  21. }
  22. let statFields = [
  23. Field(
  24. displayName: NSLocalizedString(
  25. "Low Glucose Limit",
  26. comment: "Display As Low Glucose Percantage Under This Value"
  27. ) + " (\(settingsManager.settings.units.rawValue))",
  28. type: .decimal(keypath: \.low),
  29. infoText: NSLocalizedString(
  30. "Blood Glucoses Under This Value Will Added To And Displayed as Low Glucose Percantage",
  31. comment: "Description for Low Glucose Limit"
  32. ),
  33. settable: self
  34. ),
  35. Field(
  36. displayName: NSLocalizedString(
  37. "High Glucose Limit",
  38. comment: "Limit For High Glucose in Statistics View"
  39. ) + " (\(settingsManager.settings.units.rawValue))",
  40. type: .decimal(keypath: \.high),
  41. infoText: NSLocalizedString(
  42. "Blood Glucoses Over This Value Will Added To And Displaved as High Glucose Percantage",
  43. comment: "High Glucose Limit"
  44. ),
  45. settable: self
  46. ),
  47. Field(
  48. displayName: NSLocalizedString(
  49. "Update every number of minutes:",
  50. comment: "How often to update the statistics"
  51. ),
  52. type: .decimal(keypath: \.updateInterval),
  53. infoText: NSLocalizedString(
  54. "Default is 20 minutes. How often to update and save the statistics.json and to upload last array, when enabled, to Nightscout.",
  55. comment: "Description for update interval for statistics"
  56. ),
  57. settable: self
  58. ),
  59. Field(
  60. displayName: NSLocalizedString(
  61. "Display Loop Cycle statistics",
  62. comment: "Display Display Loop Cycle statistics in statPanel"
  63. ),
  64. type: .boolean(keypath: \.displayLoops),
  65. infoText: NSLocalizedString(
  66. "Displays Loop statistics in the statPanel in Home View",
  67. comment: "Description for Display Loop statistics"
  68. ),
  69. settable: self
  70. ),
  71. Field(
  72. displayName: NSLocalizedString(
  73. "Override HbA1c unit",
  74. comment: "Display %"
  75. ),
  76. type: .boolean(keypath: \.overrideHbA1cUnit),
  77. infoText: NSLocalizedString(
  78. "Change default HbA1c unit in statPanlel. The unit in statPanel will be updateded with next statistics.json update",
  79. comment: "Description for Override HbA1c unit"
  80. ),
  81. settable: self
  82. )
  83. ]
  84. let mainFields = [
  85. Field(
  86. displayName: NSLocalizedString("Insulin curve", comment: "Insulin curve"),
  87. type: .insulinCurve(keypath: \.curve),
  88. infoText: "Insulin curve info",
  89. settable: self
  90. ),
  91. Field(
  92. displayName: NSLocalizedString("Max IOB", comment: "Max IOB"),
  93. type: .decimal(keypath: \.maxIOB),
  94. infoText: NSLocalizedString(
  95. "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).",
  96. comment: "Max IOB"
  97. ),
  98. settable: self
  99. ),
  100. Field(
  101. displayName: NSLocalizedString("Max COB", comment: "Max COB"),
  102. type: .decimal(keypath: \.maxCOB),
  103. infoText: NSLocalizedString(
  104. "This defaults maxCOB to 120 because that’s the most a typical body can absorb over 4 hours. (If someone enters more carbs or stacks more; OpenAPS will just truncate dosing based on 120. Essentially, this just limits AMA as a safety cap against weird COB calculations due to fluky data.)",
  105. comment: "Max COB"
  106. ),
  107. settable: self
  108. ),
  109. Field(
  110. displayName: NSLocalizedString("Max Daily Safety Multiplier", comment: "Max Daily Safety Multiplier"),
  111. type: .decimal(keypath: \.maxDailySafetyMultiplier),
  112. infoText: NSLocalizedString(
  113. "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.",
  114. comment: "Max Daily Safety Multiplier"
  115. ),
  116. settable: self
  117. ),
  118. Field(
  119. displayName: NSLocalizedString("Current Basal Safety Multiplier", comment: "Current Basal Safety Multiplier"),
  120. type: .decimal(keypath: \.currentBasalSafetyMultiplier),
  121. infoText: NSLocalizedString(
  122. "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.",
  123. comment: "Current Basal Safety Multiplier"
  124. ),
  125. settable: self
  126. ),
  127. Field(
  128. displayName: NSLocalizedString("Autosens Max", comment: "Autosens Max"),
  129. type: .decimal(keypath: \.autosensMax),
  130. infoText: NSLocalizedString(
  131. "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.",
  132. comment: "Autosens Max"
  133. ),
  134. settable: self
  135. ),
  136. Field(
  137. displayName: NSLocalizedString("Autosens Min", comment: "Autosens Min"),
  138. type: .decimal(keypath: \.autosensMin),
  139. infoText: NSLocalizedString(
  140. "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.",
  141. comment: "Autosens Min"
  142. ),
  143. settable: self
  144. )
  145. ]
  146. let dynamicISF = [
  147. Field(
  148. displayName: NSLocalizedString("Enable Dynamic ISF", comment: "Enable Dynamic ISF"),
  149. type: .boolean(keypath: \.useNewFormula),
  150. infoText: NSLocalizedString(
  151. "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",
  152. comment: "Enable Dynamic ISF"
  153. ),
  154. settable: self
  155. ),
  156. Field(
  157. displayName: NSLocalizedString("Enable Dynamic CR", comment: "Use Dynamic CR together with Dynamic ISF"),
  158. type: .boolean(keypath: \.enableDynamicCR),
  159. infoText: NSLocalizedString(
  160. "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)",
  161. comment: "Use Dynamic CR together with Dynamic ISF"
  162. ),
  163. settable: self
  164. ),
  165. Field(
  166. displayName: NSLocalizedString("Adjustment Factor", comment: "Adjust Dynamic ISF constant"),
  167. type: .decimal(keypath: \.adjustmentFactor),
  168. infoText: NSLocalizedString(
  169. "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",
  170. comment: "Adjust Dynamic ISF constant"
  171. ),
  172. settable: self
  173. ),
  174. Field(
  175. displayName: NSLocalizedString("Use Sigmoid Function", comment: "Use Sigmoid Function"),
  176. type: .boolean(keypath: \.sigmoid),
  177. infoText: NSLocalizedString(
  178. "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.",
  179. comment: "Use Sigmoid Function"
  180. ),
  181. settable: self
  182. ),
  183. Field(
  184. displayName: NSLocalizedString(
  185. "Weighted Average of TDD. Weight of past 24 hours:",
  186. comment: "Weight of past 24 hours of insulin"
  187. ),
  188. type: .decimal(keypath: \.weightPercentage),
  189. infoText: NSLocalizedString(
  190. "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).",
  191. comment: "Weight of past 24 hours of insulin"
  192. ),
  193. settable: self
  194. ),
  195. Field(
  196. displayName: NSLocalizedString("Adjust basal", comment: "Enable adjustment of basal profile"),
  197. type: .boolean(keypath: \.tddAdjBasal),
  198. infoText: NSLocalizedString(
  199. "Enable adjustment of basal based on the ratio of current TDD / 7 day average TDD",
  200. comment: "Enable adjustment of basal profile"
  201. ),
  202. settable: self
  203. ),
  204. Field(
  205. displayName: NSLocalizedString("Threshold Setting (mg/dl)", comment: "Threshold Setting"),
  206. type: .decimal(keypath: \.threshold_setting),
  207. infoText: NSLocalizedString(
  208. "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.",
  209. comment: "Threshold Setting"
  210. ),
  211. settable: self
  212. )
  213. ]
  214. let smbFields = [
  215. Field(
  216. displayName: NSLocalizedString("Enable SMB Always", comment: "Enable SMB Always"),
  217. type: .boolean(keypath: \.enableSMBAlways),
  218. infoText: NSLocalizedString(
  219. "Defaults to false. When true, always enable supermicrobolus (unless disabled by high temptarget).",
  220. comment: "Enable SMB Always"
  221. ),
  222. settable: self
  223. ),
  224. Field(
  225. displayName: NSLocalizedString("Max Delta-BG Threshold SMB", comment: "Max Delta-BG Threshold"),
  226. type: .decimal(keypath: \.maxDeltaBGthreshold),
  227. infoText: NSLocalizedString(
  228. "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!).",
  229. comment: "Max Delta-BG Threshold"
  230. ),
  231. settable: self
  232. ),
  233. Field(
  234. displayName: NSLocalizedString("Enable SMB With COB", comment: "Enable SMB With COB"),
  235. type: .boolean(keypath: \.enableSMBWithCOB),
  236. infoText: NSLocalizedString(
  237. "This enables supermicrobolus (SMB) while carbs on board (COB) are positive.",
  238. comment: "Enable SMB With COB"
  239. ),
  240. settable: self
  241. ),
  242. Field(
  243. displayName: NSLocalizedString("Enable SMB With Temptarget", comment: "Enable SMB With Temptarget"),
  244. type: .boolean(keypath: \.enableSMBWithTemptarget),
  245. infoText: NSLocalizedString(
  246. "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.",
  247. comment: "Enable SMB With Temptarget"
  248. ),
  249. settable: self
  250. ),
  251. Field(
  252. displayName: NSLocalizedString("Enable SMB After Carbs", comment: "Enable SMB After Carbs"),
  253. type: .boolean(keypath: \.enableSMBAfterCarbs),
  254. infoText: NSLocalizedString(
  255. "Defaults to false. When true, enables supermicrobolus (SMB) for 6h after carbs, even with 0 carbs on board (COB).",
  256. comment: "Enable SMB After Carbs"
  257. ),
  258. settable: self
  259. ),
  260. Field(
  261. displayName: NSLocalizedString(
  262. "Allow SMB With High Temptarget",
  263. comment: "Allow SMB With High Temptarget"
  264. ),
  265. type: .boolean(keypath: \.allowSMBWithHighTemptarget),
  266. infoText: NSLocalizedString(
  267. "Defaults to false. When true, allows supermicrobolus (if otherwise enabled) even with high temp targets (> 100 mg/dl).",
  268. comment: "Allow SMB With High Temptarget"
  269. ),
  270. settable: self
  271. ),
  272. Field(
  273. displayName: NSLocalizedString("Enable SMB With High BG", comment: "Enable SMB With High BG"),
  274. type: .boolean(keypath: \.enableSMB_high_bg),
  275. infoText: NSLocalizedString(
  276. "Enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile)",
  277. comment: "Enable SMB With High BG"
  278. ),
  279. settable: self
  280. ),
  281. Field(
  282. displayName: NSLocalizedString(
  283. "... When Blood Glucose Is Over (mg/dl):",
  284. comment: "... When Blood Glucose Is Over (mg/dl):"
  285. ),
  286. type: .decimal(keypath: \.enableSMB_high_bg_target),
  287. infoText: NSLocalizedString(
  288. "Set the value enableSMB_high_bg will compare against to enable SMB. If BG > than this value, SMBs should enable.",
  289. comment: "... When Blood Glucose Is Over (mg/dl):"
  290. ),
  291. settable: self
  292. ),
  293. Field(
  294. displayName: NSLocalizedString("Enable UAM", comment: "Enable UAM"),
  295. type: .boolean(keypath: \.enableUAM),
  296. infoText: NSLocalizedString(
  297. "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.",
  298. comment: "Enable UAM"
  299. ),
  300. settable: self
  301. ),
  302. Field(
  303. displayName: NSLocalizedString("Max SMB Basal Minutes", comment: "Max SMB Basal Minutes"),
  304. type: .decimal(keypath: \.maxSMBBasalMinutes),
  305. infoText: NSLocalizedString(
  306. "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.",
  307. comment: "Max SMB Basal Minutes"
  308. ),
  309. settable: self
  310. ),
  311. Field(
  312. displayName: NSLocalizedString("Max UAM SMB Basal Minutes", comment: "Max UAM SMB Basal Minutes"),
  313. type: .decimal(keypath: \.maxUAMSMBBasalMinutes),
  314. infoText: NSLocalizedString(
  315. "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.",
  316. comment: "Max UAM SMB Basal Minutes"
  317. ),
  318. settable: self
  319. ),
  320. Field(
  321. displayName: NSLocalizedString("SMB DeliveryRatio", comment: "SMB DeliveryRatio"),
  322. type: .decimal(keypath: \.smbDeliveryRatio),
  323. infoText: NSLocalizedString(
  324. "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.",
  325. comment: "SMB DeliveryRatio"
  326. ),
  327. settable: self
  328. ),
  329. Field(
  330. displayName: NSLocalizedString("SMB Interval", comment: "SMB Interval"),
  331. type: .decimal(keypath: \.smbInterval),
  332. infoText: NSLocalizedString(
  333. "Minimum duration in minutes for new SMB since last SMB or manual bolus",
  334. comment: "SMB Interval"
  335. ),
  336. settable: self
  337. ),
  338. Field(
  339. displayName: NSLocalizedString("Bolus Increment", comment: "Bolus Increment"),
  340. type: .decimal(keypath: \.bolusIncrement),
  341. infoText: NSLocalizedString(
  342. "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.",
  343. comment: "Bolus Increment"
  344. ),
  345. settable: self
  346. )
  347. ]
  348. // MARK: - Targets fields
  349. let targetSettings = [
  350. Field(
  351. displayName: NSLocalizedString(
  352. "High Temptarget Raises Sensitivity",
  353. comment: "High Temptarget Raises Sensitivity"
  354. ),
  355. type: .boolean(keypath: \.highTemptargetRaisesSensitivity),
  356. infoText: NSLocalizedString(
  357. "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).",
  358. comment: "High Temptarget Raises Sensitivity"
  359. ),
  360. settable: self
  361. ),
  362. Field(
  363. displayName: NSLocalizedString(
  364. "Low Temptarget Lowers Sensitivity",
  365. comment: "Low Temptarget Lowers Sensitivity"
  366. ),
  367. type: .boolean(keypath: \.lowTemptargetLowersSensitivity),
  368. infoText: NSLocalizedString(
  369. "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).",
  370. comment: "Low Temptarget Lowers Sensitivity"
  371. ),
  372. settable: self
  373. ),
  374. Field(
  375. displayName: NSLocalizedString("Sensitivity Raises Target", comment: "Sensitivity Raises Target"),
  376. type: .boolean(keypath: \.sensitivityRaisesTarget),
  377. infoText: NSLocalizedString(
  378. "When true, raises BG target when autosens detects sensitivity",
  379. comment: "Sensitivity Raises Target"
  380. ),
  381. settable: self
  382. ),
  383. Field(
  384. displayName: NSLocalizedString("Resistance Lowers Target", comment: "Resistance Lowers Target"),
  385. type: .boolean(keypath: \.resistanceLowersTarget),
  386. infoText: NSLocalizedString(
  387. "Defaults to false. When true, will lower BG target when autosens detects resistance",
  388. comment: "Resistance Lowers Target"
  389. ),
  390. settable: self
  391. ),
  392. Field(
  393. displayName: NSLocalizedString("Half Basal Exercise Target", comment: "Half Basal Exercise Target"),
  394. type: .decimal(keypath: \.halfBasalExerciseTarget),
  395. infoText: NSLocalizedString(
  396. "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.",
  397. comment: "Half Basal Exercise Target"
  398. ),
  399. settable: self
  400. )
  401. ]
  402. // MARK: - Other fields
  403. let otherSettings = [
  404. Field(
  405. displayName: NSLocalizedString("Rewind Resets Autosens", comment: "Rewind Resets Autosens"),
  406. type: .boolean(keypath: \.rewindResetsAutosens),
  407. infoText: NSLocalizedString(
  408. "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.",
  409. comment: "Rewind Resets Autosens"
  410. ),
  411. settable: self
  412. ),
  413. Field(
  414. displayName: NSLocalizedString("Use Custom Peak Time", comment: "Use Custom Peak Time"),
  415. type: .boolean(keypath: \.useCustomPeakTime),
  416. infoText: NSLocalizedString(
  417. "Defaults to false. Setting to true allows changing insulinPeakTime", comment: "Use Custom Peak Time"
  418. ),
  419. settable: self
  420. ),
  421. Field(
  422. displayName: NSLocalizedString("Insulin Peak Time", comment: "Insulin Peak Time"),
  423. type: .decimal(keypath: \.insulinPeakTime),
  424. infoText: NSLocalizedString(
  425. "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 FreeAPS-X, longer loop calculations and possible red loops.",
  426. comment: "Insulin Peak Time"
  427. ),
  428. settable: self
  429. ),
  430. Field(
  431. displayName: NSLocalizedString("Skip Neutral Temps", comment: "Skip Neutral Temps"),
  432. type: .boolean(keypath: \.skipNeutralTemps),
  433. infoText: NSLocalizedString(
  434. "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.",
  435. comment: "Skip Neutral Temps"
  436. ),
  437. settable: self
  438. ),
  439. Field(
  440. displayName: NSLocalizedString("Unsuspend If No Temp", comment: "Unsuspend If No Temp"),
  441. type: .boolean(keypath: \.unsuspendIfNoTemp),
  442. infoText: NSLocalizedString(
  443. "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.",
  444. comment: "Unsuspend If No Temp"
  445. ),
  446. settable: self
  447. ),
  448. Field(
  449. displayName: NSLocalizedString("Suspend Zeros IOB", comment: "Suspend Zeros IOB"),
  450. type: .boolean(keypath: \.suspendZerosIOB),
  451. infoText: NSLocalizedString(
  452. "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.",
  453. comment: "Suspend Zeros IOB"
  454. ),
  455. settable: self
  456. ),
  457. Field(
  458. displayName: NSLocalizedString("Min 5m Carbimpact", comment: "Min 5m Carbimpact"),
  459. type: .decimal(keypath: \.min5mCarbimpact),
  460. infoText: NSLocalizedString(
  461. "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.",
  462. comment: "Min 5m Carbimpact"
  463. ),
  464. settable: self
  465. ),
  466. Field(
  467. displayName: NSLocalizedString(
  468. "Autotune ISF Adjustment Fraction",
  469. comment: "Autotune ISF Adjustment Fraction"
  470. ),
  471. type: .decimal(keypath: \.autotuneISFAdjustmentFraction),
  472. infoText: NSLocalizedString(
  473. "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.",
  474. comment: "Autotune ISF Adjustment Fraction"
  475. ),
  476. settable: self
  477. ),
  478. Field(
  479. displayName: NSLocalizedString("Remaining Carbs Fraction", comment: "Remaining Carbs Fraction"),
  480. type: .decimal(keypath: \.remainingCarbsFraction),
  481. infoText: NSLocalizedString(
  482. "This is the fraction of carbs we’ll assume will absorb over 4h if we don’t yet see carb absorption.",
  483. comment: "Remaining Carbs Fraction"
  484. ),
  485. settable: self
  486. ),
  487. Field(
  488. displayName: NSLocalizedString("Remaining Carbs Cap", comment: "Remaining Carbs Cap"),
  489. type: .decimal(keypath: \.remainingCarbsCap),
  490. infoText: NSLocalizedString(
  491. "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.",
  492. comment: "Remaining Carbs Cap"
  493. ),
  494. settable: self
  495. ),
  496. Field(
  497. displayName: NSLocalizedString("Noisy CGM Target Multiplier", comment: "Noisy CGM Target Multiplier"),
  498. type: .decimal(keypath: \.noisyCGMTargetMultiplier),
  499. infoText: NSLocalizedString(
  500. "Defaults to 1.3. Increase target by this amount when looping off raw/noisy CGM data",
  501. comment: "Noisy CGM Target Multiplier"
  502. ),
  503. settable: self
  504. )
  505. ]
  506. sections = [
  507. FieldSection(
  508. displayName: NSLocalizedString("Statistics", comment: "Options for Statistics"), fields: statFields
  509. ),
  510. FieldSection(
  511. displayName: NSLocalizedString("OpenAPS main settings", comment: "OpenAPS main settings"), fields: mainFields
  512. ),
  513. FieldSection(
  514. displayName: NSLocalizedString("Dynamic settings", comment: "Dynamic settings"),
  515. fields: dynamicISF
  516. ),
  517. FieldSection(
  518. displayName: NSLocalizedString("OpenAPS SMB settings", comment: "OpenAPS SMB settings"),
  519. fields: smbFields
  520. ),
  521. FieldSection(
  522. displayName: NSLocalizedString("OpenAPS targets settings", comment: "OpenAPS targets settings"),
  523. fields: targetSettings
  524. ),
  525. FieldSection(
  526. displayName: NSLocalizedString("OpenAPS other settings", comment: "OpenAPS other settings"),
  527. fields: otherSettings
  528. )
  529. ]
  530. }
  531. func set<T>(_ keypath: WritableKeyPath<Preferences, T>, value: T) {
  532. preferences[keyPath: keypath] = value
  533. save()
  534. }
  535. func get<T>(_ keypath: WritableKeyPath<Preferences, T>) -> T {
  536. preferences[keyPath: keypath]
  537. }
  538. func save() {
  539. provider.savePreferences(preferences)
  540. }
  541. }
  542. }