diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index b580dc9b38..3f911aaceb 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -17,6 +17,8 @@ import info.nightscout.client.data.NSProfile; public interface PumpInterface { boolean isInitialized(); + boolean isSuspended(); + boolean isBusy(); boolean isTempBasalInProgress(); boolean isExtendedBoluslInProgress(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index e7a8bb2efc..c3ea14dc79 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -94,19 +94,19 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) extendedBolus.setVisibility(View.GONE); else extendedBolus.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) tempBasal.setVisibility(View.GONE); else tempBasal.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized()) + if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) fill.setVisibility(View.GONE); else fill.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index aceaaee07e..bb4513b069 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -481,7 +481,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 1a21fb9dd6..74fac9d584 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -18,6 +18,10 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -73,7 +77,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain static ArrayList pluginList; - static Date lastDeviceStatusUpload = new Date(0); + private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); + private static ScheduledFuture scheduledPost = null; PowerManager.WakeLock mWakeLock; @@ -334,6 +339,16 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return activePump.isInitialized(); } + @Override + public boolean isSuspended() { + return activePump.isSuspended(); + } + + @Override + public boolean isBusy() { + return activePump.isBusy(); + } + @Override public boolean isTempBasalInProgress() { return activePump.isTempBasalInProgress(); @@ -596,6 +611,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain result.comment = MainApp.sResources.getString(R.string.pumpNotInitialized); result.enacted = false; result.success = false; + log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized)); + return result; + } + + if (isSuspended()) { + result = new PumpEnactResult(); + result.comment = MainApp.sResources.getString(R.string.pumpsuspended); + result.enacted = false; + result.success = false; + log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended)); + return result; } if (Config.logCongigBuilderActions) @@ -780,22 +806,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain @Subscribe public void onStatusEvent(final EventNewBG ev) { - Thread t = new Thread(new Runnable() { - @Override - public void run() { - // Give some time to Loop - try { - Thread.sleep(120 * 1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - // if status not uploaded, upload pump status only - if (new Date().getTime() - lastDeviceStatusUpload.getTime() > 120 * 1000L) { - uploadDeviceStatus(); - } - } - }); - t.start(); + uploadDeviceStatus(120); } public void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) { @@ -901,7 +912,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } } - public void uploadDeviceStatus() { + public void doUploadDeviceStatus() { DeviceStatus deviceStatus = new DeviceStatus(); try { LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; @@ -942,13 +953,28 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain deviceStatus.created_at = DateUtil.toISOString(new Date()); deviceStatus.sendToNSClient(); - lastDeviceStatusUpload = new Date(); } } catch (JSONException e) { e.printStackTrace(); } } + static public void uploadDeviceStatus(int sec) { + class PostRunnable implements Runnable { + public void run() { + MainApp.getConfigBuilder().doUploadDeviceStatus(); + scheduledPost = null; + } + } + // prepare task for execution + // cancel waiting task to prevent sending multiple posts + if (scheduledPost != null) + scheduledPost.cancel(false); + Runnable task = new PostRunnable(); + scheduledPost = worker.schedule(task, sec, TimeUnit.SECONDS); + log.debug("Scheduling devicestatus upload in " + sec + " sec"); + } + public void uploadBolusWizardRecord(Treatment t, double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { JSONObject data = new JSONObject(); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 4af029b558..17a6944071 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -211,6 +211,17 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled; } + @Override + public boolean isSuspended() { + return getDanaRPump().pumpSuspended; + } + + @Override + public boolean isBusy() { + if (sExecutionService == null) return false; + return sExecutionService.isConnected() || sExecutionService.isConnecting(); + } + // Pump interface @Override public boolean isTempBasalInProgress() { @@ -705,7 +716,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf JSONObject extended = new JSONObject(); try { battery.put("percent", getDanaRPump().batteryRemaining); - status.put("status", "normal"); + status.put("status", getDanaRPump().pumpSuspended ? "suspended" : "normal"); status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection)); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("PumpIOB", getDanaRPump().iob); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index 5ce5fafdae..5f0ac7a0ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -276,6 +276,7 @@ public class ExecutionService extends Service { private boolean getPumpStatus() { try { + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus))); MsgStatus statusMsg = new MsgStatus(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); @@ -336,6 +337,7 @@ public class ExecutionService extends Service { danaRPump.lastConnection = now; MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); + MainApp.getConfigBuilder().uploadDeviceStatus(60); } catch (Exception e) { e.printStackTrace(); } @@ -345,30 +347,37 @@ public class ExecutionService extends Service { public boolean tempBasal(int percent, int durationInHours) { connect("tempBasal"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean tempBasalStop() { connect("tempBasalStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolus(double insulin, int durationInHalfHours) { connect("extendedBolus"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolusStop() { connect("extendedBolusStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); return true; @@ -482,6 +491,7 @@ public class ExecutionService extends Service { public boolean updateBasalsInPump(final NSProfile profile) { connect("updateBasalsInPump"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates))); double[] basal = buildDanaRProfileRecord(profile); MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal); mSerialIOThread.sendMessage(msgSet); @@ -489,6 +499,7 @@ public class ExecutionService extends Service { mSerialIOThread.sendMessage(msgActivate); danaRPump.lastSettingsRead = new Date(0); // force read full settings getPumpStatus(); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java index a74529416a..fef8868d2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/events/EventDanaRConnectionStatus.java @@ -4,12 +4,20 @@ public class EventDanaRConnectionStatus { public static final int CONNECTING = 0; public static final int CONNECTED = 1; public static final int DISCONNECTED = 2; + public static final int PERFORMING = 3; public int sStatus = DISCONNECTED; public int sSecondsElapsed = 0; + public String sAction = ""; public EventDanaRConnectionStatus(int status, int secondsElapsed) { sStatus = status; sSecondsElapsed = secondsElapsed; } + + public EventDanaRConnectionStatus(int status, int secondsElapsed, String action) { + sStatus = status; + sSecondsElapsed = secondsElapsed; + sAction = action; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java index 5c12ab3000..b1057b879a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java @@ -211,6 +211,17 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints return getDanaRPump().lastConnection.getTime() > 0 && !getDanaRPump().isConfigUD && !getDanaRPump().isEasyModeEnabled && getDanaRPump().isExtendedBolusEnabled; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + if (sExecutionService == null) return false; + return sExecutionService.isConnected() || sExecutionService.isConnecting(); + } + // Pump interface @Override public boolean isTempBasalInProgress() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java index bcd49e3d7e..e88cee105f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/Services/ExecutionService.java @@ -272,6 +272,7 @@ public class ExecutionService extends Service { private boolean getPumpStatus() { try { + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus))); //MsgStatus statusMsg = new MsgStatus(); MsgStatusBasic statusBasicMsg = new MsgStatusBasic(); MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(); @@ -330,6 +331,7 @@ public class ExecutionService extends Service { danaRKoreanPump.lastConnection = now; MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); + MainApp.getConfigBuilder().uploadDeviceStatus(60); } catch (Exception e) { e.printStackTrace(); } @@ -339,32 +341,40 @@ public class ExecutionService extends Service { public boolean tempBasal(int percent, int durationInHours) { connect("tempBasal"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean tempBasalStop() { connect("tempBasalStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal))); mSerialIOThread.sendMessage(new MsgSetTempBasalStop()); mSerialIOThread.sendMessage(new MsgStatusTempBasal()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolus(double insulin, int durationInHalfHours) { connect("extendedBolus"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF))); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } public boolean extendedBolusStop() { connect("extendedBolusStop"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus))); mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop()); mSerialIOThread.sendMessage(new MsgStatusBolusExtended()); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } @@ -476,11 +486,13 @@ public class ExecutionService extends Service { public boolean updateBasalsInPump(final NSProfile profile) { connect("updateBasalsInPump"); if (!isConnected()) return false; + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates))); double[] basal = buildDanaRProfileRecord(profile); MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal); mSerialIOThread.sendMessage(msgSet); danaRKoreanPump.lastSettingsRead = new Date(0); // force read full settings getPumpStatus(); + MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting))); return true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java index 6000cfddaa..552a05cc28 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LocalProfile/LocalProfileFragment.java @@ -156,7 +156,7 @@ public class LocalProfileFragment extends Fragment implements FragmentBase { activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index a357d519b9..ea7e256f4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -228,7 +228,7 @@ public class LoopPlugin implements PluginBase { } MainApp.bus().post(new EventLoopUpdateGui()); - MainApp.getConfigBuilder().uploadDeviceStatus(); + MainApp.getConfigBuilder().uploadDeviceStatus(15); } finally { if (Config.logFunctionCalls) log.debug("invoke end"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java index cc63428349..835de2b7e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/MDI/MDIPlugin.java @@ -115,6 +115,16 @@ public class MDIPlugin implements PluginBase, PumpInterface { return true; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + return false; + } + @Override public boolean isTempBasalInProgress() { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index ef15ac04c1..198468bc0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -71,6 +71,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin; @@ -116,7 +117,7 @@ public class OverviewFragment extends Fragment { TextView iobView; TextView apsModeView; TextView tempTargetView; - TextView initializingView; + TextView pumpStatusView; GraphView bgGraph; CheckBox showPredictionView; @@ -162,7 +163,7 @@ public class OverviewFragment extends Fragment { baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal); basalLayout = (LinearLayout) view.findViewById(R.id.overview_basallayout); activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile); - initializingView = (TextView) view.findViewById(R.id.overview_initializing); + pumpStatusView = (TextView) view.findViewById(R.id.overview_initializing); iobView = (TextView) view.findViewById(R.id.overview_iob); apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); @@ -268,7 +269,7 @@ public class OverviewFragment extends Fragment { finalLastRun.setByPump = applyResult; finalLastRun.lastEnact = new Date(); finalLastRun.lastOpenModeAccept = new Date(); - MainApp.getConfigBuilder().uploadDeviceStatus(); + MainApp.getConfigBuilder().uploadDeviceStatus(15); ObjectivesPlugin objectivesPlugin = (ObjectivesPlugin) MainApp.getSpecificPlugin(ObjectivesPlugin.class); if (objectivesPlugin != null) { objectivesPlugin.manualEnacts++; @@ -287,6 +288,19 @@ public class OverviewFragment extends Fragment { } }); + pumpStatusView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized()) + sHandler.post(new Runnable() { + @Override + public void run() { + MainApp.getConfigBuilder().updateStatus("RefreshClicked"); + } + }); + } + }); + updateGUI(); return view; } @@ -443,16 +457,41 @@ public class OverviewFragment extends Fragment { } @Subscribe - public void onStatusEvent(final EventNewBasalProfile ev) { updateGUIIfVisible(); } + public void onStatusEvent(final EventNewBasalProfile ev) { + updateGUIIfVisible(); + } @Subscribe - public void onStatusEvent(final EventTempTargetRangeChange ev) {updateGUIIfVisible();} + public void onStatusEvent(final EventTempTargetRangeChange ev) { + updateGUIIfVisible(); + } @Subscribe - public void onStatusEvent(final EventNewNotification n) { updateNotifications(); } + public void onStatusEvent(final EventNewNotification n) { + updateNotifications(); + } @Subscribe - public void onStatusEvent(final EventDismissNotification n) { updateNotifications(); } + public void onStatusEvent(final EventDismissNotification n) { + updateNotifications(); + } + + @Subscribe + public void onStatusEvent(final EventDanaRConnectionStatus s) { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (s.sStatus == EventDanaRConnectionStatus.CONNECTING) + updatePumpStatus(String.format(getString(R.string.danar_history_connectingfor), s.sSecondsElapsed)); + else if (s.sStatus == EventDanaRConnectionStatus.PERFORMING) + updatePumpStatus(s.sAction); + else if (s.sStatus == EventDanaRConnectionStatus.DISCONNECTED) + updatePumpStatus(null); + } + }); + } private void hideTempRecommendation() { Activity activity = getActivity(); @@ -476,6 +515,35 @@ public class OverviewFragment extends Fragment { }); } + private void updatePumpStatus(String status) { + PumpInterface pump = MainApp.getConfigBuilder(); + if (status != null) { + pumpStatusView.setText(status); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (pump.isBusy()) { + pumpStatusView.setText(R.string.pumpbusy); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (pump.isSuspended()) { + // disable all treatment buttons because we are not able to check constraints without profile + wizardButton.setVisibility(View.INVISIBLE); + treatmentButton.setVisibility(View.INVISIBLE); + quickWizardButton.setVisibility(View.INVISIBLE); + pumpStatusView.setText(R.string.pumpsuspendedclicktorefresh); + pumpStatusView.setVisibility(View.VISIBLE); + } else if (!pump.isInitialized()) { + // disable all treatment buttons because we are not able to check constraints without profile + wizardButton.setVisibility(View.INVISIBLE); + treatmentButton.setVisibility(View.INVISIBLE); + quickWizardButton.setVisibility(View.INVISIBLE); + pumpStatusView.setText(R.string.waitingforpump); + pumpStatusView.setVisibility(View.VISIBLE); + } else { + wizardButton.setVisibility(View.VISIBLE); + treatmentButton.setVisibility(View.VISIBLE); + pumpStatusView.setVisibility(View.GONE); + } + } + @SuppressLint("SetTextI18n") public void updateGUI() { updateNotifications(); @@ -483,11 +551,11 @@ public class OverviewFragment extends Fragment { BgReading lastBG = GlucoseStatus.lastBg(); if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null || MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet - initializingView.setText(R.string.noprofileset); - initializingView.setVisibility(View.VISIBLE); + pumpStatusView.setText(R.string.noprofileset); + pumpStatusView.setVisibility(View.VISIBLE); return; } else { - initializingView.setVisibility(View.GONE); + pumpStatusView.setVisibility(View.GONE); } // Skip if not initialized yet @@ -504,7 +572,7 @@ public class OverviewFragment extends Fragment { apsModeView.setBackgroundResource(R.drawable.loopmodeborder); apsModeView.setTextColor(Color.BLACK); final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); - if(activeloop != null && activeloop.isEnabled(activeloop.getType())) { + if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { if (MainApp.getConfigBuilder().isClosedModeEnabled()) { apsModeView.setText(MainApp.sResources.getString(R.string.closedloop)); } else { @@ -522,10 +590,10 @@ public class OverviewFragment extends Fragment { @Override public boolean onLongClick(View view) { view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - if (activeloop == null){ + if (activeloop == null) { log.error("no active loop?"); return true; - } else if (activeloop.isEnabled(PluginBase.LOOP)){ + } else if (activeloop.isEnabled(PluginBase.LOOP)) { activeloop.setFragmentEnabled(PluginBase.LOOP, false); activeloop.setFragmentVisible(PluginBase.LOOP, false); } else { @@ -578,7 +646,7 @@ public class OverviewFragment extends Fragment { showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested - if (showAcceptButton && pump.isInitialized() && ConfigBuilderPlugin.getActiveLoop() != null) { + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && ConfigBuilderPlugin.getActiveLoop() != null) { acceptTempLayout.setVisibility(View.VISIBLE); acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); } else { @@ -644,7 +712,7 @@ public class OverviewFragment extends Fragment { // QuickWizard button QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); - if (quickWizardEntry != null && lastBG != null && pump.isInitialized()) { + if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { quickWizardButton.setVisibility(View.VISIBLE); String text = MainApp.sResources.getString(R.string.bolus) + ": " + quickWizardEntry.buttonText() + " " + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = new BolusWizard(); @@ -663,7 +731,7 @@ public class OverviewFragment extends Fragment { bgView.setText(lastBG.valueToUnitsToString(profile.getUnits())); arrowView.setText(lastBG.directionToSymbol()); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (glucoseStatus != null){ + if (glucoseStatus != null) { deltaView.setText("Δ " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units); avgdeltaView.setText("øΔ15m: " + NSProfile.toUnitsString(glucoseStatus.short_avgdelta, glucoseStatus.short_avgdelta * Constants.MGDL_TO_MMOLL, units) + " øΔ40m: " + NSProfile.toUnitsString(glucoseStatus.long_avgdelta, glucoseStatus.long_avgdelta * Constants.MGDL_TO_MMOLL, units)); @@ -717,7 +785,7 @@ public class OverviewFragment extends Fragment { long fromTime; long endTime; if (showPrediction) { - int predHours = (int) (Math.ceil(((DetermineBasalResultAMA)finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000)); + int predHours = (int) (Math.ceil(((DetermineBasalResultAMA) finalLastRun.constraintsProcessed).getLatestPredictionsTime() - new Date().getTime()) / (60 * 60 * 1000)); predHours = Math.min(2, predHours); predHours = Math.max(0, predHours); hoursToFetch = (int) (6 - predHours); @@ -734,11 +802,11 @@ public class OverviewFragment extends Fragment { Double lowLine = SafeParse.stringToDouble(prefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(prefs.getString("high_mark", "0")); - if (lowLine < 1){ + if (lowLine < 1) { lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units); } - if(highLine < 1){ + if (highLine < 1) { highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); } @@ -847,7 +915,7 @@ public class OverviewFragment extends Fragment { } maxBgValue = NSProfile.fromMgdlToUnits(maxBgValue, units); maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4; - if(highLine > maxBgValue) maxBgValue = highLine; + if (highLine > maxBgValue) maxBgValue = highLine; Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1); BgReading[] inRange = new BgReading[inRangeArray.size()]; @@ -935,20 +1003,7 @@ public class OverviewFragment extends Fragment { bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(ContextCompat.getColor(MainApp.instance(), R.color.background_material_dark)); // same color as backround = hide } - // Pump not initialized message - if (!pump.isInitialized()) { - // disable all treatment buttons because we are not able to check constraints without profile - wizardButton.setVisibility(View.INVISIBLE); - treatmentButton.setVisibility(View.INVISIBLE); - quickWizardButton.setVisibility(View.INVISIBLE); - initializingView.setText(R.string.waitingforpump); - initializingView.setVisibility(View.VISIBLE); - } else { - wizardButton.setVisibility(View.VISIBLE); - treatmentButton.setVisibility(View.VISIBLE); - initializingView.setVisibility(View.GONE); - } - + updatePumpStatus(null); } //Notifications @@ -1040,5 +1095,4 @@ public class OverviewFragment extends Fragment { } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java index 3c5ed08377..4a31333ad9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java @@ -170,7 +170,7 @@ public class SimpleProfileFragment extends Fragment implements FragmentBase { activity.runOnUiThread(new Runnable() { @Override public void run() { - if (!MainApp.getConfigBuilder().isInitialized() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { + if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) { profileswitchButton.setVisibility(View.GONE); } else { profileswitchButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java index ac4e1a8c13..0463215c9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java @@ -124,6 +124,16 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return true; } + @Override + public boolean isSuspended() { + return false; + } + + @Override + public boolean isBusy() { + return false; + } + @Override public boolean isTempBasalInProgress() { return getTempBasal() != null; diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 926451033e..a7f3f02f36 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -58,7 +58,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { } }); t.start(); - } else if (isStatusOutdated) { + } else if (isStatusOutdated && !pump.isBusy()) { Thread t = new Thread(new Runnable() { @Override public void run() { @@ -66,7 +66,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { } }); t.start(); - } else if (isBasalOutdated) { + } else if (isBasalOutdated && !pump.isBusy()) { Thread t = new Thread(new Runnable() { @Override public void run() { diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index db2ac7c986..d0dcabeb41 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -246,7 +246,7 @@ НАТИСНАТ СТОП КЗ цел за изчисления Помпата е заета - Изчаква за помпа + Изчаква за помпа. Click to refresh. Грешна парола за помпата! Достигнахте лимита аларма diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 48117721c3..154985c6df 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -249,7 +249,7 @@ glykémie Historie Alarmy - Hodinvé bazály + Hodinové bazály Bolusy Sacharidy Připojování %d sec @@ -271,7 +271,7 @@ Stop Zastaveno STISKNUTO STOP - Čekání na pumpu + Čekání na pumpu. Klik pro připojení. Podávání %.2fU inzulínu Zkontrolovat, zda jsou glykémie a údaje z pumpy viditelné v Nightscoutu Nastavit vizualizaci a monitoring, analyzovat bazály a koeficienty @@ -457,6 +457,6 @@ xDrip+ není nainstalován xDrip nepřijímá kalibrace Odeslání kalibrace %.2f potvrďte kódem %s - Kalibrace odeslána + Kalibrace odeslána. Příjem musí být v xDripu povolený. Vzdálené kalibrace nejsou povoleny diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c0f505f944..38d24e1573 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -242,7 +242,7 @@ Korean Limit erreicht Falsches Pumpen-Passwort! - Warte auf Pumpe + Warte auf Pumpe. Click to refresh. Korr Abgabe %.2fU %.2fU Bolus erfolgreich abgegeben diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5f96bfaee6..b4be74fb35 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -283,7 +283,7 @@ Oclusión Detener Parar pulsado - Esperando bomba + Esperando bomba. Click to refresh. Va a entregar% .2fU Configuración de visualización y monitoreo, y el análisis de los basales y ratios Comprobar que los datos de BG están disponibles en Nightscout, y que los datos de la bomba de insulina se están subiendo diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 96e60dce0b..0ef31bc02e 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -286,7 +286,7 @@ 막힘 정지 정지 누름 - 펌프를 기다리고 있습니다. + 펌프를 기다리고 있습니다. Click to refresh. %.2fU을 주입합니다 나이트스카우트를 세팅하고, 기초주입과 비율을 분석한다. 나이트스카우트에서 혈당 데이터가 잘 들어오는지, 펌프데이터가 업로드 되는지 확인한다. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a8ca63e79f..155d9d318e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -301,7 +301,7 @@ Occlusion Stop STOP PRESSED - Waiting for pump + Waiting for pump. Click to refresh. Going to deliver %.2fU Setting up visualization and monitoring, and analyzing basals and ratios Verify that BG is available in Nightscout, and pump insulin data is being uploaded @@ -486,7 +486,16 @@ xDrip+ not installed Calibration sent to xDrip Remote calibration not allowed - Calibration sent + Calibration sent. Receiving must be enabled in xDrip. xDrip is not receiving calibrations Don\'t show again + Pump suspended. Click to refresh state + Pump suspended + Getting pump status + Setting temp basal + Stopping temp basal + Setting extended bolus + Stopping extended bolus + Updating basal rates + Disconnecting