Skip to content
Snippets Groups Projects
Commit 228bcef2 authored by Volker Richert's avatar Volker Richert
Browse files

Merge branch 'develop' into feature/history

# Conflicts:
#	app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlIntentService.java
parents a52f83a0 1e1419e4
Branches
Tags
No related merge requests found
...@@ -109,11 +109,23 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -109,11 +109,23 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
private StatusMessageReceiver statusMessageReceiver = new StatusMessageReceiver(); private StatusMessageReceiver statusMessageReceiver = new StatusMessageReceiver();
private MedtronicCnlAlarmReceiver medtronicCnlAlarmReceiver = new MedtronicCnlAlarmReceiver(); private MedtronicCnlAlarmReceiver medtronicCnlAlarmReceiver = new MedtronicCnlAlarmReceiver();
/**
* calculate the next poll timestamp based on last svg event
*
* @param pumpStatusData
* @return timestamp
*/
public static long getNextPoll(PumpStatusEvent pumpStatusData) { public static long getNextPoll(PumpStatusEvent pumpStatusData) {
long nextPoll = pumpStatusData.getEventDate().getTime() + pumpStatusData.getPumpTimeOffset() long nextPoll = pumpStatusData.getEventDate().getTime() + pumpStatusData.getPumpTimeOffset(),
+ MedtronicCnlIntentService.POLL_GRACE_PERIOD_MS; now = System.currentTimeMillis();
// align to next poll slot
if (nextPoll + 2 * 60 * 60 * 1000 < now) { // last event more than 2h old -> could be a calibration
nextPoll = System.currentTimeMillis() + 1000;
} else {
// align to poll interval
nextPoll += (((now - nextPoll) / MainActivity.pollInterval)) * MainActivity.pollInterval
+ MedtronicCnlIntentService.POLL_GRACE_PERIOD_MS;
if (pumpStatusData.getBatteryPercentage() > 25) { if (pumpStatusData.getBatteryPercentage() > 25) {
// poll every 5 min // poll every 5 min
nextPoll += MainActivity.pollInterval; nextPoll += MainActivity.pollInterval;
...@@ -122,6 +134,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -122,6 +134,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
//TODO add message & document it //TODO add message & document it
nextPoll += MainActivity.lowBatteryPollInterval; nextPoll += MainActivity.lowBatteryPollInterval;
} }
}
return nextPoll; return nextPoll;
} }
...@@ -411,7 +424,18 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -411,7 +424,18 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
} }
private void startCgmService() { private void startCgmService() {
startCgmService(System.currentTimeMillis() + 1000); startCgmServiceDelayed(0);
}
private void startCgmServiceDelayed(long delay) {
RealmResults<PumpStatusEvent> results = mRealm.where(PumpStatusEvent.class)
.findAllSorted("eventDate", Sort.DESCENDING);
if (results.size() > 0) {
startCgmService(getNextPoll(results.first()) + delay);
} else {
startCgmService(System.currentTimeMillis() + (delay==0?1000:delay));
}
} }
private void startCgmService(long initialPoll) { private void startCgmService(long initialPoll) {
...@@ -912,7 +936,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -912,7 +936,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
if (hasUsbPermission()) { if (hasUsbPermission()) {
// Give the USB a little time to warm up first // Give the USB a little time to warm up first
startCgmService(System.currentTimeMillis() + MedtronicCnlIntentService.USB_WARMUP_TIME_MS); startCgmServiceDelayed(MedtronicCnlIntentService.USB_WARMUP_TIME_MS);
} else { } else {
Log.d(TAG, "No permission for USB. Waiting."); Log.d(TAG, "No permission for USB. Waiting.");
waitForUsbPermission(); waitForUsbPermission();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment