Jon Mårtensson 4 лет назад
Родитель
Сommit
60fbc7355e

+ 5 - 0
FreeAPS/Resources/javascript/middleware/determine_basal.js

@@ -4,6 +4,7 @@ function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoi
     const BG = glucose[0].glucose;
     // Change to false to turn off Chris Wilson's formula
     var chrisFormula = preferences.enableChris;
+    var useDynamicCR = preferences.enableDynamicCR;
     const minLimitChris = profile.autosens_min;
     const maxLimitChris = profile.autosens_max;
     const adjustmentFactor = preferences.adjustmentFactor;
@@ -277,6 +278,10 @@ function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoi
         
         // Set the new ratio
         autosens.ratio = round(newRatio, 2);
+        // Set the new Dynamic CR (Test)
+        if (useDynamicCR == true) {
+            profile.carb_ratio = round(profile.carb_ratio/newRatio, 2);
+        }
         // Print to log
         return log + logTDD + logBolus + logTempBasal + logBasal;
         

+ 2 - 0
FreeAPS/Sources/Models/Preferences.swift

@@ -64,6 +64,7 @@ struct Preferences: JSON {
     var maxDeltaBGthreshold: Decimal = 0.2
     var adjustmentFactor: Decimal = 1.0
     var enableChris: Bool = true
+    var enableDynamicCR: Bool = false
 }
 
 extension Preferences {
@@ -130,6 +131,7 @@ extension Preferences {
         case maxDeltaBGthreshold = "maxDelta_bg_threshold"
         case adjustmentFactor
         case enableChris
+        case enableDynamicCR
     }
 }
 

+ 9 - 0
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift

@@ -109,6 +109,15 @@ extension PreferencesEditor {
                         comment: "Enable Dynamic ISF"
                     ),
                     settable: self
+                ),
+                Field(
+                    displayName: "Enable Dynamic CR",
+                    type: .boolean(keypath: \.enableDynamicCR),
+                    infoText: NSLocalizedString(
+                        "Use Dynamic CR together with Dynamic ISF",
+                        comment: "Use Dynamic CR together with Dynamic ISF"
+                    ),
+                    settable: self
                 )
             ]