Remove code to determine pump capabilities for the time being.

This commit is contained in:
Johannes Mockenhaupt 2017-08-27 13:39:29 +02:00
parent 40941996c2
commit c8f7b535c2
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
6 changed files with 0 additions and 302 deletions

View file

@ -1,23 +0,0 @@
package de.jotomo.ruffyscripter;
/**
* Created by adrian on 26/07/17.
* <p>
* Contains the capabilities of the current pump model.
*/
public class PumpCapabilities {
public long maxTempPercent;
public PumpCapabilities maxTempPercent(long maxTempPercent) {
this.maxTempPercent = maxTempPercent;
return this;
}
@Override
public String toString() {
return "PumpCapabilities{" +
"maxTempPercent=" + maxTempPercent +
'}';
}
}

View file

@ -3,7 +3,6 @@ package de.jotomo.ruffyscripter.commands;
import java.util.Date;
import de.jotomo.ruffyscripter.History;
import de.jotomo.ruffyscripter.PumpCapabilities;
import de.jotomo.ruffyscripter.PumpState;
public class CommandResult {
@ -14,7 +13,6 @@ public class CommandResult {
public String message;
public PumpState state;
public History history;
public PumpCapabilities capabilities;
public String duration;
public CommandResult() {
@ -60,11 +58,6 @@ public class CommandResult {
return this;
}
public CommandResult capabilities(PumpCapabilities capabilities) {
this.capabilities = capabilities;
return this;
}
@Override
public String toString() {
return "CommandResult{" +

View file

@ -1,160 +0,0 @@
package de.jotomo.ruffyscripter.commands;
import android.os.SystemClock;
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
import de.jotomo.ruffyscripter.PumpCapabilities;
public class DetermineCapabilitiesCommand extends BaseCommand {
private static final Logger log = LoggerFactory.getLogger(DetermineCapabilitiesCommand.class);
public static final int UP_STEPS = 75;
public static final int RETRIES = 5;
@Override
public List<String> validateArguments() {
return Collections.emptyList();
}
@Override
public CommandResult execute() {
try {
//read main menu 100% or TBR? Read remaining duration.
long durationBefore = readDisplayedTbrDurationMainMenu();
long percentageBefore = readDisplayedTbrPercentageMainMenu();
enterTbrMenu();
long maxTbrPercentage = findMaxTbrPercentage();
// TODO v2 this can probably be removed by now
SystemClock.sleep(750);
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU,
"Pump did not return to MAIN_MEU after finding max tbr. " +
"Check pump manually, the TBR might be wrong.");
//TODO: check if TBR is still the same or duration was less than 5 minutes
long durationAfter = readDisplayedTbrDurationMainMenu();
long percentageAfter = readDisplayedTbrPercentageMainMenu();
if(Math.abs(durationBefore-durationAfter) > 5){
throw new CommandException().message("Duration jump during DetermineCapabilities");
}
if(percentageAfter != percentageBefore){
if(durationBefore<5 && percentageAfter == 100){
log.debug("(percentageBefore != percentageAfter) - ignoring as tbr is now 100% and had a very short duration left");
}
throw new CommandException().message("TBR changed while determining maxTBR.");
}
//TODO return Result
return new CommandResult().success(true).enacted(false).message("Capablities: {maxTbrPercentage = " + maxTbrPercentage + ", success=" + "success }").capabilities((new PumpCapabilities()).maxTempPercent(maxTbrPercentage));
} catch (CommandException e) {
return e.toCommandResult();
}
}
private void enterTbrMenu() {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
scripter.navigateToMenu(MenuType.TBR_MENU);
scripter.verifyMenuIsDisplayed(MenuType.TBR_MENU);
scripter.pressCheckKey();
scripter.waitForMenuUpdate();
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
}
private long findMaxTbrPercentage() {
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
long activeTempBasal = readDisplayedTbrPercentage();
// pretend to increase the TBR to more than 500%
log.debug("Pressing up " + UP_STEPS + " times to get to maximum");
for (int i = 0; i < UP_STEPS; i++) {
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
scripter.pressUpKey();
SystemClock.sleep(200);
log.debug("Push #" + (i + 1));
}
//read the displayed maximum value
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
long maximumTempBasal = readDisplayedTbrPercentage();
//reset the TBR in a controlled manner
long percentageChange = maximumTempBasal - activeTempBasal;
long percentageSteps = percentageChange / 10;
int retries= 0;
while (percentageSteps > 0 && retries < RETRIES) {
log.debug("Pressing down " + percentageSteps + " times to get to previous value. Retry " + retries);
for (int i = 0; i < percentageSteps; i++) {
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
scripter.pressDownKey();
SystemClock.sleep(200);
log.debug("Push #" + (i + 1));
}
//do the rest if button-presses failed.
scripter.verifyMenuIsDisplayed(MenuType.TBR_SET);
long currentPercentage = readDisplayedTbrPercentage();
percentageChange = currentPercentage - activeTempBasal;
percentageSteps = percentageChange / 10;
retries++;
}
//exit menu
scripter.pressCheckKey();
scripter.waitForMenuToBeLeft(MenuType.TBR_SET);
return maximumTempBasal;
}
private long readDisplayedTbrPercentage() {
SystemClock.sleep(1000);
// TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded
Object percentageObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.BASAL_RATE);
// this as a bit hacky, the display value is blinking, so we might catch that, so
// keep trying till we get the Double we want
while (!(percentageObj instanceof Double)) {
scripter.waitForMenuUpdate();
percentageObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.BASAL_RATE);
}
return ((Double) percentageObj).longValue();
}
private int readDisplayedTbrDurationMainMenu() {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
if(scripter.getCurrentMenu().attributes().contains(MenuAttribute.RUNTIME)){
// TODO v2 add timeout? Currently the command execution timeout would trigger if exceeded
Object durationObj = scripter.getCurrentMenu().getAttribute(MenuAttribute.RUNTIME);
MenuTime duration = (MenuTime) durationObj;
return duration.getHour() * 60 + duration.getMinute();
} else {
return 0;
}
}
private int readDisplayedTbrPercentageMainMenu() {
scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);
if(scripter.getCurrentMenu().attributes().contains(MenuAttribute.TBR)){
return (int)((Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.TBR)).doubleValue();
} else {
return 100;
}
}
@Override
public String toString() {
return "DetermineCapabilitiesCommand{}";
}
}

