wip
This commit is contained in:
parent
324b68717f
commit
dd98d9f7ae
|
@ -154,6 +154,7 @@ dependencies {
|
|||
exclude group: 'com.google.android', module: 'android'
|
||||
}
|
||||
compile 'org.apache.commons:commons-lang3:3.6'
|
||||
compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
|
||||
compile 'org.slf4j:slf4j-api:1.7.12'
|
||||
compile 'com.jjoe64:graphview:4.0.1'
|
||||
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
|
||||
|
|
|
@ -26,7 +26,6 @@ public interface PumpInterface {
|
|||
int setNewBasalProfile(Profile profile);
|
||||
boolean isThisProfileSet(Profile profile);
|
||||
|
||||
@NonNull
|
||||
Date lastDataTime();
|
||||
void refreshDataFromPump(String reason);
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ import de.jotomo.ruffy.spi.history.Bolus;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
// TODO clean up time/date formatting once this stabilizes a bit more
|
||||
public class ComboFragment extends SubscriberFragment implements View.OnClickListener, View.OnLongClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(ComboFragment.class);
|
||||
|
||||
|
@ -39,6 +39,8 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
|
||||
private Button refresh;
|
||||
|
||||
private PrettyTime prettyTime = new PrettyTime();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@ -136,8 +138,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
}
|
||||
|
||||
// last connection
|
||||
PrettyTime p = new PrettyTime();
|
||||
String timeAgo = StringUtils.capitalize(p.format(new Date(plugin.getPump().lastSuccessfulConnection)));
|
||||
String timeAgo = StringUtils.capitalize(prettyTime.format(new Date(plugin.getPump().lastSuccessfulConnection)));
|
||||
if (plugin.getPump().lastSuccessfulConnection == 0) {
|
||||
lastConnectionView.setText(R.string.combo_pump_never_connected);
|
||||
lastConnectionView.setTextColor(Color.RED);
|
||||
|
@ -159,7 +160,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
||||
double bolusMinAgo = agoMsc / 60d / 1000d;
|
||||
double bolusHoursAgo = agoMsc / 60d / 60d / 1000d;
|
||||
lastBolusView.setText(String.format("%.1f U (", bolus.amount) + p.format(new Date(bolus.timestamp)) + ")");
|
||||
lastBolusView.setText(String.format("%.1f U (", bolus.amount) + prettyTime.format(new Date(bolus.timestamp)) + ")");
|
||||
// lastBolusView.setText(getString(R.string.combo_last_bolus,
|
||||
// bolus.amount,
|
||||
// bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
|
||||
|
@ -176,7 +177,8 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
long remaining = ps.tbrRemainingDuration - minSinceRead;
|
||||
if (remaining >= 0) {
|
||||
tbrStr = getString(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
|
||||
tbrStr = ps.tbrPercent + "% (" + p.formatDuration(new Date(System.currentTimeMillis() + remaining * 60 * 1000)) + " remaining)";
|
||||
tbrStr = ps.tbrPercent + "% (" + prettyTime.formatDuration(new Date(System.currentTimeMillis() + remaining * 60 * 1000)) + " remaining)";
|
||||
tbrStr = ps.tbrPercent + "% (" + prettyTime.format(new Date(System.currentTimeMillis() + remaining * 60 * 1000)) + " remaining)";
|
||||
}
|
||||
}
|
||||
tempBasalText.setText(tbrStr);
|
||||
|
|
|
@ -52,6 +52,7 @@ import static de.jotomo.ruffy.spi.BolusProgressReporter.State.FINISHED;
|
|||
public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(ComboPlugin.class);
|
||||
|
||||
private static ComboPlugin plugin = null;
|
||||
private boolean fragmentEnabled = false;
|
||||
private boolean fragmentVisible = false;
|
||||
|
||||
|
@ -63,8 +64,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
// TODO access to pump (and its members) is chaotic and needs an update
|
||||
private static ComboPump pump = new ComboPump();
|
||||
|
||||
private static ComboPlugin plugin = null;
|
||||
|
||||
private volatile boolean bolusInProgress;
|
||||
private volatile boolean cancelBolus;
|
||||
private Bolus lastRequestedBolus;
|
||||
|
@ -204,7 +203,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return ruffyScripter.isPumpBusy() && !pump.state.suspended;
|
||||
return ruffyScripter.isPumpBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,10 +230,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
public synchronized void refreshDataFromPump(String reason) {
|
||||
log.debug("RefreshDataFromPump called");
|
||||
if (!pump.initialized) {
|
||||
// TODO reading profile
|
||||
long maxWait = System.currentTimeMillis() + 15 * 1000;
|
||||
while (!ruffyScripter.isPumpAvailable()) {
|
||||
log.debug("Waiting for ruffy service to be connected ...");
|
||||
log.debug("Waiting for ruffy service to come up ...");
|
||||
SystemClock.sleep(100);
|
||||
if (System.currentTimeMillis() > maxWait) {
|
||||
log.debug("ruffy service unavailable, wtf");
|
||||
|
@ -243,15 +241,17 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
}
|
||||
|
||||
// TODO reading profile, set clock; periodically and forced at startup (by setting/having profile/stateLastRead be 0
|
||||
CommandResult result = runCommand("Refreshing", 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
||||
updateLocalData(result);
|
||||
if (result.success)
|
||||
pump.initialized = true;
|
||||
|
||||
// TODO fuse the below into 'sync'? or make checkForTbrMismatch jut a trigger to issue a sync if needed; don't run sync twice as is nice
|
||||
// checkForTbrMismatch();
|
||||
checkPumpHistory();
|
||||
// checkPumpDate()
|
||||
|
||||
pump.initialized = true;
|
||||
}
|
||||
|
||||
private void updateLocalData(CommandResult result) {
|
||||
|
@ -577,8 +577,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
// TODO properly check pumpstate to confirm cancellation
|
||||
PumpState state = commandResult.state;
|
||||
if (!state.tbrActive && state.tbrPercent == percent
|
||||
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
|
||||
// if (!state.tbrActive && state.tbrPercent == percent
|
||||
// && (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
if (tempBasal != null) {
|
||||
|
|
|
@ -29,6 +29,7 @@ public class CommandResult {
|
|||
|
||||
public int reservoirLevel = -1;
|
||||
|
||||
@Nullable
|
||||
public Bolus lastBolus;
|
||||
|
||||
public long pumpTime;
|
||||
|
|
Loading…
Reference in a new issue