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