diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 83cc32a9e0..7bae8d1883 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -53,16 +53,9 @@ public class ComboFragment extends Fragment implements View.OnClickListener { lastCmdTime = (TextView) view.findViewById(R.id.combo_last_command_time); lastCmdResult = (TextView) view.findViewById(R.id.combo_last_command_result); - status.setText("Initializing"); - tbrPercentage.setText(""); - tbrDurationRemaining.setText(""); - tbrRate.setText(""); - lastCmd.setText(""); - lastCmdTime.setText(""); - lastCmdResult.setText(""); - refresh.setOnClickListener(this); + updateGUI(); return view; } @@ -87,12 +80,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener { public void onClick(View view) { switch (view.getId()) { case R.id.combo_refresh: - status.setText("Refreshing"); Thread thread = new Thread(new Runnable() { @Override public void run() { getPlugin().refreshDataFromPump("User request"); - updateGUI(); } }); thread.start(); @@ -107,25 +98,27 @@ public class ComboFragment extends Fragment implements View.OnClickListener { @Override public void run() { status.setText(getPlugin().statusSummary); - PumpState ps = getPlugin().pumpState; - boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; - if (tbrActive) { - tbrPercentage.setText("" + ps.tbrPercent + "%"); - tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min"); - tbrRate.setText("" + ps.tbrRate + " U/h"); - } else { - tbrPercentage.setText("Default basal rate running"); - tbrDurationRemaining.setText(""); - tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h"); - } - if (getPlugin().lastCmd != null) { - lastCmd.setText("" + getPlugin().lastCmd); - lastCmdTime.setText(ps.timestamp.toLocaleString()); - lastCmdResult.setText(ps.errorMsg == null ? "Success" : ps.errorMsg); - } else { - lastCmd.setText(""); - lastCmdTime.setText(""); - lastCmdResult.setText(""); + if (getPlugin().isInitialized()) { + PumpState ps = getPlugin().pumpState; + boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; + if (tbrActive) { + tbrPercentage.setText("" + ps.tbrPercent + "%"); + tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min"); + tbrRate.setText("" + ps.tbrRate + " U/h"); + } else { + tbrPercentage.setText("Default basal rate running"); + tbrDurationRemaining.setText(""); + tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h"); + } + if (getPlugin().lastCmd != null) { + lastCmd.setText("" + getPlugin().lastCmd); + lastCmdTime.setText(ps.timestamp.toLocaleString()); + lastCmdResult.setText(ps.errorMsg == null ? "Success" : ps.errorMsg); + } else { + lastCmd.setText(""); + lastCmdTime.setText(""); + lastCmdResult.setText(""); + } } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index fb4795b03f..4e28061ccc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -108,12 +108,6 @@ public class ComboPlugin implements PluginBase, PumpInterface { public void onServiceConnected(ComponentName name, IBinder service) { ruffyScripter = new RuffyScripter(IRuffyService.Stub.asInterface(service)); log.debug("ruffy serivce connected"); - new Thread(new Runnable() { - @Override - public void run() { - log.debug("Querying pump for initial state"); - } - }).start(); } @Override @@ -136,9 +130,9 @@ public class ComboPlugin implements PluginBase, PumpInterface { long lastAlarmTime = 0; while (true) { String errorMsg = pumpState.errorMsg; - long now = System.currentTimeMillis(); - long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000); - if (errorMsg != null) + if (errorMsg != null) { + long now = System.currentTimeMillis(); + long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000); if (now > fiveMinutesSinceLastAlarm) { log.warn("Pump is in error state, raising alert: " + errorMsg); log.warn(" LastCmd: " + lastCmd); @@ -159,8 +153,9 @@ public class ComboPlugin implements PluginBase, PumpInterface { lastAlarmTime = now; } else { log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg); + } } else { - log.debug("Pump state normal"); + log.trace("Pump state normal"); } SystemClock.sleep(5 * 1000); } @@ -257,9 +252,8 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public boolean isInitialized() { - // TODO - // hm, lastCmdDate > 0, like the DanaR does it? - return true; // scripter does this as needed; ruffyScripter != null; + // consider initialized when the pump's state was initially fetched + return lastCmdTime.getTime() > 0; } @Override