View file

@ -34,7 +34,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
}
private Button refresh;
private TextView updateCapabilities;
private TextView statusText;
@ -48,7 +47,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
private TextView lastCmdResultText;
private TextView lastCmdDurationText;
private TextView tbrCapabilityText;
private TextView pumpstateBatteryText;
private TextView insulinstateText;
@ -59,7 +57,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
View view = inflater.inflate(R.layout.combopump_fragment, container, false);
refresh = (Button) view.findViewById(R.id.combo_refresh);
updateCapabilities = (TextView) view.findViewById(R.id.combo_update_capabilities);
statusText = (TextView) view.findViewById(R.id.combo_status);
@ -72,12 +69,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
lastCmdTimeText = (TextView) view.findViewById(R.id.combo_last_command_time);
lastCmdResultText = (TextView) view.findViewById(R.id.combo_last_command_result);
lastCmdDurationText = (TextView) view.findViewById(R.id.combo_last_command_duration);
tbrCapabilityText = (TextView) view.findViewById(R.id.combo_tbr_capability);
pumpstateBatteryText = (TextView) view.findViewById(R.id.combo_pumpstate_battery);
insulinstateText = (TextView) view.findViewById(R.id.combo_insulinstate);
refresh.setOnClickListener(this);
updateCapabilities.setOnClickListener(this);
updateGUI();
return view;
@ -113,32 +108,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
});
thread.start();
break;
case R.id.combo_update_capabilities:
(new Thread(new Runnable() {
@Override
public void run() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCapabilities.setText("{fa-bluetooth spin}");
}
});
getPlugin().updateCapabilities();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateCapabilities.setText("{fa-bluetooth-b}");
}
});
}
})).start();
break;
}
}
@ -201,7 +170,6 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
lastCmdDurationText.setText("");
}
}
tbrCapabilityText.setText(getPlugin().getPumpDescription().maxTempPercent + "%");
}
});
}

View file

@ -31,7 +31,6 @@ import de.jotomo.ruffyscripter.commands.BolusCommand;
import de.jotomo.ruffyscripter.commands.CancelTbrCommand;
import de.jotomo.ruffyscripter.commands.Command;
import de.jotomo.ruffyscripter.commands.CommandResult;
import de.jotomo.ruffyscripter.commands.DetermineCapabilitiesCommand;
import de.jotomo.ruffyscripter.commands.GetPumpStateCommand;
import de.jotomo.ruffyscripter.commands.SetTbrCommand;
import de.jotomo.ruffyscripter.commands.SetTbrCommandAlt;
@ -695,29 +694,4 @@ public class ComboPlugin implements PluginBase, PumpInterface {
public void onStatusEvent(final EventAppExit ignored) {
unbindRuffyService();
}
public void updateCapabilities() {
// if Android is sluggish this might get called before ruffy is bound
if (ruffyScripter == null) {
log.warn("Rejecting call to RefreshDataFromPump: ruffy service not bound (yet)");
ToastUtils.showToastInUiThread(MainApp.instance(), "Ruffy not initialized.");
return;
}
if (isBusy()) {
ToastUtils.showToastInUiThread(MainApp.instance(), "Pump busy!");
return;
}
CommandResult result = runCommand(new DetermineCapabilitiesCommand());
if (result.success) {
pumpDescription.maxTempPercent = (int) result.capabilities.maxTempPercent;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance());
SharedPreferences.Editor editor = preferences.edit();
editor.putInt(COMBO_MAX_TEMP_PERCENT_SP, pumpDescription.maxTempPercent);
editor.commit();
MainApp.bus().post(new EventComboPumpUpdateGUI());
} else {
ToastUtils.showToastInUiThread(MainApp.instance(), "No success.");
}
}
}

View file

@ -418,60 +418,6 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:paddingRight="5dp"
android:text="TBR Capability"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/combo_tbr_capability"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/combo_update_capabilities"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="20sp"
android:gravity="center_horizontal"
android:text="{fa-bluetooth-b}" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"