Skip to content

Commit 5a79416

Browse files
committed
2 parents 06bdbf1 + 9ac2251 commit 5a79416

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/services/BluetoothGlucoseMeter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,14 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
223223
Bluetooth_CMD.notify(GLUCOSE_SERVICE, GLUCOSE_CHARACTERISTIC, "notify new glucose record");
224224
Bluetooth_CMD.enable_notification_value(GLUCOSE_SERVICE, GLUCOSE_CHARACTERISTIC, "notify new glucose value");
225225

226-
Bluetooth_CMD.enable_notification_value(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC, "notify new context value");
227-
Bluetooth_CMD.notify(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC, "notify new glucose context");
226+
if (hasContextCharacteristic(gatt)) {
227+
Bluetooth_CMD.enable_notification_value(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC, "notify new context value");
228+
Bluetooth_CMD.notify(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC, "notify new glucose context");
229+
} else {
230+
if (d) {
231+
Log.d(TAG, "Device has no context characteristic. Skipping");
232+
}
233+
}
228234

229235
Bluetooth_CMD.enable_indications(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "readings indication request");
230236
Bluetooth_CMD.notify(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "notify glucose record");
@@ -241,6 +247,15 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
241247
}
242248
}
243249

250+
private boolean hasContextCharacteristic(BluetoothGatt gatt) {
251+
BluetoothGattService glucoseService = gatt.getService(GLUCOSE_SERVICE);
252+
if (glucoseService != null) {
253+
BluetoothGattCharacteristic contextCharacteristic = glucoseService.getCharacteristic(CONTEXT_CHARACTERISTIC);
254+
return contextCharacteristic != null;
255+
}
256+
return false;
257+
}
258+
244259
@Override
245260
public void onDescriptorWrite(BluetoothGatt gatt,
246261
BluetoothGattDescriptor descriptor,

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/BgGraphBuilder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public class BgGraphBuilder {
129129
private SharedPreferences prefs;
130130
public double highMark;
131131
public double lowMark;
132+
public double forecastLowMark; // Marker used for forecast low analysis
132133
public double defaultMinY;
133134
public double defaultMaxY;
134135
public boolean doMgdl;
@@ -243,6 +244,10 @@ public BgGraphBuilder(Context context, long start, long end, int numValues, bool
243244
this.context = context;
244245
this.highMark = tolerantParseDouble(prefs.getString("highValue", "170"), 170);
245246
this.lowMark = tolerantParseDouble(prefs.getString("lowValue", "70"), 70);
247+
this.forecastLowMark = this.lowMark; // Set the forecast low marker to match the low value marker
248+
if (!Pref.getBoolean("low_value_is_forecast_low_threshold", true)) { // If the user has chosen not to use the Low Value as the Forecast Low threshold
249+
this.forecastLowMark = tolerantParseDouble(prefs.getString("forecast_low_threshold", "70"), 70); // Set the forecast low marker to match the forecast low threshold specified by the user
250+
}
246251
this.doMgdl = (prefs.getString("units", "mgdl").equals("mgdl"));
247252
defaultMinY = unitized(40);
248253
defaultMaxY = unitized(250);
@@ -1461,15 +1466,15 @@ private synchronized void addBgReadingValues(final boolean simple) {
14611466
double polyPredicty = poly.predict(plow_timestamp);
14621467
Log.d(TAG, "Low predictor at max lookahead is: " + JoH.qs(polyPredicty));
14631468
low_occurs_at_processed_till_timestamp = highest_bgreading_timestamp; // store that we have processed up to this timestamp
1464-
if (polyPredicty <= (lowMark + offset)) {
1469+
if (polyPredicty <= (forecastLowMark + offset)) {
14651470
low_occurs_at = plow_timestamp;
1466-
final double lowMarkIndicator = (lowMark - (lowMark / 4));
1471+
final double lowMarkIndicator = (forecastLowMark - (forecastLowMark / 4));
14671472
//if (d) Log.d(TAG, "Poly predict: "+JoH.qs(polyPredict)+" @ "+JoH.qsz(iob.timestamp));
14681473
while (plow_timestamp > plow_now) {
14691474
// plow_timestamp = plow_timestamp - FUZZER;
14701475
plow_timestamp = plow_timestamp - (1000 * 30 * 5); // TODO check this! 2.5 minute accuracy on dots and low mark intercept for low_occurs at
14711476
polyPredicty = poly.predict(plow_timestamp);
1472-
if (polyPredicty > (lowMark + offset)) {
1477+
if (polyPredicty > (forecastLowMark + offset)) {
14731478
PointValue zv = new HPointValue((double) (plow_timestamp / FUZZER), (float) polyPredicty);
14741479
polyBgValues.add(zv);
14751480
} else {

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/IdempotentMigrations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private static void legacySettingsMoveLanguageFromNoToNb() {
173173
// Include new preference settings here that represent glucose values.
174174
private static void prefSettingRangeVerification() {
175175
Preferences.applyPrefSettingRange("persistent_high_threshold", "170", MIN_GLUCOSE_INPUT, MAX_GLUCOSE_INPUT);
176+
Preferences.applyPrefSettingRange("forecast_low_threshold", "70", MIN_GLUCOSE_INPUT, MAX_GLUCOSE_INPUT);
176177
}
177178

178179
}

app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ public void onCreate(Bundle savedInstanceState) {
11341134
bindPreferenceSummaryToValue(findPreference("other_alerts_sound"));
11351135
bindPreferenceSummaryToValue(findPreference("bridge_battery_alert_level"));
11361136
bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(findPreference("persistent_high_threshold"));
1137+
bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(findPreference("forecast_low_threshold"));
11371138

11381139
addPreferencesFromResource(R.xml.pref_data_source);
11391140

@@ -3116,6 +3117,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
31163117
final Double default_insulin_sensitivity = Double.parseDouble(preferences.getString("profile_insulin_sensitivity_default", "54"));
31173118
final Double default_target_glucose = Double.parseDouble(preferences.getString("plus_target_range", "100"));
31183119
final Double persistent_high_Val = Double.parseDouble(preferences.getString("persistent_high_threshold", "0"));
3120+
final Double forecast_low_Val = Double.parseDouble(preferences.getString("forecast_low_threshold", "0"));
31193121

31203122

31213123
static_units = newValue.toString();
@@ -3132,6 +3134,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
31323134
preferences.edit().putString("persistent_high_threshold", Long.toString(Math.round(persistent_high_Val * Constants.MMOLL_TO_MGDL))).apply();
31333135
Profile.invalidateProfile();
31343136
}
3137+
if (forecast_low_Val < 36) {
3138+
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
3139+
preferences.edit().putString("forecast_low_threshold", Long.toString(Math.round(forecast_low_Val * Constants.MMOLL_TO_MGDL))).apply();
3140+
Profile.invalidateProfile();
3141+
}
31353142
if (lowVal < 36) {
31363143
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
31373144
preferences.edit().putString("lowValue", Long.toString(Math.round(lowVal * Constants.MMOLL_TO_MGDL))).apply();
@@ -3153,6 +3160,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
31533160
preferences.edit().putString("persistent_high_threshold", JoH.qs(persistent_high_Val * Constants.MGDL_TO_MMOLL, 1)).apply();
31543161
Profile.invalidateProfile();
31553162
}
3163+
if (forecast_low_Val > 35) {
3164+
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
3165+
preferences.edit().putString("forecast_low_threshold", JoH.qs(forecast_low_Val * Constants.MGDL_TO_MMOLL, 1)).apply();
3166+
Profile.invalidateProfile();
3167+
}
31563168
if (lowVal > 35) {
31573169
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
31583170
preferences.edit().putString("lowValue", JoH.qs(lowVal * Constants.MGDL_TO_MMOLL, 1)).apply();
@@ -3166,6 +3178,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
31663178
allPrefsFragment.setSummary("highValue");
31673179
allPrefsFragment.setSummary("lowValue");
31683180
allPrefsFragment.setSummary("persistent_high_threshold");
3181+
allPrefsFragment.setSummary("forecast_low_threshold");
31693182
}
31703183
if (profile_insulin_sensitivity_default != null) {
31713184
Log.d(TAG, "refreshing profile insulin sensitivity default display");

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
<string name="pref_was_less_than_min">%1$s was set to a value less than minimum allowed. It has been changed to minimum.</string>
253253
<string name="extrapolate_data_to_try_to_predict_lows">Extrapolate data to try to predict lows</string>
254254
<string name="alarm_at_forecasted_low_mins">Alarm at Forecasted Low mins</string>
255+
<string name="title_forecast_low_threshold">Threshold</string>
255256
<string name="other_xdrip_plus_alerts">Other xDrip+ alerts</string>
256257
<string name="xdrip_plus_display_settings">xDrip+ Display Settings</string>
257258
<string name="display_customisations">Display customizations</string>
@@ -1536,6 +1537,8 @@
15361537
<string name="summary_persistent_high_alert">When above threshold and not falling for long</string>
15371538
<string name="summary_persistent_high_threshold_link">When enabled, High Value is the threshold.\nWhen disabled, the threshold is the value specified below.</string>
15381539
<string name="title_persistent_high_threshold_link">Threshold: High Value</string>
1540+
<string name="summary_forecast_low_threshold_link">When enabled, Low Value is the threshold.\nWhen disabled, the threshold is the value specified below.</string>
1541+
<string name="title_forecast_low_threshold_link">Threshold: Low Value</string>
15391542
<string name="note_search_button">SEARCH</string>
15401543
<string name="all_note_button">ALL</string>
15411544
<string name="title_full_screen_mode">Full Screen mode</string>

app/src/main/res/xml/pref_notifications.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@
360360
android:key="predict_lows_alarm"
361361
android:summary="@string/notify_when_predicted_low_time_reaches_threshold"
362362
android:title="@string/raise_alarm_on_forecast_low" />
363+
<SwitchPreference
364+
android:defaultValue="true"
365+
android:disableDependentsState="true"
366+
android:key="low_value_is_forecast_low_threshold"
367+
android:summary="@string/summary_forecast_low_threshold_link"
368+
android:title="@string/title_forecast_low_threshold_link" />
369+
<EditTextPreference
370+
android:defaultValue="70"
371+
android:dependency="low_value_is_forecast_low_threshold"
372+
android:inputType="numberDecimal"
373+
android:key="forecast_low_threshold"
374+
android:title="@string/title_forecast_low_threshold" />
363375
<EditTextPreference
364376
android:defaultValue="40"
365377
android:dependency="predict_lows_alarm"

0 commit comments

Comments
 (0)