Merge branch 'no-history-for-you' into combo-scripter-v2
* no-history-for-you: When bolusing, only read history in case of error or cancellation. Cleanups. Remove lastBolus, reservoirLevel. Use timestamp for TBR, not pump minutes. Rework checkAndResolveTbrMismatch to update from pump to AAPS only. ComboFragment: move forced history read to long-pressing the TDD button. More steps towards reducing comms amount. Don't check pump history, clean up usage of pumpHistoryLastChecked, mark stuff to disable. Remove last bolus, units display of reservoir level from Combo fragment. # Conflicts: # app/src/main/res/values/strings.xml
This commit is contained in:
commit
e7d49f2300
9 changed files with 114 additions and 170 deletions
|
@ -20,7 +20,7 @@ public class ComboAlertHistoryDialog extends DialogFragment {
|
||||||
TextView text = (TextView) layout.findViewById(R.id.combo_error_history_text);
|
TextView text = (TextView) layout.findViewById(R.id.combo_error_history_text);
|
||||||
List<PumpAlert> errors = ComboPlugin.getPlugin().getPump().errorHistory;
|
List<PumpAlert> errors = ComboPlugin.getPlugin().getPump().errorHistory;
|
||||||
if (errors.isEmpty()) {
|
if (errors.isEmpty()) {
|
||||||
text.setText(R.string.combo_empty_alert_history_note);
|
text.setText(R.string.combo_empty_history_note);
|
||||||
} else {
|
} else {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
DateFormat dateTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
DateFormat dateTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
|
|
|
@ -14,7 +14,6 @@ import android.widget.TextView;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.history.Bolus;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||||
|
@ -40,7 +39,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery);
|
batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery);
|
||||||
reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate);
|
reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate);
|
||||||
lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
|
lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
|
||||||
lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
|
//lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
|
||||||
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
|
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
|
||||||
buttonsLayout = (LinearLayout) view.findViewById(R.id.combo_buttons_layout);
|
buttonsLayout = (LinearLayout) view.findViewById(R.id.combo_buttons_layout);
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View view) {
|
public boolean onLongClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.combo_refresh:
|
case R.id.combo_tdd_history:
|
||||||
new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start();
|
new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +85,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventComboPumpUpdateGUI ev) {
|
public void onStatusEvent(final EventComboPumpUpdateGUI ignored) {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +129,15 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
}
|
}
|
||||||
|
|
||||||
// reservoir
|
// reservoir
|
||||||
int reservoirLevel = plugin.getPump().reservoirLevel;
|
|
||||||
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
|
|
||||||
if (ps.insulinState == PumpState.LOW) {
|
if (ps.insulinState == PumpState.LOW) {
|
||||||
reservoirView.setTextColor(Color.YELLOW);
|
reservoirView.setTextColor(Color.YELLOW);
|
||||||
|
reservoirView.setText(R.string.combo_reservoir_low);
|
||||||
} else if (ps.insulinState == PumpState.EMPTY) {
|
} else if (ps.insulinState == PumpState.EMPTY) {
|
||||||
reservoirView.setTextColor(Color.RED);
|
reservoirView.setTextColor(Color.RED);
|
||||||
|
reservoirView.setText(R.string.combo_reservoir_empty);
|
||||||
} else {
|
} else {
|
||||||
reservoirView.setTextColor(Color.WHITE);
|
reservoirView.setTextColor(Color.WHITE);
|
||||||
|
reservoirView.setText(R.string.combo_reservoir_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// last connection
|
// last connection
|
||||||
|
@ -154,6 +154,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
lastConnectionView.setTextColor(Color.WHITE);
|
lastConnectionView.setTextColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reading the data that would be displayed here 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()) {
|
||||||
|
@ -175,6 +176,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
} else {
|
} else {
|
||||||
lastBolusView.setText("");
|
lastBolusView.setText("");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// TBR
|
// TBR
|
||||||
String tbrStr = "";
|
String tbrStr = "";
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.BasalProfile;
|
import de.jotomo.ruffy.spi.BasalProfile;
|
||||||
import de.jotomo.ruffy.spi.BolusProgressReporter;
|
import de.jotomo.ruffy.spi.BolusProgressReporter;
|
||||||
|
@ -17,11 +16,11 @@ import de.jotomo.ruffy.spi.CommandResult;
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.PumpWarningCodes;
|
import de.jotomo.ruffy.spi.PumpWarningCodes;
|
||||||
import de.jotomo.ruffy.spi.RuffyCommands;
|
import de.jotomo.ruffy.spi.RuffyCommands;
|
||||||
|
import de.jotomo.ruffy.spi.WarningOrErrorCode;
|
||||||
import de.jotomo.ruffy.spi.history.Bolus;
|
import de.jotomo.ruffy.spi.history.Bolus;
|
||||||
import de.jotomo.ruffy.spi.history.PumpHistory;
|
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||||
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
|
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
|
||||||
import de.jotomo.ruffy.spi.history.Tbr;
|
import de.jotomo.ruffy.spi.history.Tbr;
|
||||||
import de.jotomo.ruffy.spi.WarningOrErrorCode;
|
|
||||||
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
|
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -47,7 +46,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProg
|
||||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
import static de.jotomo.ruffy.spi.BolusProgressReporter.State.FINISHED;
|
import static de.jotomo.ruffy.spi.BolusProgressReporter.State.FINISHED;
|
||||||
|
@ -241,24 +239,20 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
return PumpInterface.FAILED;
|
return PumpInterface.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* don't re-read basal profile to not trigger pump bug; setBasalProfile command checks the total at the end, which must suffice
|
||||||
CommandResult readResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_setting_basal_profile), 2,
|
CommandResult readResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_setting_basal_profile), 2,
|
||||||
ruffyScripter::readBasalProfile);
|
ruffyScripter::readBasalProfile);
|
||||||
|
*/
|
||||||
|
|
||||||
pump.basalProfile = readResult.basalProfile;
|
pump.basalProfile = requestedBasalProfile;
|
||||||
|
|
||||||
if(readResult.success && readResult.basalProfile.equals(requestedBasalProfile)){
|
//dismiss previously "FAILED" overview notifications
|
||||||
//dismiss previously "FAILED" overview notifications
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
//issue success notification
|
||||||
//issue success notification
|
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
|
||||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
return PumpInterface.SUCCESS;
|
||||||
return PumpInterface.SUCCESS;
|
|
||||||
} else {
|
|
||||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
return PumpInterface.FAILED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -322,7 +316,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult stateResult = runCommand(pump.initialized ? MainApp.sResources.getString(R.string.combo_pump_action_refreshing) : MainApp.sResources.getString(R.string.combo_pump_action_initializing),
|
CommandResult stateResult = runCommand(pump.initialized ? MainApp.sResources.getString(R.string.combo_pump_action_refreshing) : MainApp.sResources.getString(R.string.combo_pump_action_initializing),
|
||||||
1, ruffyScripter::readReservoirLevelAndLastBolus);
|
1, ruffyScripter::readPumpState);
|
||||||
if (!stateResult.success) {
|
if (!stateResult.success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -366,16 +360,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLocalData(CommandResult result) {
|
private void updateLocalData(CommandResult result) {
|
||||||
if (result.reservoirLevel != PumpState.UNKNOWN) {
|
|
||||||
pump.reservoirLevel = result.reservoirLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.lastBolus != null) {
|
|
||||||
pump.lastBolus = result.lastBolus;
|
|
||||||
} else if (result.history != null && !result.history.bolusHistory.isEmpty()) {
|
|
||||||
pump.lastBolus = result.history.bolusHistory.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.state.menu != null) {
|
if (result.state.menu != null) {
|
||||||
pump.state = result.state;
|
pump.state = result.state;
|
||||||
}
|
}
|
||||||
|
@ -466,34 +450,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
||||||
|
|
||||||
Bolus lastKnownBolus = pump.lastBolus;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
pump.activity = MainApp.sResources.getString(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
|
|
||||||
// refresh pump data
|
|
||||||
CommandResult reservoirBolusResult = runCommand(null, 3,
|
|
||||||
ruffyScripter::readReservoirLevelAndLastBolus);
|
|
||||||
if (!reservoirBolusResult.success) {
|
|
||||||
log.error("Bolus delivery failure at stage 1", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check enough insulin left for bolus
|
|
||||||
if (Math.round(detailedBolusInfo.insulin + 0.5) > reservoirBolusResult.reservoirLevel) {
|
|
||||||
log.error("Bolus delivery failure at stage 2", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_reservoir_level_insufficient_for_bolus));
|
|
||||||
}
|
|
||||||
|
|
||||||
// verify we're update to date and know the most recent bolus
|
|
||||||
if (!Objects.equals(lastKnownBolus, reservoirBolusResult.lastBolus)) {
|
|
||||||
log.error("Bolus delivery failure at stage 3", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_history_state_mismatch));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancelBolus) {
|
if (cancelBolus) {
|
||||||
return new PumpEnactResult().success(true).enacted(false);
|
return new PumpEnactResult().success(true).enacted(false);
|
||||||
}
|
}
|
||||||
|
@ -505,28 +465,29 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
||||||
bolusInProgress = false;
|
bolusInProgress = false;
|
||||||
|
|
||||||
if (!bolusCmdResult.success) {
|
if (!cancelBolus && bolusCmdResult.success) {
|
||||||
new Thread(this::checkPumpHistory).start();
|
detailedBolusInfo.date = bolusCmdResult.state.timestamp;
|
||||||
log.error("Bolus delivery failure at stage 4", new Exception());
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
|
return new PumpEnactResult().success(true).enacted(true)
|
||||||
|
.bolusDelivered(detailedBolusInfo.insulin)
|
||||||
|
.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case of error check what was actually delivered
|
||||||
|
CommandResult historyResult = runCommand(null, 1,
|
||||||
|
() -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
||||||
|
if (!historyResult.success) {
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
return new PumpEnactResult().success(false).enacted(false)
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
||||||
}
|
}
|
||||||
|
Bolus lastPumpBolus = historyResult.lastBolus;
|
||||||
// verify delivered bolus
|
|
||||||
reservoirBolusResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
|
||||||
if (!reservoirBolusResult.success) {
|
|
||||||
log.error("Bolus delivery failure at stage 5", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false)
|
|
||||||
.comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
|
||||||
}
|
|
||||||
Bolus lastPumpBolus = reservoirBolusResult.lastBolus;
|
|
||||||
if (cancelBolus) {
|
if (cancelBolus) {
|
||||||
// if cancellation was requested, the delivered bolus is allowed to differ from requested
|
// if cancellation was requested, the delivered bolus is allowed to differ from requested
|
||||||
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|
||||||
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
|
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
|
||||||
log.error("Bolus delivery failure at stage 6", new Exception());
|
|
||||||
return new PumpEnactResult().success(false).enacted(false).
|
return new PumpEnactResult().success(false).enacted(false).
|
||||||
comment(MainApp.sResources.getString(R.string.combo_pump_bolus_verification_failed));
|
comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add treatment record to DB (if it wasn't cancelled)
|
// add treatment record to DB (if it wasn't cancelled)
|
||||||
|
@ -534,8 +495,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);
|
||||||
|
@ -556,13 +516,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
|
// TODO if the pump is busy setting a TBR while a bolus was requested,
|
||||||
|
// cancelling here, when the TBR is still being set will fail to cancel the bolus.
|
||||||
|
// See if the queue might solve this, otherwise we could add a check in runCommand
|
||||||
|
// (but can't currently determine if the request is a basal request)
|
||||||
|
// or have the scripter skip the next bolus that comes in
|
||||||
if (bolusInProgress) {
|
if (bolusInProgress) {
|
||||||
ruffyScripter.cancelBolus();
|
ruffyScripter.cancelBolus();
|
||||||
}
|
}
|
||||||
cancelBolus = true;
|
cancelBolus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: AAPS calls this only to enact OpenAPS recommendations
|
// Note: AAPS calls this solely to enact OpenAPS suggestions
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {
|
||||||
// the force parameter isn't used currently since we always set the tbr - there might be room for optimization to
|
// the force parameter isn't used currently since we always set the tbr - there might be room for optimization to
|
||||||
|
@ -579,7 +544,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
return setTempBasalPercent(roundedPercentage, durationInMinutes);
|
return setTempBasalPercent(roundedPercentage, durationInMinutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: AAPS calls this only for setting a temp basal issued by the user
|
// Note: AAPS calls this directly only for setting a temp basal issued by the user
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) {
|
public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) {
|
||||||
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
|
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
|
||||||
|
@ -622,12 +587,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
if (state.tbrActive && state.tbrPercent == percent
|
if (state.tbrActive && state.tbrPercent == percent
|
||||||
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
|
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
|
||||||
TemporaryBasal tempStart = new TemporaryBasal();
|
TemporaryBasal tempStart = new TemporaryBasal();
|
||||||
tempStart.date = state.timestamp / (60 * 1000) * (60 * 1000);
|
tempStart.date = state.timestamp;
|
||||||
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;
|
||||||
tempStart.pumpId = tempStart.date;
|
|
||||||
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin treatmentsInterface = MainApp.getConfigBuilder();
|
||||||
treatmentsInterface.addToHistoryTempBasal(tempStart);
|
treatmentsInterface.addToHistoryTempBasal(tempStart);
|
||||||
|
|
||||||
|
@ -647,9 +611,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());
|
||||||
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);
|
||||||
|
@ -657,13 +618,14 @@ 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;
|
||||||
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(true).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.");
|
||||||
|
@ -676,22 +638,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,8 +662,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
if (!ruffyScripter.isConnected()) {
|
if (!ruffyScripter.isConnected()) {
|
||||||
CommandResult preCheckError = runOnConnectChecks();
|
CommandResult preCheckError = runOnConnectChecks();
|
||||||
if (preCheckError != null) {
|
if (preCheckError != null) {
|
||||||
updateLocalData(preCheckError);
|
updateLocalData(preCheckError);
|
||||||
return preCheckError;
|
return preCheckError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,9 +735,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if TBR was cancelled or set by user
|
checkAndResolveTbrMismatch(preCheckResult.state);
|
||||||
boolean mismatch = checkForTbrMismatch(preCheckResult.state);
|
|
||||||
if (mismatch) checkPumpHistory();
|
|
||||||
|
|
||||||
// raise notification if clock is off (setting clock is not supported by ruffy)
|
// raise notification if clock is off (setting clock is not supported by ruffy)
|
||||||
if (preCheckResult.state.pumpTimeMinutesOfDay != 0) {
|
if (preCheckResult.state.pumpTimeMinutesOfDay != 0) {
|
||||||
|
@ -799,6 +744,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,39 +795,42 @@ 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 void checkAndResolveTbrMismatch(PumpState state) {
|
||||||
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
boolean sync = false;
|
|
||||||
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
|
if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) {
|
||||||
log.debug("Pump runs TBR AAPS is unaware of, cancelling TBR so it can be read from history properly");
|
log.debug("Creating temp basal from pump TBR");
|
||||||
runCommand(null, 0, ruffyScripter::cancelTbr);
|
TemporaryBasal newTempBasal = new TemporaryBasal();
|
||||||
sync = true;
|
newTempBasal.date = System.currentTimeMillis();
|
||||||
|
newTempBasal.percentRate = state.tbrPercent;
|
||||||
|
newTempBasal.isAbsolute = false;
|
||||||
|
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
|
||||||
|
newTempBasal.source = Source.USER;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
|
||||||
} else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) {
|
} else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) {
|
||||||
log.debug("AAPS shows a TBR but pump isn't running a TBR; deleting TBR in AAPS and reading pump history");
|
log.debug("Ending AAPS-TBR since pump has no TBR active");
|
||||||
MainApp.getDbHelper().delete(aapsTbr);
|
TemporaryBasal tempStop = new TemporaryBasal();
|
||||||
sync = true;
|
tempStop.date = aapsTbr.date;
|
||||||
} else if (aapsTbr != null && state.tbrActive) {
|
tempStop.durationInMinutes = 0;
|
||||||
// both AAPS and pump have an active TBR ...
|
tempStop.source = Source.USER;
|
||||||
if (aapsTbr.percentRate != state.tbrPercent) {
|
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
|
||||||
// ... but they have different percentages
|
} else if (aapsTbr != null && state.tbrActive
|
||||||
log.debug("TBR percentage differs between AAPS and pump; deleting TBR in AAPS and reading pump history");
|
&& (aapsTbr.percentRate != state.tbrPercent ||
|
||||||
MainApp.getDbHelper().delete(aapsTbr);
|
Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration) > 2)) {
|
||||||
sync = true;
|
log.debug("AAPSs and pump-TBR differ; Ending AAPS-TBR and creating new TBR based on pump TBR");
|
||||||
}
|
TemporaryBasal tempStop = new TemporaryBasal();
|
||||||
int durationDiff = Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration);
|
tempStop.date = aapsTbr.date;
|
||||||
if (durationDiff > 2) {
|
tempStop.durationInMinutes = 0;
|
||||||
// ... but they have different runtimes
|
tempStop.source = Source.USER;
|
||||||
log.debug("TBR duration differs between AAPS and pump; deleting TBR in AAPS and reading pump history");
|
MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop);
|
||||||
MainApp.getDbHelper().delete(aapsTbr);
|
|
||||||
sync = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sync) {
|
TemporaryBasal newTempBasal = new TemporaryBasal();
|
||||||
log.debug("Sync requested from checkTbrMismatch");
|
newTempBasal.date = System.currentTimeMillis();
|
||||||
|
newTempBasal.percentRate = state.tbrPercent;
|
||||||
|
newTempBasal.isAbsolute = false;
|
||||||
|
newTempBasal.durationInMinutes = state.tbrRemainingDuration;
|
||||||
|
newTempBasal.source = Source.USER;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sync;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -889,6 +838,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
* read to get the DB up to date.
|
* read to get the DB up to date.
|
||||||
*/
|
*/
|
||||||
private synchronized boolean checkPumpHistory() {
|
private synchronized boolean checkPumpHistory() {
|
||||||
|
return true;
|
||||||
|
|
||||||
|
/* reading history triggers pump bug
|
||||||
// set here, rather at the end so that if this runs into an error it's not tried
|
// set here, rather at the end so that if this runs into an error it's not tried
|
||||||
// over and over since it's called at the end of runCommand
|
// over and over since it's called at the end of runCommand
|
||||||
pumpHistoryLastChecked = System.currentTimeMillis();
|
pumpHistoryLastChecked = System.currentTimeMillis();
|
||||||
|
@ -956,10 +908,14 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the pump's history and updates the DB accordingly.
|
* Reads the pump's history and updates the DB accordingly.
|
||||||
|
*
|
||||||
|
* Only ever called by #readAllPumpData which is triggered by the user via the combo fragment
|
||||||
|
* which warns the user against doing this.
|
||||||
*/
|
*/
|
||||||
private boolean readHistory(final PumpHistoryRequest request) {
|
private boolean readHistory(final PumpHistoryRequest request) {
|
||||||
CommandResult historyResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(request));
|
CommandResult historyResult = runCommand(MainApp.sResources.getString(R.string.combo_activity_reading_pump_history), 3, () -> ruffyScripter.readHistory(request));
|
||||||
|
@ -967,15 +923,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update local cache
|
|
||||||
PumpHistory history = historyResult.history;
|
PumpHistory history = historyResult.history;
|
||||||
if (!history.bolusHistory.isEmpty()) {
|
updateDbFromPumpHistory(history);
|
||||||
pump.lastHistoryBolusTime = history.bolusHistory.get(0).timestamp;
|
|
||||||
}
|
|
||||||
if (!history.tbrHistory.isEmpty()) {
|
|
||||||
pump.lastHistoryTbrTime = history.tbrHistory.get(0).timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// update local cache
|
||||||
if (!history.pumpAlertHistory.isEmpty()) {
|
if (!history.pumpAlertHistory.isEmpty()) {
|
||||||
pump.errorHistory = history.pumpAlertHistory;
|
pump.errorHistory = history.pumpAlertHistory;
|
||||||
}
|
}
|
||||||
|
@ -983,8 +934,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
pump.tddHistory = history.tddHistory;
|
pump.tddHistory = history.tddHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDbFromPumpHistory(history);
|
|
||||||
|
|
||||||
return historyResult.success;
|
return historyResult.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,20 +972,26 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
void readAllPumpData() {
|
void readAllPumpData() {
|
||||||
|
long lastCheckInitiated = System.currentTimeMillis();
|
||||||
|
|
||||||
boolean readHistorySuccess = readHistory(new PumpHistoryRequest()
|
boolean readHistorySuccess = readHistory(new PumpHistoryRequest()
|
||||||
.bolusHistory(pump.lastHistoryBolusTime)
|
.bolusHistory(pumpHistoryLastChecked)
|
||||||
.tbrHistory(pump.lastHistoryTbrTime)
|
.tbrHistory(pumpHistoryLastChecked)
|
||||||
.pumpErrorHistory(PumpHistoryRequest.FULL)
|
.pumpErrorHistory(PumpHistoryRequest.FULL)
|
||||||
.tddHistory(PumpHistoryRequest.FULL));
|
.tddHistory(PumpHistoryRequest.FULL));
|
||||||
if (!readHistorySuccess) {
|
if (!readHistorySuccess) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pumpHistoryLastChecked = lastCheckInitiated;
|
||||||
|
|
||||||
|
/* not displayed in the UI anymore due to pump bug
|
||||||
CommandResult reservoirResult = runCommand("Checking reservoir level", 2,
|
CommandResult reservoirResult = runCommand("Checking reservoir level", 2,
|
||||||
ruffyScripter::readReservoirLevelAndLastBolus);
|
ruffyScripter::readReservoirLevelAndLastBolus);
|
||||||
if (!reservoirResult.success) {
|
if (!reservoirResult.success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
CommandResult basalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
CommandResult basalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
||||||
if (!basalResult.success) {
|
if (!basalResult.success) {
|
||||||
|
@ -1060,7 +1015,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
try {
|
try {
|
||||||
JSONObject pumpJson = new JSONObject();
|
JSONObject pumpJson = new JSONObject();
|
||||||
pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime));
|
pumpJson.put("clock", DateUtil.toISOString(pump.lastSuccessfulCmdTime));
|
||||||
pumpJson.put("reservoir", pump.reservoirLevel);
|
// TODO can we upload empty/low/normal or is a int expected? If so, use fake numbers like 0/50/200
|
||||||
|
// pumpJson.put("reservoir", pump.reservoirState);
|
||||||
|
|
||||||
JSONObject statusJson = new JSONObject();
|
JSONObject statusJson = new JSONObject();
|
||||||
statusJson.put("status", getStateSummary());
|
statusJson.put("status", getStateSummary());
|
||||||
|
@ -1070,10 +1026,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
JSONObject extendedJson = new JSONObject();
|
JSONObject extendedJson = new JSONObject();
|
||||||
extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
|
||||||
extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
|
||||||
if (pump.lastBolus != null) {
|
|
||||||
extendedJson.put("LastBolus", new Date(pump.lastBolus.timestamp).toLocaleString());
|
|
||||||
extendedJson.put("LastBolusAmount", DecimalFormatter.to1Decimal(pump.lastBolus.amount));
|
|
||||||
}
|
|
||||||
PumpState ps = pump.state;
|
PumpState ps = pump.state;
|
||||||
if (ps.tbrActive) {
|
if (ps.tbrActive) {
|
||||||
extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate);
|
extendedJson.put("TempBasalAbsoluteRate", ps.tbrRate);
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo;
|
package info.nightscout.androidaps.plugins.PumpCombo;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.BasalProfile;
|
import de.jotomo.ruffy.spi.BasalProfile;
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.history.Bolus;
|
|
||||||
import de.jotomo.ruffy.spi.history.PumpAlert;
|
import de.jotomo.ruffy.spi.history.PumpAlert;
|
||||||
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
|
|
||||||
import de.jotomo.ruffy.spi.history.Tdd;
|
import de.jotomo.ruffy.spi.history.Tdd;
|
||||||
|
|
||||||
class ComboPump {
|
class ComboPump {
|
||||||
|
@ -21,15 +17,9 @@ class ComboPump {
|
||||||
public volatile String activity;
|
public volatile String activity;
|
||||||
@NonNull
|
@NonNull
|
||||||
volatile PumpState state = new PumpState();
|
volatile PumpState state = new PumpState();
|
||||||
volatile int reservoirLevel = -1;
|
|
||||||
volatile Bolus lastBolus = null;
|
|
||||||
@NonNull
|
@NonNull
|
||||||
volatile BasalProfile basalProfile = new BasalProfile();
|
volatile BasalProfile basalProfile = new BasalProfile();
|
||||||
|
|
||||||
// Last known history record times to skip over old ones when reading history
|
|
||||||
long lastHistoryBolusTime = PumpHistoryRequest.FULL;
|
|
||||||
long lastHistoryTbrTime = PumpHistoryRequest.FULL;
|
|
||||||
|
|
||||||
// Alert and TDD histories are not stored in DB, but are read on demand and just cached here
|
// Alert and TDD histories are not stored in DB, but are read on demand and just cached here
|
||||||
List<PumpAlert> errorHistory = new ArrayList<>(0);
|
List<PumpAlert> errorHistory = new ArrayList<>(0);
|
||||||
List<Tdd> tddHistory = new ArrayList<>(0);
|
List<Tdd> tddHistory = new ArrayList<>(0);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class ComboTddHistoryDialog extends DialogFragment {
|
||||||
TextView text = (TextView) layout.findViewById(R.id.combo_tdd_history_text);
|
TextView text = (TextView) layout.findViewById(R.id.combo_tdd_history_text);
|
||||||
List<Tdd> tdds = ComboPlugin.getPlugin().getPump().tddHistory;
|
List<Tdd> tdds = ComboPlugin.getPlugin().getPump().tddHistory;
|
||||||
if (tdds.isEmpty()) {
|
if (tdds.isEmpty()) {
|
||||||
text.setText(R.string.combo_empty_tdd_history_note);
|
text.setText(R.string.combo_empty_history_note);
|
||||||
} else {
|
} else {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
DateFormat dateFormatter = DateFormat.getDateInstance();
|
DateFormat dateFormatter = DateFormat.getDateInstance();
|
||||||
|
|
|
@ -236,6 +236,7 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- reading last bolus from pump triggers pump bug
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="2dip"
|
android:layout_height="2dip"
|
||||||
|
@ -280,6 +281,7 @@
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
-->
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
|
|
@ -811,11 +811,8 @@
|
||||||
<string name="key_raise_urgent_alarms_as_android_notification" translatable="false">raise_urgent_alarms_as_android_notification</string>
|
<string name="key_raise_urgent_alarms_as_android_notification" translatable="false">raise_urgent_alarms_as_android_notification</string>
|
||||||
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
||||||
<string name="combo_pump_never_connected">Never</string>
|
<string name="combo_pump_never_connected">Never</string>
|
||||||
<string name="combo_reservoir_level_insufficient_for_bolus">Not enough insulin left in reservoir for bolus</string>
|
|
||||||
<string name="combo_pump_bolus_history_state_mismatch">A bolus has been delivered directly on the pump recently, of which AndroidAPS has only just become aware of. The pump\'s history is currently being read. Please check the Combo page, verify the last bolus and IOB and bolus again if needed. No bolus has been delivered.</string>
|
|
||||||
<string name="combo_pump_bolus_verification_failed">Bolus delivery verification failed. The pump history will be read again on the next loop run or when refreshing from the Combo page. Please check and bolus again if needed.</string>
|
|
||||||
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
|
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
|
||||||
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please check the Combo page and bolus again as needed.</string>
|
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please the pump and treatments tabs and bolus again as needed.</string>
|
||||||
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
|
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
|
||||||
<string name="combo_notification_check_time_date">Check pump time and date</string>
|
<string name="combo_notification_check_time_date">Check pump time and date</string>
|
||||||
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
|
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
|
||||||
|
@ -827,11 +824,13 @@
|
||||||
<string name="combo_pump_cartridge_low_warrning">Pump cartridge level is low</string>
|
<string name="combo_pump_cartridge_low_warrning">Pump cartridge level is low</string>
|
||||||
<string name="combo_pump_battery_low_warrning">Pump battery is low</string>
|
<string name="combo_pump_battery_low_warrning">Pump battery is low</string>
|
||||||
<string name="combo_is_in_error_state">Pump is in an error state, please check the pump</string>
|
<string name="combo_is_in_error_state">Pump is in an error state, please check the pump</string>
|
||||||
<string name="combo_empty_alert_history_note">To retrieve the alert history from the pump, long press the Refresh button.</string>
|
<string name="combo_empty_history_note">To read all data from the pump, long press the Stats button.\n\nWARNING: this can trigger a bug which causes the pump to reject all connection attempts and requires pressing a button on the pump to recover and should therefore be avoided.</string>
|
||||||
<string name="combo_empty_tdd_history_note">To retrieve the TDD history from the pump, long press the Refresh button.</string>
|
|
||||||
<string name="key_sync_profile_to_pump">sync_profile_to_pump</string>
|
<string name="key_sync_profile_to_pump">sync_profile_to_pump</string>
|
||||||
<string name="combo_tdd_minimum">Minimum: %3.1f U</string>
|
<string name="combo_tdd_minimum">Minimum: %3.1f U</string>
|
||||||
<string name="combo_tdd_average">Average: %3.1f U</string>
|
<string name="combo_tdd_average">Average: %3.1f U</string>
|
||||||
<string name="combo_tdd_maximum">Maximum: %3.1f U</string>
|
<string name="combo_tdd_maximum">Maximum: %3.1f U</string>
|
||||||
|
<string name="combo_reservoir_low">Low</string>
|
||||||
|
<string name="combo_reservoir_empty">Empty</string>
|
||||||
|
<string name="combo_reservoir_normal">Normal</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package de.jotomo.ruffy.spi;
|
||||||
|
|
||||||
/** State displayed on the main screen of the pump. */
|
/** State displayed on the main screen of the pump. */
|
||||||
public class PumpState {
|
public class PumpState {
|
||||||
/** Time the state was captured, rounded to a full second */
|
/** Time the state was captured. This is NOT the pump's time! */
|
||||||
public long timestamp;
|
public long timestamp;
|
||||||
/** The time displayed on the main menu */
|
/** The time displayed on the main menu */
|
||||||
public long pumpTimeMinutesOfDay;
|
public long pumpTimeMinutesOfDay;
|
||||||
|
|
|
@ -499,8 +499,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
*/
|
*/
|
||||||
public PumpState readPumpStateInternal() {
|
public PumpState readPumpStateInternal() {
|
||||||
PumpState state = new PumpState();
|
PumpState state = new PumpState();
|
||||||
// round timestamp to full second
|
state.timestamp = System.currentTimeMillis();
|
||||||
state.timestamp = System.currentTimeMillis() / (60 * 1000) * (60 * 1000);
|
|
||||||
Menu menu = currentMenu;
|
Menu menu = currentMenu;
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in a new issue