RS bolus code

This commit is contained in:
Milos Kozak 2017-10-03 21:47:36 +02:00
parent f5dfff7491
commit 2a98a7e9ba
4 changed files with 21 additions and 3 deletions

View file

@ -436,9 +436,22 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
int speed = 12;
switch (preferencesSpeed) {
case 0:
speed = 12;
break;
case 1:
speed = 30;
break;
case 2:
speed = 60;
break;
}
// v2 stores end time for bolus, we need to adjust time
// delivery speed is 12 U/min
detailedBolusInfo.date += detailedBolusInfo.insulin / 12d * 60 * 1000;
// default delivery speed is 12 U/min
detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000;
// clean carbs to prevent counting them as twice because they will picked up as another record
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
double carbs = detailedBolusInfo.carbs;

View file

@ -17,6 +17,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
private static Treatment t;
private static double amount;
public static boolean done;
public DanaRS_Packet_Notify_Delivery_Complete() {
super();
@ -28,6 +29,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
this();
this.amount = amount;
this.t = t;
done = false;
}
@Override
@ -40,6 +42,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), deliveredInsulin);
bolusingEvent.t = t;
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100);
done = true;
MainApp.bus().post(bolusingEvent);
}

View file

@ -695,6 +695,7 @@ public class BLEComm {
Runnable task = new DisconnectRunnable();
final int sec = 5;
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
log.debug("Disconnection scheduled");
}
}

View file

@ -214,7 +214,7 @@ public class DanaRSService extends Service {
t.insulin = 0d;
return false;
}
while (!stop.stopped && !start.failed) {
while (!stop.stopped && !start.failed && !complete.done) {
SystemClock.sleep(100);
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
stop.stopped = true;
@ -225,6 +225,7 @@ public class DanaRSService extends Service {
}
SystemClock.sleep(3000);
bolusingTreatment = null;
DanaRSPlugin.connectIfNotConnected("ReadHistoryAfterBolus");
loadEvents();
return true;
}