diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 93eebec9b..79ec61208 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -52,7 +52,9 @@ function enable_smb( profile, microBolusAllowed, meal_data, - target_bg + bg, + target_bg, + high_bg ) { // disable SMB when a high temptarget is set if (! microBolusAllowed) { @@ -105,7 +107,19 @@ function enable_smb( console.error("SMB enabled for temptarget of",convert_bg(target_bg, profile)); } return true; - } + } + + // enable SMB if high bg is found + if (profile.enableSMB_high_bg === true && high_bg !== null && bg >= high_bg) { + console.error("Checking BG to see if High for SMB enablement."); + console.error("Current BG", bg, " | High BG ", high_bg); + if (meal_data.bwFound) { + console.error("Warning: High BG SMB enabled within 6h of using Bolus Wizard: be sure to easy bolus 30s before using Bolus Wizard"); + } else { + console.error("High BG detected. Enabling SMB."); + } + return true; + } console.error("SMB disabled (no enableSMB preferences active or no condition satisfied)"); return false; @@ -215,12 +229,16 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ var target_bg; var min_bg; var max_bg; + var high_bg; if (typeof profile.min_bg !== 'undefined') { min_bg = profile.min_bg; } if (typeof profile.max_bg !== 'undefined') { max_bg = profile.max_bg; } + if (typeof profile.enableSMB_high_bg_target !== 'undefined') { + high_bg = profile.enableSMB_high_bg_target; + } if (typeof profile.min_bg !== 'undefined' && typeof profile.max_bg !== 'undefined') { target_bg = (profile.min_bg + profile.max_bg) / 2; } else { @@ -434,7 +452,9 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ profile, microBolusAllowed, meal_data, - target_bg + bg, + target_bg, + high_bg ); // enable UAM (if enabled in preferences) diff --git a/lib/profile/index.js b/lib/profile/index.js index fc15f1b94..f4bdae9f7 100644 --- a/lib/profile/index.js +++ b/lib/profile/index.js @@ -45,6 +45,8 @@ function defaults ( ) { // if the CGM sensor reads falsely high and doesn't come down as actual BG does , enableSMB_always: false // always enable supermicrobolus (unless disabled by high temptarget) , enableSMB_after_carbs: false // enable supermicrobolus for 6h after carbs, even with 0 COB + , enableSMB_high_bg: false // enable SMBs when a high BG is detected, based on the high BG target (adjusted or profile) + , enableSMB_high_bg_target: 110 // set the value enableSMB_high_bg will compare against to enable SMB. If BG > than this value, SMBs should enable. // *** WARNING *** DO NOT USE enableSMB_always or enableSMB_after_carbs with Libre or similar. , allowSMB_with_high_temptarget: false // allow supermicrobolus (if otherwise enabled) even with high temp targets , maxSMBBasalMinutes: 30 // maximum minutes of basal that can be delivered as a single SMB with uncovered COB