More steps towards reducing comms amount.

(cherry picked from commit 3ba6079)
This commit is contained in:
Johannes Mockenhaupt 2017-12-03 21:33:42 +01:00
parent 471c813bb4
commit fe40ebd4a5
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 14 additions and 26 deletions

View file

@ -155,7 +155,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
lastConnectionView.setTextColor(Color.WHITE); lastConnectionView.setTextColor(Color.WHITE);
} }
/* trigger pump bug /* triggers pump bug
// last bolus // last bolus
Bolus bolus = plugin.getPump().lastBolus; Bolus bolus = plugin.getPump().lastBolus;
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {

View file

@ -531,8 +531,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
detailedBolusInfo.date = lastPumpBolus.timestamp; detailedBolusInfo.date = lastPumpBolus.timestamp;
detailedBolusInfo.insulin = lastPumpBolus.amount; detailedBolusInfo.insulin = lastPumpBolus.amount;
detailedBolusInfo.date = lastPumpBolus.timestamp; detailedBolusInfo.date = lastPumpBolus.timestamp;
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.USER;
detailedBolusInfo.pumpId = lastPumpBolus.timestamp;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
return new PumpEnactResult().success(true).enacted(true) return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(lastPumpBolus.amount).carbsDelivered(detailedBolusInfo.carbs); .bolusDelivered(lastPumpBolus.amount).carbsDelivered(detailedBolusInfo.carbs);
@ -623,7 +622,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
tempStart.durationInMinutes = durationInMinutes; tempStart.durationInMinutes = durationInMinutes;
tempStart.percentRate = adjustedPercent; tempStart.percentRate = adjustedPercent;
tempStart.isAbsolute = false; tempStart.isAbsolute = false;
tempStart.source = Source.PUMP; tempStart.source = Source.USER;
// TODO this might be rubbish, test will show
// fake pumpId, so this can be identified on cancellation
tempStart.pumpId = tempStart.date; tempStart.pumpId = tempStart.date;
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder(); ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
treatmentsInterface.addToHistoryTempBasal(tempStart); treatmentsInterface.addToHistoryTempBasal(tempStart);
@ -644,10 +645,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public PumpEnactResult cancelTempBasal(boolean userRequested) { public PumpEnactResult cancelTempBasal(boolean userRequested) {
log.debug("cancelTempBasal called"); log.debug("cancelTempBasal called");
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
// TODO verify this; should probably still do the call since there can be a mismatch
if (activeTemp == null) {
return new PumpEnactResult().success(false).enacted(false);
}
if (userRequested) { if (userRequested) {
log.debug("cancelTempBasal: hard-cancelling TBR since user requested"); log.debug("cancelTempBasal: hard-cancelling TBR since user requested");
CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr); CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, ruffyScripter::cancelTbr);
@ -655,13 +652,17 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
TemporaryBasal tempBasal = new TemporaryBasal(); TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = commandResult.state.timestamp; tempBasal.date = commandResult.state.timestamp;
tempBasal.durationInMinutes = 0; tempBasal.durationInMinutes = 0;
tempBasal.source = Source.PUMP; tempBasal.source = Source.USER;
// not really the pumpId, but we need to use the same value here as used with
// starting the TBR we're cancelling here
tempBasal.pumpId = activeTemp.pumpId; tempBasal.pumpId = activeTemp.pumpId;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal); MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult().isTempCancel(true).success(true).enacted(true); return new PumpEnactResult().isTempCancel(true).success(true).enacted(true);
} else { } else {
return new PumpEnactResult().success(false).enacted(false); return new PumpEnactResult().success(false).enacted(false);
} }
} else if (activeTemp == null) {
return new PumpEnactResult().success(false).enacted(false);
} else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15) { } else if ((activeTemp.percentRate >= 90 && activeTemp.percentRate <= 110) && activeTemp.getPlannedRemainingMinutes() <= 15) {
// Let fake neutral temp keep run (see below) // Let fake neutral temp keep run (see below)
log.debug("cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins."); log.debug("cancelTempBasal: skipping changing tbr since it already is at " + activeTemp.percentRate + "% and running for another " + activeTemp.getPlannedRemainingMinutes() + " mins.");
@ -670,27 +671,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
+ activeTemp.percentRate + "% and running for another " + activeTemp.percentRate + "% and running for another "
+ activeTemp.getPlannedRemainingMinutes() + " mins."); + activeTemp.getPlannedRemainingMinutes() + " mins.");
} else { } else {
// TODO just call this.setTempBasal? code duplication
// Set a fake neutral temp to avoid TBR cancel alert. Decide 90% vs 110% based on // Set a fake neutral temp to avoid TBR cancel alert. Decide 90% vs 110% based on
// on whether the TBR we're cancelling is above or below 100%. // on whether the TBR we're cancelling is above or below 100%.
final int percentage = (activeTemp.percentRate > 100) ? 110 : 90; final int percentage = (activeTemp.percentRate > 100) ? 110 : 90;
log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins."); log.debug("cancelTempBasal: changing TBR to " + percentage + "% for 15 mins.");
CommandResult commandResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_cancelling_tbr), 2, () -> ruffyScripter.setTbr(percentage, 15)); return setTempBasalPercent(percentage, 15);
if (commandResult.state.tbrActive && commandResult.state.tbrPercent == percentage
&& (commandResult.state.tbrRemainingDuration == 15 || commandResult.state.tbrRemainingDuration == 14)) {
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = System.currentTimeMillis() / (60 * 1000) * (60 * 1000);
tempBasal.durationInMinutes = 15;
tempBasal.source = Source.PUMP;
tempBasal.pumpId = tempBasal.date;
tempBasal.percentRate = percentage;
tempBasal.isAbsolute = false;
MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult().success(true).enacted(true);
} else {
return new PumpEnactResult().success(false).enacted(false);
}
} }
} }
@ -798,6 +783,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if ((Math.abs(preCheckResult.state.pumpTimeMinutesOfDay - minutesOfDayNow) > 3)) { if ((Math.abs(preCheckResult.state.pumpTimeMinutesOfDay - minutesOfDayNow) > 3)) {
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_notification_check_time_date), Notification.NORMAL); Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_notification_check_time_date), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
// setting date time isn't supported by ruffy v1, a warning is issue during connect if clock is off
// runCommand("Updating pump clock", 2, ruffyScripter::setDateAndTime); // runCommand("Updating pump clock", 2, ruffyScripter::setDateAndTime);
} }
} }
@ -849,6 +835,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* Checks the main screen to determine if TBR on pump matches app state. * Checks the main screen to determine if TBR on pump matches app state.
*/ */
private boolean checkForTbrMismatch(PumpState state) { private boolean checkForTbrMismatch(PumpState state) {
// TODO
if (1==1) return false;
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
boolean sync = false; boolean sync = false;
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) { if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {