Merge pull request #1704 from TebbeUbben/insight-fix

Insight fix
This commit is contained in:
AdrianLxM 2019-04-01 09:36:10 +02:00 committed by GitHub
commit 98a3d64c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View file

@ -18,6 +18,10 @@ public enum DoseStepSize
new DoseStepSizeEntry(5f, 10f, 0.2f), //
new DoseStepSizeEntry(10f, Double.MAX_VALUE, 0.5f)),
InsightBasal(
new DoseStepSizeEntry(0f, 5f, 0.01f),
new DoseStepSizeEntry(5f, Double.MAX_VALUE, 0.1f)),
MedtronicVeoBasal( //
new DoseStepSizeEntry(0f, 1f, 0.025f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //

View file

@ -49,9 +49,15 @@ public enum PumpType {
AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, //
new DoseSettings(0.05d, 15, 24*60, 0.05d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, null, PumpCapability.InsightCapabilities), //
AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, //
new DoseSettings(0.01d, 15, 24*60, 0.05d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
// Animas
AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
new DoseSettings(0.05d, 30, 12*60, 0.05d), //

View file

@ -171,7 +171,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
.preferencesId(R.xml.pref_insight_local));
pumpDescription = new PumpDescription();
pumpDescription.setPumpDescription(PumpType.AccuChekInsight);
pumpDescription.setPumpDescription(PumpType.AccuChekInsightBluetooth);
}
public TBROverNotificationBlock getTBROverNotificationBlock() {
@ -315,7 +315,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
calendar.set(Calendar.HOUR_OF_DAY, pumpTime.getHour());
calendar.set(Calendar.MINUTE, pumpTime.getMinute());
calendar.set(Calendar.SECOND, pumpTime.getSecond());
if (Math.abs(calendar.getTimeInMillis() - System.currentTimeMillis()) > 10000) {
if (calendar.get(Calendar.HOUR_OF_DAY) != pumpTime.getHour() || Math.abs(calendar.getTimeInMillis() - System.currentTimeMillis()) > 10000) {
calendar.setTime(new Date());
pumpTime.setYear(calendar.get(Calendar.YEAR));
pumpTime.setMonth(calendar.get(Calendar.MONTH) + 1);
@ -421,7 +421,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
if (profile.getBasalValues().length > i + 1)
nextValue = profile.getBasalValues()[i + 1];
BasalProfileBlock profileBlock = new BasalProfileBlock();
profileBlock.setBasalAmount(basalValue.value);
profileBlock.setBasalAmount(basalValue.value > 5 ? Math.round(basalValue.value / 0.1) * 0.1 : Math.round(basalValue.value / 0.01) * 0.01);
profileBlock.setDuration((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
profileBlocks.add(profileBlock);
}
@ -476,7 +476,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
nextValue = profile.getBasalValues()[i + 1];
if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds)
return false;
if (Math.abs(profileBlock.getBasalAmount() - basalValue.value) > 0.01D)
if (Math.abs(profileBlock.getBasalAmount() - basalValue.value) > (basalValue.value > 5 ? 0.05 : 0.005))
return false;
}
return true;
@ -510,14 +510,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
PumpEnactResult result = new PumpEnactResult();
if (detailedBolusInfo.insulin > 0) {
double insulin = Math.round(detailedBolusInfo.insulin / 0.01) * 0.01;
if (insulin > 0) {
try {
synchronized ($bolusLock) {
DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
bolusMessage.setBolusType(BolusType.STANDARD);
bolusMessage.setDuration(0);
bolusMessage.setExtendedAmount(0);
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
bolusMessage.setImmediateAmount(insulin);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
bolusCancelled = false;
}
@ -527,7 +528,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
t.isSMB = detailedBolusInfo.isSMB;
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.t = t;
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, detailedBolusInfo.insulin);
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, 0d, insulin);
bolusingEvent.percent = 0;
MainApp.bus().post(bolusingEvent);
int trials = 0;
@ -565,7 +566,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
synchronized ($bolusLock) {
if (bolusCancelled || trials == -1 || trials++ >= 5) {
if (!bolusCancelled) {
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, insulin, insulin);
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
}
@ -592,6 +593,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
result.enacted = true;
}
result.carbsDelivered = detailedBolusInfo.carbs;
result.bolusDelivered = insulin;
return result;
}
@ -1537,6 +1539,11 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
return insulin;
}
@Override
public Constraint<Double> applyExtendedBolusConstraints(Constraint<Double> insulin) {
return applyBolusConstraints(insulin);
}
@Override
public void onStateChanged(InsightState state) {
if (state == InsightState.CONNECTED) {