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); detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history 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 // v2 stores end time for bolus, we need to adjust time
// delivery speed is 12 U/min // default delivery speed is 12 U/min
detailedBolusInfo.date += detailedBolusInfo.insulin / 12d * 60 * 1000; detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000;
// clean carbs to prevent counting them as twice because they will picked up as another record // 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 // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
double carbs = detailedBolusInfo.carbs; 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 Treatment t;
private static double amount; private static double amount;
public static boolean done;
public DanaRS_Packet_Notify_Delivery_Complete() { public DanaRS_Packet_Notify_Delivery_Complete() {
super(); super();
@ -28,6 +29,7 @@ public class DanaRS_Packet_Notify_Delivery_Complete extends DanaRS_Packet {
this(); this();
this.amount = amount; this.amount = amount;
this.t = t; this.t = t;
done = false;
} }
@Override @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.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), deliveredInsulin);
bolusingEvent.t = t; bolusingEvent.t = t;
bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100); bolusingEvent.percent = Math.min((int) (deliveredInsulin / amount * 100), 100);
done = true;
MainApp.bus().post(bolusingEvent); MainApp.bus().post(bolusingEvent);
} }

View file

@ -695,6 +695,7 @@ public class BLEComm {
Runnable task = new DisconnectRunnable(); Runnable task = new DisconnectRunnable();
final int sec = 5; final int sec = 5;
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS); 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; t.insulin = 0d;
return false; return false;
} }
while (!stop.stopped && !start.failed) { while (!stop.stopped && !start.failed && !complete.done) {
SystemClock.sleep(100); SystemClock.sleep(100);
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
stop.stopped = true; stop.stopped = true;
@ -225,6 +225,7 @@ public class DanaRSService extends Service {
} }
SystemClock.sleep(3000); SystemClock.sleep(3000);
bolusingTreatment = null; bolusingTreatment = null;
DanaRSPlugin.connectIfNotConnected("ReadHistoryAfterBolus");
loadEvents(); loadEvents();
return true; return true;
} }