Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Jul 17, 2024
2 parents 567dcd5 + db95b03 commit bcd2868
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import android.widget.TextView;
import android.widget.Toast;

import com.eveningoutpost.dexdrip.g5model.DexSyncKeeper;
import com.eveningoutpost.dexdrip.g5model.DexTimeKeeper;
import com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine;
import com.eveningoutpost.dexdrip.g5model.SensorDays;
Expand Down Expand Up @@ -2630,11 +2631,11 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
}

if (!isSensorActive) {
// Define a variable (notConnectedToG6Yet) that is only true if Native G6 is chosen, but, transmitter days is unknown.
boolean notConnectedToG6Yet = DexCollectionType.getDexCollectionType() == DexcomG5 && Pref.getBooleanDefaultFalse("ob1_g5_use_transmitter_alg") && Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1;
if (notConnectedToG6Yet || shortTxId()) { // Only if G6 has been selected and transmitter days is unknown, or if G7 has been selected.
// Define a variable (notConnectedToG6Yet) that is only true if Native G6 is chosen, but, transmitter days is unknown or not synced yet.
boolean notConnectedToG6Yet = DexCollectionType.getDexCollectionType() == DexcomG5 && Pref.getBooleanDefaultFalse("ob1_g5_use_transmitter_alg") && Pref.getBooleanDefaultFalse("using_g6") && (DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1 || !DexSyncKeeper.isReady(getTransmitterID()));
if (notConnectedToG6Yet || shortTxId()) { // Only if G6 has been selected and transmitter is not synced yet, or if G7 has been selected.
notificationText.setText(R.string.wait_to_connect);
} else { // Only if G6 is not selected or G6 transmitter days is known.
} else { // Only if G6 is not selected or G6 transmitter is synced.
notificationText.setText(R.string.now_start_your_sensor);
}

Expand All @@ -2653,7 +2654,7 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
dialog.show();
} else {
if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && !notConnectedToG6Yet && JoH.ratelimit("start-sensor_prompt", 20)) {
// Show the dialog only if there is no data, and there is no dialog, and G6 is not selected or G6 is connected, and the rate limit is satisfied.
// Show the start sensor prompt only if G6 is not selected or the G6 transmitter is synchronized.
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
final Context context = this;
builder.setTitle(getString(R.string.start_sensor) + "?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS;
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.SECOND_IN_MS;
import static com.eveningoutpost.dexdrip.utils.DexCollectionType.getBestCollectorHardwareName;
import static com.eveningoutpost.dexdrip.utils.bt.Helper.getStatusName;


Expand Down Expand Up @@ -133,6 +134,7 @@ public class Ob1G5StateMachine {
private static volatile AuthRequestTxMessage lastAuthPacket;
private static volatile boolean backup_loaded = false;
private static final int OLDEST_RAW = 300 * 24 * 60 * 60; // 300 days
private static long relAutoSessionStartTime = HOUR_IN_MS * 3;

public static long maxBackfillPeriod_MS = 0;

Expand Down Expand Up @@ -1550,14 +1552,19 @@ private static void processQueueCommand(Ob1G5CollectionService parent, RxBleConn
}

private static void checkAndActivateSensor() {
// automagically start an xDrip sensor session if transmitter already has active sensor
// automagically start an xDrip sensor session if transmitter already has active sensor
if (!Sensor.isActive() && Ob1G5CollectionService.isG5SensorStarted() && (!Sensor.stoppedRecently() || shortTxId())) {
JoH.static_toast_long(xdrip.gs(R.string.auto_starting_sensor));
// TODO possibly here we want to look at last sensor stop time and not backtrack before that
Sensor.create(tsl() - HOUR_IN_MS * 3);
if (shortTxId()) { // If we are using G7
Sensor.create(tsl() - HOUR_IN_MS * 24);
if (shortTxId()) relAutoSessionStartTime = HOUR_IN_MS * 24; // If we are using a G7
final List<BgReading> last = BgReading.latest(1); // Last reading
if ((last != null) && (last.size() > 0)) { // Have we had a reading?
final long now = JoH.tsl();
final long since = now - last.get(0).timestamp; // Time since last reading
if (since < relAutoSessionStartTime) { // If the last reading was less than 3 hours ago, or if we are using G7 and the last reading was less than 24 hours ago
relAutoSessionStartTime = since; // We will start the new session starting from the last reading.
}
}
Sensor.create(tsl() - relAutoSessionStartTime);
}
}

Expand Down

0 comments on commit bcd2868

Please sign in to comment.