Incremental recovery duration
This commit is contained in:
parent
c564cc2214
commit
a4312acb3e
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.ActiveBas
|
|||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.ActiveBolus;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.ActiveTBR;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.CartridgeStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.InsightState;
|
||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.descriptors.TotalDailyDose;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
@ -169,7 +170,8 @@ public class LocalInsightFragment extends SubscriberFragment implements View.OnC
|
|||
|
||||
private void getConnectionStatusItem(List<View> statusItems) {
|
||||
int string = 0;
|
||||
switch (LocalInsightPlugin.getInstance().getConnectionService().getState()) {
|
||||
InsightState state = LocalInsightPlugin.getInstance().getConnectionService().getState();
|
||||
switch (state) {
|
||||
case NOT_PAIRED:
|
||||
string = R.string.not_paired;
|
||||
break;
|
||||
|
@ -199,6 +201,9 @@ public class LocalInsightFragment extends SubscriberFragment implements View.OnC
|
|||
break;
|
||||
}
|
||||
statusItems.add(getStatusItem(MainApp.gs(R.string.insight_status), MainApp.gs(string)));
|
||||
if (state == InsightState.RECOVERING) {
|
||||
statusItems.add(getStatusItem(MainApp.gs(R.string.recovery_duration), LocalInsightPlugin.getInstance().getConnectionService().getRecoveryDuration() / 1000 + "s"));
|
||||
}
|
||||
}
|
||||
|
||||
private void getLastConnectedItem(List<View> statusItems) {
|
||||
|
|
|
@ -116,6 +116,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
private List<info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.Service> activatedServices = new ArrayList<>();
|
||||
private long lastDataTime;
|
||||
private long lastConnected;
|
||||
private long recoveryDuration = 0;
|
||||
|
||||
KeyPair getKeyPair() {
|
||||
if (keyPair == null) keyPair = Cryptograph.generateRSAKey();
|
||||
|
@ -130,6 +131,22 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
return randomBytes;
|
||||
}
|
||||
|
||||
public synchronized long getRecoveryDuration() {
|
||||
return recoveryDuration;
|
||||
}
|
||||
|
||||
private void increaseRecoveryDuration() {
|
||||
long maxRecoveryDuration = SP.getInt("insight_max_recovery_duration", 20);
|
||||
maxRecoveryDuration = Math.min(maxRecoveryDuration, 20);
|
||||
maxRecoveryDuration = Math.max(maxRecoveryDuration, 0);
|
||||
long minRecoveryDuration = SP.getInt("insight_min_recovery_duration", 5);
|
||||
minRecoveryDuration = Math.min(minRecoveryDuration, 20);
|
||||
minRecoveryDuration = Math.max(minRecoveryDuration, 0);
|
||||
recoveryDuration += 1000;
|
||||
recoveryDuration = Math.max(recoveryDuration, minRecoveryDuration * 1000);
|
||||
recoveryDuration = Math.min(recoveryDuration, maxRecoveryDuration * 1000);
|
||||
}
|
||||
|
||||
public long getLastConnected() {
|
||||
return lastConnected;
|
||||
}
|
||||
|
@ -255,7 +272,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
disconnectTimer.interrupt();
|
||||
disconnectTimer = null;
|
||||
}
|
||||
if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) connect();
|
||||
if (state == InsightState.DISCONNECTED && pairingDataStorage.isPaired()) {
|
||||
recoveryDuration = 0;
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void withdrawConnectionRequest(Object lock) {
|
||||
|
@ -271,7 +291,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
long disconnectTimeout = SP.getInt("insight_disconnect_delay", 5);
|
||||
disconnectTimeout = Math.min(disconnectTimeout, 15);
|
||||
disconnectTimeout = Math.max(disconnectTimeout, 0);
|
||||
log.info("Last connection lock released, will disconnect " + disconnectTimeout + " seconds");
|
||||
log.info("Last connection lock released, will disconnect in " + disconnectTimeout + " seconds");
|
||||
disconnectTimer = DelayedActionThread.runDelayed("Disconnect Timer", disconnectTimeout * 1000, this::disconnect);
|
||||
}
|
||||
}
|
||||
|
@ -342,15 +362,16 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
if (!(e instanceof ConnectionFailedException)) {
|
||||
connect();
|
||||
} else {
|
||||
int recoveryDuration = SP.getInt("insight_recovery_duration", 5);
|
||||
recoveryDuration = Math.min(recoveryDuration, 20);
|
||||
recoveryDuration = Math.max(recoveryDuration, 0);
|
||||
recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration * 1000, () -> {
|
||||
recoveryTimer = null;
|
||||
synchronized (InsightConnectionService.this) {
|
||||
if (!Thread.currentThread().isInterrupted()) connect();
|
||||
}
|
||||
});
|
||||
increaseRecoveryDuration();
|
||||
if (recoveryDuration == 0) connect();
|
||||
else {
|
||||
recoveryTimer = DelayedActionThread.runDelayed("RecoveryTimer", recoveryDuration, () -> {
|
||||
recoveryTimer = null;
|
||||
synchronized (InsightConnectionService.this) {
|
||||
if (!Thread.currentThread().isInterrupted()) connect();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -402,6 +423,7 @@ public class InsightConnectionService extends Service implements ConnectionEstab
|
|||
@Override
|
||||
public synchronized void onConnectionSucceed() {
|
||||
try {
|
||||
recoveryDuration = 0;
|
||||
inputStreamReader = new InputStreamReader(bluetoothSocket.getInputStream(), this);
|
||||
outputStreamWriter = new OutputStreamWriter(bluetoothSocket.getOutputStream(), this);
|
||||
inputStreamReader.start();
|
||||
|
|
|
@ -1230,7 +1230,6 @@
|
|||
<string name="log_alerts">Log alerts</string>
|
||||
<string name="enable_tbr_emulation">Enable TBR emulation</string>
|
||||
<string name="enable_tbr_emulation_summary">Use extended boluses instead of TBRs to bypass the 250% limit</string>
|
||||
<string name="recovery_duration">Recovery duration [s]</string>
|
||||
<string name="disconnect_delay">Disconnect delay [s]</string>
|
||||
<string name="serial_number">Serial number</string>
|
||||
<string name="release_software_version">Release software version</string>
|
||||
|
@ -1273,6 +1272,9 @@
|
|||
<string name="short_status_tdd">TDD: %1$.2f</string>
|
||||
<string name="short_status_reservoir">Reser.: %1$.2fU</string>
|
||||
<string name="short_status_battery">Batt.: %1$d%%</string>
|
||||
<string name="max_recovery_duration">Max. recovery duration [s]</string>
|
||||
<string name="min_recovery_duration">Min. recovery duration [s]</string>
|
||||
<string name="recovery_duration">Recovery duration</string>
|
||||
|
||||
<plurals name="objective_days">
|
||||
<item quantity="one">%1$d day</item>
|
||||
|
|
|
@ -40,8 +40,14 @@
|
|||
<EditTextPreference
|
||||
android:defaultValue="5"
|
||||
android:inputType="number"
|
||||
android:key="insight_recovery_duration"
|
||||
android:title="@string/recovery_duration" />
|
||||
android:key="insight_min_recovery_duration"
|
||||
android:title="@string/min_recovery_duration" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="20"
|
||||
android:inputType="number"
|
||||
android:key="insight_max_recovery_duration"
|
||||
android:title="@string/max_recovery_duration" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="5"
|
||||
|
|
Loading…
Reference in a new issue