Merge branch 'master' into insight-dev
This commit is contained in:
commit
ee704c3988
|
@ -1745,7 +1745,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return getDaoInsightPumpID().queryBuilder()
|
return getDaoInsightPumpID().queryBuilder()
|
||||||
.orderBy("timestamp", false)
|
.orderBy("timestamp", false)
|
||||||
.where().eq("pumpSerial", pumpSerial)
|
.where().eq("pumpSerial", pumpSerial)
|
||||||
.and().eq("eventType", "PumpStopped")
|
.and().in("eventType", "PumpStopped", "PumpPaused")
|
||||||
.and().lt("timestamp", before)
|
.and().lt("timestamp", before)
|
||||||
.queryForFirst();
|
.queryForFirst();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -823,7 +823,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
|
confirmMessage += "\n" + MainApp.gs(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
|
||||||
confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
confirmMessage += "\n" + MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||||
|
|
||||||
if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
|
if (Math.abs(insulinAfterConstraints - wizard.calculatedTotalInsulin) >= 0.01 || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror));
|
builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror));
|
||||||
builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
|
builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
|
||||||
|
|
|
@ -69,12 +69,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.his
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.ActiveBRProfileBlock;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile2Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile3Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile4Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile5Block;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock;
|
||||||
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock;
|
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock;
|
||||||
|
@ -155,7 +150,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Object $bolusLock = new Object[0];
|
private final Object $bolusLock = new Object[0];
|
||||||
private int bolusID = -1;
|
private int bolusID;
|
||||||
|
private boolean bolusCancelled;
|
||||||
private List<BasalProfileBlock> profileBlocks;
|
private List<BasalProfileBlock> profileBlocks;
|
||||||
private boolean limitsFetched;
|
private boolean limitsFetched;
|
||||||
private double maximumBolusAmount;
|
private double maximumBolusAmount;
|
||||||
|
@ -269,7 +265,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false;
|
if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this))
|
||||||
|
return false;
|
||||||
InsightState state = connectionService.getState();
|
InsightState state = connectionService.getState();
|
||||||
return state == InsightState.CONNECTING
|
return state == InsightState.CONNECTING
|
||||||
|| state == InsightState.APP_CONNECT_MESSAGE
|
|| state == InsightState.APP_CONNECT_MESSAGE
|
||||||
|
@ -308,11 +305,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class);
|
tbrOverNotificationBlock = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, TBROverNotificationBlock.class);
|
||||||
fetchStatus();
|
readHistory();
|
||||||
fetchBasalProfile();
|
fetchBasalProfile();
|
||||||
fetchLimitations();
|
fetchLimitations();
|
||||||
updatePumpTimeIfNeeded();
|
updatePumpTimeIfNeeded();
|
||||||
readHistory();
|
fetchStatus();
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
log.info("Exception while fetching status: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
} catch (InsightException e) {
|
} catch (InsightException e) {
|
||||||
|
@ -529,6 +526,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
bolusMessage.setExtendedAmount(0);
|
bolusMessage.setExtendedAmount(0);
|
||||||
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
|
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
|
||||||
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
||||||
|
bolusCancelled = false;
|
||||||
}
|
}
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -550,8 +548,12 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
detailedBolusInfo.pumpId = insightBolusID.id;
|
detailedBolusInfo.pumpId = insightBolusID.id;
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
while (true) {
|
while (true) {
|
||||||
fetchStatus();
|
synchronized ($bolusLock) {
|
||||||
|
if (bolusCancelled) break;
|
||||||
|
}
|
||||||
|
OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
|
||||||
if (operatingMode != OperatingMode.STARTED) break;
|
if (operatingMode != OperatingMode.STARTED) break;
|
||||||
|
List<ActiveBolus> activeBoluses = connectionService.requestMessage(new GetActiveBolusesMessage()).await().getActiveBoluses();
|
||||||
ActiveBolus activeBolus = null;
|
ActiveBolus activeBolus = null;
|
||||||
for (ActiveBolus bolus : activeBoluses) {
|
for (ActiveBolus bolus : activeBoluses) {
|
||||||
if (bolus.getBolusID() == bolusID) {
|
if (bolus.getBolusID() == bolusID) {
|
||||||
|
@ -566,11 +568,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
|
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
|
||||||
if (percentBefore != bolusingEvent.percent)
|
if (percentBefore != bolusingEvent.percent)
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
} else if (trials == -1 || trials++ >= 5) {
|
} else {
|
||||||
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
|
synchronized ($bolusLock) {
|
||||||
bolusingEvent.percent = 100;
|
if (bolusCancelled || trials == -1 || trials++ >= 5) {
|
||||||
MainApp.bus().post(bolusingEvent);
|
if (!bolusCancelled) {
|
||||||
break;
|
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
|
||||||
|
bolusingEvent.percent = 100;
|
||||||
|
MainApp.bus().post(bolusingEvent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
}
|
}
|
||||||
|
@ -597,20 +605,21 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
synchronized ($bolusLock) {
|
try {
|
||||||
try {
|
synchronized ($bolusLock) {
|
||||||
alertService.ignore(AlertType.WARNING_38);
|
alertService.ignore(AlertType.WARNING_38);
|
||||||
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
|
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
|
||||||
cancelBolusMessage.setBolusID(bolusID);
|
cancelBolusMessage.setBolusID(bolusID);
|
||||||
connectionService.requestMessage(cancelBolusMessage).await();
|
connectionService.requestMessage(cancelBolusMessage).await();
|
||||||
confirmAlert(AlertType.WARNING_38);
|
bolusCancelled = true;
|
||||||
} catch (AppLayerErrorException e) {
|
|
||||||
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
|
||||||
} catch (InsightException e) {
|
|
||||||
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Exception while canceling bolus", e);
|
|
||||||
}
|
}
|
||||||
|
confirmAlert(AlertType.WARNING_38);
|
||||||
|
} catch (AppLayerErrorException e) {
|
||||||
|
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
|
} catch (InsightException e) {
|
||||||
|
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exception while canceling bolus", e);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1133,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
Collections.reverse(temporaryBasals);
|
Collections.reverse(temporaryBasals);
|
||||||
for (InsightPumpID pumpID : pumpStartedEvents) {
|
for (InsightPumpID pumpID : pumpStartedEvents) {
|
||||||
InsightPumpID stoppedEvent = MainApp.getDbHelper().getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
|
InsightPumpID stoppedEvent = MainApp.getDbHelper().getPumpStoppedEvent(pumpID.pumpSerial, pumpID.timestamp);
|
||||||
if (stoppedEvent == null) continue;
|
if (stoppedEvent == null || stoppedEvent.eventType.equals("PumpPaused")) continue;
|
||||||
long tbrStart = stoppedEvent.timestamp + 10000;
|
long tbrStart = stoppedEvent.timestamp + 10000;
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
||||||
temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000);
|
temporaryBasal.durationInMinutes = (int) ((pumpID.timestamp - tbrStart) / 60000);
|
||||||
|
@ -1224,22 +1233,22 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
switch (event.getNewValue()) {
|
switch (event.getNewValue()) {
|
||||||
case STARTED:
|
case STARTED:
|
||||||
pumpID.eventType = "PumpStarted";
|
pumpID.eventType = "PumpStarted";
|
||||||
MainApp.getDbHelper().createOrUpdate(pumpID);
|
|
||||||
pumpStartedEvents.add(pumpID);
|
pumpStartedEvents.add(pumpID);
|
||||||
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
logNote(timestamp, MainApp.gs(R.string.pump_started));
|
logNote(timestamp, MainApp.gs(R.string.pump_started));
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
|
pumpID.eventType = "PumpStopped";
|
||||||
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
pumpID.eventType = "PumpStopped";
|
logNote(timestamp, MainApp.gs(R.string.pump_stopped));
|
||||||
MainApp.getDbHelper().createOrUpdate(pumpID);
|
|
||||||
logNote(timestamp, MainApp.gs(R.string.pump_stopped));
|
|
||||||
break;
|
break;
|
||||||
case PAUSED:
|
case PAUSED:
|
||||||
|
pumpID.eventType = "PumpPaused";
|
||||||
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
if (SP.getBoolean("insight_log_operating_mode_changes", false))
|
||||||
logNote(timestamp, MainApp.gs(R.string.pump_paused));
|
logNote(timestamp, MainApp.gs(R.string.pump_paused));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
MainApp.getDbHelper().createOrUpdate(pumpID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processStartOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, StartOfTBREvent event) {
|
private void processStartOfTBREvent(String serial, List<TemporaryBasal> temporaryBasals, StartOfTBREvent event) {
|
||||||
|
|
Loading…
Reference in a new issue