SPI first draft.
This commit is contained in:
parent
4a91b68ed7
commit
e5eba342ba
24 changed files with 311 additions and 54 deletions
|
@ -126,11 +126,14 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
|
||||||
tbrRateText.setText("");
|
tbrRateText.setText("");
|
||||||
}
|
}
|
||||||
pumpErrorText.setText(ps.errorMsg != null ? ps.errorMsg : "");
|
pumpErrorText.setText(ps.errorMsg != null ? ps.errorMsg : "");
|
||||||
if(ps.lowBattery){
|
if(ps.batteryState == PumpState.EMPTY){
|
||||||
pumpstateBatteryText.setText("{fa-battery-empty}");
|
pumpstateBatteryText.setText("{fa-battery-empty}");
|
||||||
pumpstateBatteryText.setTextColor(Color.RED);
|
pumpstateBatteryText.setTextColor(Color.RED);
|
||||||
|
} else if(ps.batteryState == PumpState.LOW){
|
||||||
|
pumpstateBatteryText.setText("{fa-battery-quarter}");
|
||||||
|
pumpstateBatteryText.setTextColor(Color.WHITE);
|
||||||
} else {
|
} else {
|
||||||
pumpstateBatteryText.setText("{fa-battery-three-quarters}");
|
pumpstateBatteryText.setText("{fa-battery-full}");
|
||||||
pumpstateBatteryText.setTextColor(Color.WHITE);
|
pumpstateBatteryText.setTextColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
switch (ps.insulinState){
|
switch (ps.insulinState){
|
||||||
|
|
|
@ -29,7 +29,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyCommandsV1Impl;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpState;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpState;
|
||||||
|
@ -73,7 +73,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
definePumpCapabilities();
|
definePumpCapabilities();
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
startAlerter();
|
startAlerter();
|
||||||
ruffyScripter = new RuffyScripter();
|
ruffyScripter = RuffyCommandsV1Impl.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void definePumpCapabilities() {
|
private void definePumpCapabilities() {
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BasalProfile;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistory;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.RuffyCommands;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistoryRequest;
|
||||||
|
|
||||||
|
public class RuffyCommandsV1Impl implements RuffyCommands {
|
||||||
|
private static RuffyCommands delegate;
|
||||||
|
|
||||||
|
public static RuffyCommands getInstance() {
|
||||||
|
if (delegate == null) delegate = new RuffyScripter();
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RuffyCommandsV1Impl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter) {
|
||||||
|
return delegate.deliverBolus(amount, bolusProgressReporter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelBolus() {
|
||||||
|
delegate.cancelBolus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult setTbr(int percent, int duration) {
|
||||||
|
return delegate.setTbr(percent, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult cancelTbr() {
|
||||||
|
return delegate.cancelTbr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPumpAvailable() {
|
||||||
|
return delegate.isPumpAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPumpBusy() {
|
||||||
|
return delegate.isPumpBusy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult readHistory(PumpHistoryRequest request) {
|
||||||
|
return delegate.readHistory(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult readBasalProfile(int number) {
|
||||||
|
return delegate.readBasalProfile(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult setBasalProfile(BasalProfile basalProfile) {
|
||||||
|
return delegate.setBasalProfile(basalProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult setDateAndTime(Date date) {
|
||||||
|
return delegate.setDateAndTime(date);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo.ruffy;
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -20,6 +20,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -37,9 +38,13 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.comm
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BasalProfile;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BasalProfile;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpHistory;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Bolus;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistory;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpState;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpState;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.RuffyCommands;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.RuffyCommands;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistoryRequest;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Tbr;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Tdd;
|
||||||
|
|
||||||
// TODO regularly read "My data" history (boluses, TBR) to double check all commands ran successfully.
|
// TODO regularly read "My data" history (boluses, TBR) to double check all commands ran successfully.
|
||||||
// Automatically compare against AAPS db, or log all requests in the PumpInterface (maybe Milos
|
// Automatically compare against AAPS db, or log all requests in the PumpInterface (maybe Milos
|
||||||
|
@ -452,7 +457,8 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute();
|
state.tbrRemainingDuration = durationMenuTime.getHour() * 60 + durationMenuTime.getMinute();
|
||||||
state.tbrRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE));
|
state.tbrRate = ((double) menu.getAttribute(MenuAttribute.BASAL_RATE));
|
||||||
}
|
}
|
||||||
state.lowBattery = ((boolean) menu.getAttribute(MenuAttribute.LOW_BATTERY));
|
// ruffy doesn't support 'empty battery' flag, not sure if the pump does
|
||||||
|
state.batteryState = ((boolean) menu.getAttribute(MenuAttribute.LOW_BATTERY)) ? PumpState.LOW : -1;
|
||||||
state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE));
|
state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE));
|
||||||
// TODO v2, read current base basal rate, which is shown center when no TBR is active.
|
// TODO v2, read current base basal rate, which is shown center when no TBR is active.
|
||||||
// Check if that holds true when an extended bolus is running.
|
// Check if that holds true when an extended bolus is running.
|
||||||
|
@ -462,7 +468,8 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
state.errorMsg = (String) menu.getAttribute(MenuAttribute.MESSAGE);
|
state.errorMsg = (String) menu.getAttribute(MenuAttribute.MESSAGE);
|
||||||
} else if (menuType == MenuType.STOP) {
|
} else if (menuType == MenuType.STOP) {
|
||||||
state.suspended = true;
|
state.suspended = true;
|
||||||
state.lowBattery = ((boolean) menu.getAttribute(MenuAttribute.LOW_BATTERY));
|
// ruffy doesn't support 'empty battery' flag, not sure if the pump does
|
||||||
|
state.batteryState = ((boolean) menu.getAttribute(MenuAttribute.LOW_BATTERY)) ? PumpState.LOW : -1;
|
||||||
state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE));
|
state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE));
|
||||||
} else {
|
} else {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -750,8 +757,8 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult setTbr(int percent, int duraton) {
|
public CommandResult setTbr(int percent, int duration) {
|
||||||
return runCommand(new SetTbrCommand(percent, duraton));
|
return runCommand(new SetTbrCommand(percent, duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -760,18 +767,18 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readReservoirLevel() {
|
public CommandResult readHistory(PumpHistoryRequest request) {
|
||||||
return runCommand(new ReadReserverLevelCommand());
|
return new CommandResult().history(
|
||||||
|
new PumpHistory(50,
|
||||||
|
Collections.<Bolus>emptyList(),
|
||||||
|
Collections.<Tbr>emptyList(),
|
||||||
|
Collections.<Error>emptyList(),
|
||||||
|
Collections.<Tdd>emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readHistory(PumpHistory knownHistory) {
|
public CommandResult readBasalProfile(int number) {
|
||||||
return runCommand(new ReadHistoryCommand(knownHistory));
|
return runCommand(new ReadBasalProfileCommand(number));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult readBasalProfile() {
|
|
||||||
return runCommand(new ReadBasalProfileCommand());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -1,6 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.commands;
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.commands;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
|
|
||||||
public abstract class BaseCommand implements Command {
|
public abstract class BaseCommand implements Command {
|
||||||
// RS will inject itself here
|
// RS will inject itself here
|
||||||
|
|
|
@ -11,7 +11,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BolusProgressReporter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.com
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
public class GetBasalRateProfileCommand extends BaseCommand {
|
public class GetBasalRateProfileCommand extends BaseCommand {
|
||||||
|
|
|
@ -2,10 +2,16 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.com
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
public class ReadBasalProfileCommand implements Command {
|
public class ReadBasalProfileCommand implements Command {
|
||||||
|
private final int number;
|
||||||
|
|
||||||
|
public ReadBasalProfileCommand(int number) {
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute() {
|
public CommandResult execute() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.com
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.PumpHistory;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistory;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
public class ReadHistoryCommand implements Command {
|
public class ReadHistoryCommand implements Command {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.com
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
public class ReadReserverLevelCommand implements Command {
|
public class ReadReserverLevelCommand implements Command {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.com
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BasalProfile;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.BasalProfile;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.RuffyScripter;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.internal.scripter.RuffyScripter;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.CommandResult;
|
||||||
|
|
||||||
public class SetBasalProfileCommand implements Command {
|
public class SetBasalProfileCommand implements Command {
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
||||||
|
|
||||||
public class BasalProfile {
|
public class BasalProfile {
|
||||||
|
public final int number;
|
||||||
|
public final double[] hourlyRates;
|
||||||
|
|
||||||
|
public BasalProfile(int number, double[] hourlyRates) {
|
||||||
|
this.number = number;
|
||||||
|
if (hourlyRates.length != 24)
|
||||||
|
throw new IllegalArgumentException("Profile must have 24 hourly rates");
|
||||||
|
this.hourlyRates = hourlyRates;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,30 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistory;
|
||||||
|
|
||||||
public class CommandResult {
|
public class CommandResult {
|
||||||
|
/** The request made made to the pump, like setting a TBR. */
|
||||||
public String request;
|
public String request;
|
||||||
|
/** Whether the command was executed successfully. */
|
||||||
public boolean success;
|
public boolean success;
|
||||||
|
/** Whether any changes were made, e.g. if a the request was to cancel a running TBR,
|
||||||
|
* but not TBR was active, this will be false. */
|
||||||
public boolean enacted;
|
public boolean enacted;
|
||||||
|
/** Time the command completed. */
|
||||||
public long completionTime;
|
public long completionTime;
|
||||||
|
/** Null unless an unhandled exception was raised. */
|
||||||
public Exception exception;
|
public Exception exception;
|
||||||
|
/** (Error)message describing the result of the command. */
|
||||||
public String message;
|
public String message;
|
||||||
|
/** State of the pump *after* command execution. */
|
||||||
public PumpState state;
|
public PumpState state;
|
||||||
|
/** History if requested by the command. */
|
||||||
public PumpHistory history;
|
public PumpHistory history;
|
||||||
|
/** Basal rate profile if requested. */
|
||||||
|
public List<BasalProfile> basalProfiles;
|
||||||
|
/** Total duration the command took. */
|
||||||
public String duration;
|
public String duration;
|
||||||
|
|
||||||
public CommandResult() {
|
public CommandResult() {
|
||||||
|
@ -61,17 +75,24 @@ public class CommandResult {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandResult basalProfile(List<BasalProfile> basalProfiles) {
|
||||||
|
this.basalProfiles = basalProfiles;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CommandResult{" +
|
return "CommandResult{" +
|
||||||
"request=" + request +
|
"request='" + request + '\'' +
|
||||||
", success=" + success +
|
", success=" + success +
|
||||||
", enacted=" + enacted +
|
", enacted=" + enacted +
|
||||||
", completionTime=" + completionTime + "(" + new Date(completionTime) + ")" +
|
", completionTime=" + completionTime +
|
||||||
"' duration=" + duration +
|
|
||||||
", exception=" + exception +
|
", exception=" + exception +
|
||||||
", message='" + message + '\'' +
|
", message='" + message + '\'' +
|
||||||
", state=" + state +
|
", state=" + state +
|
||||||
|
", history=" + history +
|
||||||
|
", basalProfiles=" + basalProfiles +
|
||||||
|
", duration='" + duration + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
|
||||||
|
|
||||||
public class PumpHistory {
|
|
||||||
}
|
|
|
@ -3,13 +3,17 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State representing the state of the MAIN_MENU.
|
* State representing the state of the MAIN_MENU, plus reservoir level (if requested).
|
||||||
*/
|
*/
|
||||||
public class PumpState {
|
public class PumpState {
|
||||||
public Date timestamp = new Date();
|
public Date timestamp = new Date();
|
||||||
public boolean tbrActive = false;
|
public boolean tbrActive = false;
|
||||||
|
/** TBR percentage. 100% means no TBR active, just the normal basal rate running. */
|
||||||
public int tbrPercent = -1;
|
public int tbrPercent = -1;
|
||||||
|
/** The absolute rate the TBR is running, e.g. 0.80U/h. */
|
||||||
public double tbrRate = -1;
|
public double tbrRate = -1;
|
||||||
|
/** Remaining time of an active TBR. Note that 0:01 is te lowest displayed, the pump
|
||||||
|
* jumps from that to TBR end, skipping 0:00(xx). */
|
||||||
public int tbrRemainingDuration = -1;
|
public int tbrRemainingDuration = -1;
|
||||||
/**
|
/**
|
||||||
* This is the error message (if any) displayed by the pump if there is an alarm,
|
* This is the error message (if any) displayed by the pump if there is an alarm,
|
||||||
|
@ -20,9 +24,14 @@ public class PumpState {
|
||||||
*/
|
*/
|
||||||
public String errorMsg;
|
public String errorMsg;
|
||||||
public boolean suspended;
|
public boolean suspended;
|
||||||
public boolean lowBattery;
|
|
||||||
|
public static final int LOW = 1;
|
||||||
|
public static final int EMPTY = 2;
|
||||||
|
|
||||||
|
public int batteryState = - 1;
|
||||||
public int insulinState = -1;
|
public int insulinState = -1;
|
||||||
public int reservoirLevel = -1;
|
|
||||||
|
public int activeBasalProfileNumber;
|
||||||
|
|
||||||
public PumpState tbrActive(boolean tbrActive) {
|
public PumpState tbrActive(boolean tbrActive) {
|
||||||
this.tbrActive = tbrActive;
|
this.tbrActive = tbrActive;
|
||||||
|
@ -54,8 +63,8 @@ public class PumpState {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpState lowBattery(boolean lowBattery) {
|
public PumpState batteryState(int batteryState) {
|
||||||
this.lowBattery = lowBattery;
|
this.batteryState = batteryState;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +73,8 @@ public class PumpState {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpState reservoirLevel(int reservoirLevel) {
|
public PumpState activeBasalProfileNumber(int activeBasalProfileNumber) {
|
||||||
this.reservoirLevel = reservoirLevel;
|
this.activeBasalProfileNumber = activeBasalProfileNumber;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,16 +89,16 @@ public class PumpState {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PumpState{" +
|
return "PumpState{" +
|
||||||
"tbrActive=" + tbrActive +
|
"timestamp=" + timestamp +
|
||||||
|
", tbrActive=" + tbrActive +
|
||||||
", tbrPercent=" + tbrPercent +
|
", tbrPercent=" + tbrPercent +
|
||||||
", tbrRate=" + tbrRate +
|
", tbrRate=" + tbrRate +
|
||||||
", tbrRemainingDuration=" + tbrRemainingDuration +
|
", tbrRemainingDuration=" + tbrRemainingDuration +
|
||||||
", errorMsg=" + errorMsg +
|
", errorMsg='" + errorMsg + '\'' +
|
||||||
", suspended=" + suspended +
|
", suspended=" + suspended +
|
||||||
", lowBattery=" + lowBattery +
|
", batteryState=" + batteryState +
|
||||||
", insulinState=" + insulinState +
|
", insulinState=" + insulinState +
|
||||||
", reversoirLevel=" + reservoirLevel +
|
", activeBasalProfileNumber=" + activeBasalProfileNumber +
|
||||||
", timestamp=" + timestamp +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.PumpHistoryRequest;
|
||||||
|
|
||||||
public interface RuffyCommands {
|
public interface RuffyCommands {
|
||||||
CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter);
|
CommandResult deliverBolus(double amount, BolusProgressReporter bolusProgressReporter);
|
||||||
|
|
||||||
void cancelBolus();
|
void cancelBolus();
|
||||||
|
|
||||||
CommandResult setTbr(int percent, int duraton);
|
CommandResult setTbr(int percent, int duration);
|
||||||
|
|
||||||
CommandResult cancelTbr();
|
CommandResult cancelTbr();
|
||||||
|
|
||||||
|
@ -15,12 +17,9 @@ public interface RuffyCommands {
|
||||||
|
|
||||||
boolean isPumpBusy();
|
boolean isPumpBusy();
|
||||||
|
|
||||||
CommandResult readReservoirLevel();
|
CommandResult readHistory(PumpHistoryRequest request);
|
||||||
|
|
||||||
// PumpHistory.fields.*: null=don't care. empty history=we know nothing yet. filled history=this is what we know so far
|
CommandResult readBasalProfile(int number);
|
||||||
CommandResult readHistory(PumpHistory knownHistory);
|
|
||||||
|
|
||||||
CommandResult readBasalProfile();
|
|
||||||
|
|
||||||
CommandResult setBasalProfile(BasalProfile basalProfile);
|
CommandResult setBasalProfile(BasalProfile basalProfile);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
public class Bolus extends HistoryRecord {
|
||||||
|
public final double amount;
|
||||||
|
|
||||||
|
public Bolus(long timestamp, double amount) {
|
||||||
|
super(timestamp);
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
public class Error extends HistoryRecord {
|
||||||
|
/** Code is an E for error or W for warning, followed by a single digit, e.g. W7 (TBR cancelled). */
|
||||||
|
public final String code;
|
||||||
|
/** Error message, in the language configured on the pump. */
|
||||||
|
public final String message;
|
||||||
|
|
||||||
|
public Error(long timestamp, String code, String message) {
|
||||||
|
super(timestamp);
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
public abstract class HistoryRecord {
|
||||||
|
public final long timestamp;
|
||||||
|
|
||||||
|
protected HistoryRecord(long timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.lang.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Bolus;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Tbr;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history.Tdd;
|
||||||
|
|
||||||
|
public class PumpHistory {
|
||||||
|
public final int reservoirLevel;
|
||||||
|
@NonNull
|
||||||
|
public final List<Bolus> bolusHistory;
|
||||||
|
@NonNull
|
||||||
|
public final List<Tbr> tbrHistory;
|
||||||
|
@NonNull
|
||||||
|
public final List<java.lang.Error> errorHistory;
|
||||||
|
@NonNull
|
||||||
|
public final List<Tdd> tddHistory;
|
||||||
|
|
||||||
|
public PumpHistory(int reservoirLevel, List<Bolus> bolusHistory, List<Tbr> tbrHistory, List<java.lang.Error> errorHistory, List<Tdd> tddHistory) {
|
||||||
|
this.reservoirLevel = reservoirLevel;
|
||||||
|
this.bolusHistory = Objects.requireNonNull(bolusHistory);
|
||||||
|
this.tbrHistory = Objects.requireNonNull(tbrHistory);
|
||||||
|
this.errorHistory = Objects.requireNonNull(errorHistory);
|
||||||
|
this.tddHistory = Objects.requireNonNull(tddHistory);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
/** What data a 'read history' request should return. */
|
||||||
|
public class PumpHistoryRequest {
|
||||||
|
public boolean reservoirLevel;
|
||||||
|
|
||||||
|
/* History to read:
|
||||||
|
Either the timestamp of the last known record to fetch all newer records,
|
||||||
|
or one of the constants to read no history or all of it.
|
||||||
|
*/
|
||||||
|
public static final long SKIP = -1;
|
||||||
|
public static final long FULL = 0;
|
||||||
|
|
||||||
|
public long bolusHistory;
|
||||||
|
public long tbrHistory;
|
||||||
|
public long errorHistory;
|
||||||
|
|
||||||
|
public PumpHistoryRequest reservoirLevel(boolean reservoirLevel) {
|
||||||
|
this.reservoirLevel = reservoirLevel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpHistoryRequest bolusHistory(long bolusHistory) {
|
||||||
|
this.bolusHistory = bolusHistory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpHistoryRequest tbrHistory(long tbrHistory) {
|
||||||
|
this.tbrHistory = tbrHistory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpHistoryRequest errorHistory(long errorHistory) {
|
||||||
|
this.errorHistory = errorHistory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PumpHistoryRequest{" +
|
||||||
|
"reservoirLevel=" + reservoirLevel +
|
||||||
|
", bolusHistory=" + bolusHistory +
|
||||||
|
", tbrHistory=" + tbrHistory +
|
||||||
|
", errorHistory=" + errorHistory +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
public class Tbr extends HistoryRecord {
|
||||||
|
public final int duration;
|
||||||
|
public final int percent;
|
||||||
|
|
||||||
|
public Tbr(long timestamp, int duration, int percent) {
|
||||||
|
super(timestamp);
|
||||||
|
this.duration = duration;
|
||||||
|
this.percent = percent;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpCombo.ruffy.spi.history;
|
||||||
|
|
||||||
|
/** Total daily dosage; amount of insulin delivered over a full day. */
|
||||||
|
public class Tdd extends HistoryRecord {
|
||||||
|
public final double total;
|
||||||
|
|
||||||
|
public Tdd(long timestamp, double total) {
|
||||||
|
super(timestamp);
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue