- added bolus and basal amount rounding (rounding to pump specification)
This commit is contained in:
parent
4082f52dd9
commit
07495ccfdd
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
||||||
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.DoseStepSize;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
|
||||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
||||||
|
@ -12,6 +13,61 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
||||||
public class PumpUtil {
|
public class PumpUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType)
|
||||||
|
{
|
||||||
|
if (bolusAmount == 0.0d || pumpType==null)
|
||||||
|
{
|
||||||
|
return bolusAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
double bolusStepSize;
|
||||||
|
|
||||||
|
if (pumpType.getSpecialBolusSize()==null)
|
||||||
|
{
|
||||||
|
bolusStepSize = pumpType.getBolusSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DoseStepSize specialBolusSize = pumpType.getSpecialBolusSize();
|
||||||
|
|
||||||
|
bolusStepSize = specialBolusSize.getStepSizeForAmount((float)bolusAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.round(bolusAmount/bolusStepSize) * bolusStepSize;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType)
|
||||||
|
{
|
||||||
|
if ( basalAmount == null || basalAmount == 0.0d || pumpType==null)
|
||||||
|
{
|
||||||
|
return basalAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
double basalStepSize;
|
||||||
|
|
||||||
|
if (pumpType.getBaseBasalSpecialSteps()==null)
|
||||||
|
{
|
||||||
|
basalStepSize = pumpType.getBaseBasalStep();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DoseStepSize specialBolusSize = pumpType.getBaseBasalSpecialSteps();
|
||||||
|
|
||||||
|
basalStepSize = specialBolusSize.getStepSizeForAmount(basalAmount.floatValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (basalAmount> pumpType.getBaseBasalMaxValue())
|
||||||
|
basalAmount = pumpType.getBaseBasalMaxValue().doubleValue();
|
||||||
|
|
||||||
|
|
||||||
|
return Math.round(basalAmount/basalStepSize) * basalStepSize;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
|
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
|
||||||
{
|
{
|
||||||
// reset
|
// reset
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
private static VirtualPumpPlugin plugin = null;
|
private static VirtualPumpPlugin plugin = null;
|
||||||
|
|
||||||
public static VirtualPumpPlugin getPlugin() {
|
public static VirtualPumpPlugin getPlugin() {
|
||||||
|
|
||||||
loadFakingStatus();
|
loadFakingStatus();
|
||||||
if (plugin == null)
|
if (plugin == null)
|
||||||
plugin = new VirtualPumpPlugin();
|
plugin = new VirtualPumpPlugin();
|
||||||
|
@ -66,19 +67,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
|
|
||||||
private static void loadFakingStatus() {
|
private static void loadFakingStatus() {
|
||||||
|
|
||||||
fromNSAreCommingFakedExtendedBoluses = SP.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false);
|
fromNSAreCommingFakedExtendedBoluses = SP.getBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFakingStatus(boolean newStatus) {
|
public static void setFakingStatus(boolean newStatus) {
|
||||||
|
|
||||||
fromNSAreCommingFakedExtendedBoluses = newStatus;
|
fromNSAreCommingFakedExtendedBoluses = newStatus;
|
||||||
SP.putBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, fromNSAreCommingFakedExtendedBoluses);
|
SP.putBoolean(R.string.key_fromNSAreCommingFakedExtendedBoluses, fromNSAreCommingFakedExtendedBoluses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getFakingStatus() {
|
public static boolean getFakingStatus() {
|
||||||
|
|
||||||
return fromNSAreCommingFakedExtendedBoluses;
|
return fromNSAreCommingFakedExtendedBoluses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualPumpPlugin() {
|
public VirtualPumpPlugin() {
|
||||||
|
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.PUMP)
|
.mainType(PluginType.PUMP)
|
||||||
.fragmentClass(VirtualPumpFragment.class.getName())
|
.fragmentClass(VirtualPumpFragment.class.getName())
|
||||||
|
@ -120,6 +125,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
|
|
||||||
super.onStart();
|
super.onStart();
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
refreshConfiguration();
|
refreshConfiguration();
|
||||||
|
@ -127,17 +133,20 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
|
||||||
MainApp.bus().unregister(this);
|
MainApp.bus().unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange s) {
|
public void onStatusEvent(final EventPreferenceChange s) {
|
||||||
|
|
||||||
if (s.isChanged(R.string.key_virtualpump_type))
|
if (s.isChanged(R.string.key_virtualpump_type))
|
||||||
refreshConfiguration();
|
refreshConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
public boolean isFakingTempsByExtendedBoluses() {
|
||||||
|
|
||||||
return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses;
|
return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,40 +159,48 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSuspended() {
|
public boolean isSuspended() {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBusy() {
|
public boolean isBusy() {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnecting() {
|
public boolean isConnecting() {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHandshakeInProgress() {
|
public boolean isHandshakeInProgress() {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishHandshaking() {
|
public void finishHandshaking() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
|
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT)
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
|
@ -191,19 +208,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(String reason) {
|
public void disconnect(String reason) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopConnecting() {
|
public void stopConnecting() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
|
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -215,16 +236,19 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long lastDataTime() {
|
public long lastDataTime() {
|
||||||
|
|
||||||
return lastDataTime;
|
return lastDataTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
|
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
return profile.getBasal();
|
return profile.getBasal();
|
||||||
|
@ -232,8 +256,18 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
return 0d;
|
return 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
|
||||||
|
if (this.pumpType!=null)
|
||||||
|
{
|
||||||
|
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
|
||||||
|
}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.bolusDelivered = detailedBolusInfo.insulin;
|
result.bolusDelivered = detailedBolusInfo.insulin;
|
||||||
|
@ -272,6 +306,9 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
|
|
||||||
|
absoluteRate = PumpUtil.determineCorrectBasalSize(absoluteRate, this.pumpType);
|
||||||
|
|
||||||
TemporaryBasal tempBasal = new TemporaryBasal()
|
TemporaryBasal tempBasal = new TemporaryBasal()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.absolute(absoluteRate)
|
.absolute(absoluteRate)
|
||||||
|
|
Loading…
Reference in a new issue