allign dana plugin code

This commit is contained in:
Milos Kozak 2017-11-21 19:27:43 +01:00
parent 3ab235f829
commit d2cba61354
3 changed files with 30 additions and 25 deletions

View file

@ -415,7 +415,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
log.debug("setTempBasalAbsolute: currently running: " + running.toString()); log.debug("setTempBasalAbsolute: currently running: " + running.toString());
if (running.percentRate == percentRate) { if (running.percentRate == percentRate) {
if (enforceNew) { if (enforceNew) {
cancelTempBasal(true); cancelTempBasal(true);
} else { } else {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
@ -543,7 +543,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
} }
result.enacted = false; result.enacted = false;
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror);
log.error("setTempBasalPercent: Failed to set temp basal"); log.error("setTempBasalPercent: Failed to set temp basal");
return result; return result;
} }

View file

@ -61,9 +61,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
return DanaRFragment.class.getName(); return DanaRFragment.class.getName();
} }
private boolean fragmentPumpEnabled = false; private static boolean fragmentPumpEnabled = false;
private boolean fragmentProfileEnabled = false; private static boolean fragmentProfileEnabled = false;
private boolean fragmentPumpVisible = true; private static boolean fragmentPumpVisible = true;
private static DanaRKoreanExecutionService sExecutionService; private static DanaRKoreanExecutionService sExecutionService;
@ -201,11 +201,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
@Override @Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) { public void setFragmentEnabled(int type, boolean fragmentEnabled) {
if (type == PluginBase.PROFILE) if (type == PluginBase.PROFILE)
this.fragmentProfileEnabled = fragmentEnabled; fragmentProfileEnabled = fragmentEnabled;
else if (type == PluginBase.PUMP) else if (type == PluginBase.PUMP)
this.fragmentPumpEnabled = fragmentEnabled; fragmentPumpEnabled = fragmentEnabled;
// if pump profile was enabled need to switch to another too // if pump profile was enabled need to switch to another too
if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) { if (type == PluginBase.PUMP && !fragmentEnabled && fragmentProfileEnabled) {
setFragmentEnabled(PluginBase.PROFILE, false); setFragmentEnabled(PluginBase.PROFILE, false);
setFragmentVisible(PluginBase.PROFILE, false); setFragmentVisible(PluginBase.PROFILE, false);
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true); NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
@ -216,7 +216,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PluginBase.PUMP) if (type == PluginBase.PUMP)
this.fragmentPumpVisible = fragmentVisible; fragmentPumpVisible = fragmentVisible;
} }
@Override @Override
@ -316,8 +316,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
Treatment t = new Treatment(); Treatment t = new Treatment();
boolean connectionOK = false; boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
@ -394,9 +393,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue(); if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
else percentRate = Round.floorTo((double) percentRate, 10d).intValue(); else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
if (percentRate > 200) { if (percentRate > getPumpDescription().maxTempPercent) {
percentRate = 200; percentRate = getPumpDescription().maxTempPercent;
} }
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
// If extended in progress // If extended in progress
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
if (Config.logPumpActions) if (Config.logPumpActions)
@ -410,7 +412,10 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) { TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
if (running.percentRate == percentRate) {
if (enforceNew) { if (enforceNew) {
cancelTempBasal(true); cancelTempBasal(true);
} else { } else {
@ -451,7 +456,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
Double extendedRateToSet = absoluteRate - getBaseBasalRate(); Double extendedRateToSet = absoluteRate - getBaseBasalRate();
extendedRateToSet = configBuilderPlugin.applyBasalConstraints(extendedRateToSet); extendedRateToSet = configBuilderPlugin.applyBasalConstraints(extendedRateToSet);
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of 30 min extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { if (Config.logPumpActions) {

View file

@ -61,9 +61,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
return DanaRFragment.class.getName(); return DanaRFragment.class.getName();
} }
private boolean fragmentPumpEnabled = false; private static boolean fragmentPumpEnabled = false;
private boolean fragmentProfileEnabled = false; private static boolean fragmentProfileEnabled = false;
private boolean fragmentPumpVisible = false; private static boolean fragmentPumpVisible = true;
private static DanaRv2ExecutionService sExecutionService; private static DanaRv2ExecutionService sExecutionService;
@ -186,11 +186,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
@Override @Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) { public void setFragmentEnabled(int type, boolean fragmentEnabled) {
if (type == PluginBase.PROFILE) if (type == PluginBase.PROFILE)
this.fragmentProfileEnabled = fragmentEnabled; fragmentProfileEnabled = fragmentEnabled;
else if (type == PluginBase.PUMP) else if (type == PluginBase.PUMP)
this.fragmentPumpEnabled = fragmentEnabled; fragmentPumpEnabled = fragmentEnabled;
// if pump profile was enabled need to switch to another too // if pump profile was enabled need to switch to another too
if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) { if (type == PluginBase.PUMP && !fragmentEnabled && fragmentProfileEnabled) {
setFragmentEnabled(PluginBase.PROFILE, false); setFragmentEnabled(PluginBase.PROFILE, false);
setFragmentVisible(PluginBase.PROFILE, false); setFragmentVisible(PluginBase.PROFILE, false);
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true); NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
@ -201,7 +201,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PluginBase.PUMP) if (type == PluginBase.PUMP)
this.fragmentPumpVisible = fragmentVisible; fragmentPumpVisible = fragmentVisible;
} }
@Override @Override
@ -398,7 +398,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
if (percentRate > 500) // Special high temp 500/15min if (percentRate > 500) // Special high temp 500/15min
percentRate = 500; percentRate = 500;
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) { if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
if (!enforceNew) { if (!enforceNew) {
@ -515,6 +515,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
@ -802,7 +803,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n";
} }
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
@ -816,7 +817,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
ret += "Batt: " + pump.batteryRemaining + "\n"; ret += "Batt: " + pump.batteryRemaining + "\n";
return ret; return ret;
} }
// TODO: daily total constraint // TODO: daily total constraint
} }