Bolusing dialog
This commit is contained in:
parent
3e5eb85b88
commit
a7d3dca752
|
@ -37,7 +37,7 @@
|
|||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -46,10 +46,10 @@ android {
|
|||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||
}
|
||||
full {
|
||||
buildConfigField "boolean", "APS", "true"
|
||||
buildConfigField "boolean", "APS", "true"
|
||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||
buildConfigField "boolean", "OBJECTIVES", "true"
|
||||
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
||||
buildConfigField "boolean", "OBJECTIVES", "true"
|
||||
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
||||
}
|
||||
full_noobjectives {
|
||||
buildConfigField "boolean", "APS", "true"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -27,7 +29,8 @@ public interface PumpInterface {
|
|||
TempBasal getTempBasal();
|
||||
TempBasal getExtendedBolus();
|
||||
|
||||
PumpEnactResult deliverTreatment(Double insulin, Integer carbs);
|
||||
PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context);
|
||||
void stopBolusDelivering();
|
||||
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
||||
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -9,6 +10,7 @@ import android.os.Bundle;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -47,10 +49,12 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResult;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
|
||||
import info.nightscout.client.data.DbLogger;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
|
@ -318,11 +322,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
*/
|
||||
|
||||
public PumpEnactResult deliverTreatmentFromBolusWizard(Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||
public PumpEnactResult deliverTreatmentFromBolusWizard(Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||
insulin = applyBolusConstraints(insulin);
|
||||
carbs = applyCarbsConstraints(carbs);
|
||||
|
||||
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs);
|
||||
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context);
|
||||
|
||||
if (Config.logCongigBuilderActions)
|
||||
log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
|
||||
|
@ -345,11 +349,21 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
insulin = applyBolusConstraints(insulin);
|
||||
carbs = applyCarbsConstraints(carbs);
|
||||
|
||||
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs);
|
||||
BolusProgressDialog bolusProgressDialog = null;
|
||||
if (context != null) {
|
||||
bolusProgressDialog = new BolusProgressDialog(insulin);
|
||||
bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress");
|
||||
}
|
||||
|
||||
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context);
|
||||
|
||||
if (bolusProgressDialog != null) {
|
||||
bolusProgressDialog.dismiss();
|
||||
}
|
||||
|
||||
if (Config.logCongigBuilderActions)
|
||||
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
|
||||
|
@ -371,6 +385,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBolusDelivering() {
|
||||
activePump.stopBolusDelivering();
|
||||
}
|
||||
|
||||
/**
|
||||
* apply constraints, set temp based on absolute valus and expecting absolute result
|
||||
*
|
||||
|
|
|
@ -57,7 +57,6 @@ import info.nightscout.client.data.NSProfile;
|
|||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.SetWarnColor;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
|
@ -190,6 +189,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
return view;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
|
@ -238,9 +238,9 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (c.sStatus == c.CONNECTING)
|
||||
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING)
|
||||
btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s");
|
||||
else if (c.sStatus == c.CONNECTED)
|
||||
else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED)
|
||||
btConnectionView.setText("{fa-bluetooth}");
|
||||
else
|
||||
btConnectionView.setText("{fa-bluetooth-b}");
|
||||
|
@ -399,12 +399,11 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
|
||||
insulin = configBuilderFragment.applyBolusConstraints(insulin);
|
||||
if (insulin > 0 || carbs > 0) {
|
||||
Treatment t = new Treatment();
|
||||
t.insulin = insulin;
|
||||
boolean connectionOK = false;
|
||||
if (carbs > 0) connectionOK = mExecutionService.carbsEntry(carbs);
|
||||
if (insulin > 0) connectionOK = mExecutionService.bolus(insulin, t);
|
||||
|
@ -427,6 +426,15 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBolusDelivering() {
|
||||
if (mExecutionService == null) {
|
||||
log.error("stopBolusDelivering mExecutionService is null");
|
||||
return;
|
||||
}
|
||||
mExecutionService.bolusStop();
|
||||
}
|
||||
|
||||
// This is called from APS
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
|
|
|
@ -432,7 +432,6 @@ public class DanaRHistoryActivity extends Activity {
|
|||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRConnectionStatus c) {
|
||||
log.debug("EventDanaRConnectionStatus: " + c.sStatus);
|
||||
runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -170,6 +170,10 @@ public class SerialIOThread extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
if (!message.received) {
|
||||
log.warn("Reply not received " + message.getMessageName());
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
|
@ -73,6 +72,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusBolusExtended;
|
|||
import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusTempBasal;
|
||||
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
|
@ -181,10 +181,10 @@ public class ExecutionService extends Service {
|
|||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||
return;
|
||||
}
|
||||
if (isConnected()) {
|
||||
while (isConnected() || isConnecting()) {
|
||||
if (Config.logDanaBTComm)
|
||||
log.debug("already connected from:" + from);
|
||||
return;
|
||||
log.debug("already connected from: " + from);
|
||||
waitMsec(3000);
|
||||
}
|
||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
||||
synchronized (connectionLock) {
|
||||
|
@ -199,7 +199,7 @@ public class ExecutionService extends Service {
|
|||
long secondsElapsed = (new Date().getTime() - startTime) / 1000L;
|
||||
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTING, (int) secondsElapsed));
|
||||
if (Config.logDanaBTComm)
|
||||
log.debug("connect waiting " + secondsElapsed + "sec from:" + from);
|
||||
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
|
||||
try {
|
||||
mRfcommSocket.connect();
|
||||
} catch (IOException e) {
|
||||
|
@ -265,7 +265,6 @@ public class ExecutionService extends Service {
|
|||
mSerialIOThread.sendMessage(tempStatusMsg); // do this before statusBasic because here is temp duration
|
||||
mSerialIOThread.sendMessage(exStatusMsg);
|
||||
mSerialIOThread.sendMessage(statusMsg);
|
||||
waitMsec(100);
|
||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
||||
mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); // TODO: show it somewhere
|
||||
|
||||
|
@ -323,7 +322,6 @@ public class ExecutionService extends Service {
|
|||
connect("tempBasal");
|
||||
if (!isConnected()) return false;
|
||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||
return true;
|
||||
}
|
||||
|
@ -332,7 +330,6 @@ public class ExecutionService extends Service {
|
|||
connect("tempBasalStop");
|
||||
if (!isConnected()) return false;
|
||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
||||
return true;
|
||||
}
|
||||
|
@ -341,7 +338,6 @@ public class ExecutionService extends Service {
|
|||
connect("extendedBolus");
|
||||
if (!isConnected()) return false;
|
||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||
return true;
|
||||
}
|
||||
|
@ -350,46 +346,49 @@ public class ExecutionService extends Service {
|
|||
connect("extendedBolusStop");
|
||||
if (!isConnected()) return false;
|
||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||
waitMsec(200);
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean bolus(Double amount, Treatment t) {
|
||||
connect("bolus");
|
||||
if (!isConnected()) return false;
|
||||
// TODO: progress dialog
|
||||
bolusingTreatment = t;
|
||||
MsgBolusStart start = new MsgBolusStart(amount);
|
||||
MsgBolusProgress progress = new MsgBolusProgress(MainApp.bus(), amount, t);
|
||||
MsgBolusStop stop = new MsgBolusStop(MainApp.bus(), amount, t);
|
||||
|
||||
mSerialIOThread.sendMessage(start);
|
||||
connect("bolus");
|
||||
if (!isConnected()) return false;
|
||||
|
||||
MainApp.bus().post(new EventDanaRBolusStart());
|
||||
|
||||
if (!stop.stopped) {
|
||||
mSerialIOThread.sendMessage(start);
|
||||
} else {
|
||||
t.insulin = 0d;
|
||||
return false;
|
||||
}
|
||||
while (!stop.stopped && !start.failed) {
|
||||
waitMsec(100);
|
||||
}
|
||||
bolusingTreatment = null;
|
||||
waitMsec(200);
|
||||
getPumpStatus();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void bolusStop() {
|
||||
Treatment lastBolusingTreatment = bolusingTreatment;
|
||||
if (Config.logDanaBTComm)
|
||||
log.debug("bolusStop >>>>> @ " + (bolusingTreatment == null ? "" : bolusingTreatment.insulin));
|
||||
MsgBolusStop stop = new MsgBolusStop();
|
||||
stop.forced = true;
|
||||
mSerialIOThread.sendMessage(stop);
|
||||
while (!stop.stopped) {
|
||||
if (isConnected()) {
|
||||
mSerialIOThread.sendMessage(stop);
|
||||
waitMsec(200);
|
||||
while (!stop.stopped) {
|
||||
mSerialIOThread.sendMessage(stop);
|
||||
waitMsec(200);
|
||||
}
|
||||
} else {
|
||||
stop.stopped = true;
|
||||
}
|
||||
// and update ns status to last amount
|
||||
waitMsec(60000);
|
||||
EventDanaRBolusProgress be = EventDanaRBolusProgress.getInstance();
|
||||
be.sStatus = "";
|
||||
MainApp.bus().post(be);
|
||||
}
|
||||
|
||||
public boolean carbsEntry(int amount) {
|
||||
|
@ -398,7 +397,6 @@ public class ExecutionService extends Service {
|
|||
Calendar time = Calendar.getInstance();
|
||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
||||
mSerialIOThread.sendMessage(msg);
|
||||
waitMsec(200);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -453,10 +451,8 @@ public class ExecutionService extends Service {
|
|||
double[] basal = buildDanaRProfileRecord(profile);
|
||||
MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal);
|
||||
mSerialIOThread.sendMessage(msgSet);
|
||||
waitMsec(200);
|
||||
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
|
||||
mSerialIOThread.sendMessage(msgActivate);
|
||||
waitMsec(200);
|
||||
getPumpStatus();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,9 @@ public class MsgBolusProgress extends MessageBase {
|
|||
Double done = (amount * 100 - progress) / 100d;
|
||||
t.insulin = done;
|
||||
EventDanaRBolusProgress bolusingEvent = EventDanaRBolusProgress.getInstance();
|
||||
bolusingEvent.sStatus = "Delivering " + DecimalFormatter.to1Decimal(done) + "U";
|
||||
bolusingEvent.status = "Delivering " + DecimalFormatter.to1Decimal(done) + "U";
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = Math.min((int) (done / amount * 100), 100);
|
||||
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Bolus remaining: " + progress + " delivered: " + done);
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.squareup.otto.Bus;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
|
||||
|
@ -36,9 +38,10 @@ public class MsgBolusStop extends MessageBase {
|
|||
stopped = true;
|
||||
if (!forced) {
|
||||
t.insulin = amount;
|
||||
bolusingEvent.sStatus = "Delivered";
|
||||
bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_delivered);
|
||||
bolusingEvent.percent = 100;
|
||||
} else {
|
||||
bolusingEvent.sStatus = "Stopped";
|
||||
bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusprogress_stoped);
|
||||
}
|
||||
bus.post(bolusingEvent);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Date;
|
|||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
import info.nightscout.client.data.DbLogger;
|
||||
|
@ -31,7 +32,7 @@ public class MsgOcclusion extends MessageBase {
|
|||
log.debug("Oclusion detected");
|
||||
EventDanaRBolusProgress bolusingEvent = EventDanaRBolusProgress.getInstance();
|
||||
MsgBolusStop.stopped = true;
|
||||
bolusingEvent.sStatus = "Oclusion";
|
||||
bolusingEvent.status = MainApp.sResources.getString(R.string.overview_bolusiprogress_occlusion);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
sendToNSClient();
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ public class MsgOcclusion extends MessageBase {
|
|||
try {
|
||||
data.put("eventType", "Announcement");
|
||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||
data.put("notes", "Occlusion detected");
|
||||
data.put("notes", MainApp.sResources.getString(R.string.overview_bolusiprogress_occlusion));
|
||||
data.put("isAnnouncement", true);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -17,8 +17,9 @@ import info.nightscout.client.data.DbLogger;
|
|||
|
||||
public class EventDanaRBolusProgress {
|
||||
private static Logger log = LoggerFactory.getLogger(EventDanaRBolusProgress.class);
|
||||
public String sStatus = "";
|
||||
public String status = "";
|
||||
public Treatment t = null;
|
||||
public int percent = 0;
|
||||
private static EventDanaRBolusProgress eventDanaRBolusProgress = null;
|
||||
|
||||
public EventDanaRBolusProgress() {
|
||||
|
@ -31,25 +32,4 @@ public class EventDanaRBolusProgress {
|
|||
return eventDanaRBolusProgress;
|
||||
}
|
||||
|
||||
public void sendToNSClient() {
|
||||
if (t == null || t._id == null || t._id.equals("")) return;
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("action", "dbUpdate");
|
||||
bundle.putString("collection", "treatments");
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("status", sStatus);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
bundle.putString("data", data.toString());
|
||||
bundle.putString("_id", t._id);
|
||||
Intent intent = new Intent(Intents.ACTION_DATABASE);
|
||||
intent.putExtras(bundle);
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
context.sendBroadcast(intent);
|
||||
DbLogger.dbAdd(intent, data.toString(), EventDanaRBolusProgress.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 03.08.2016.
|
||||
*/
|
||||
public class EventDanaRBolusStart {
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.MM640g;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -164,10 +165,15 @@ public class MM640gFragment extends Fragment implements PluginBase, PumpInterfac
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
return new PumpEnactResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBolusDelivering() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
return new PumpEnactResult();
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class BolusProgressDialog extends DialogFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(BolusProgressDialog.class);
|
||||
Button stopButton;
|
||||
TextView statusView;
|
||||
TextView stopPressedView;
|
||||
ProgressBar progressBar;
|
||||
|
||||
double amount;
|
||||
|
||||
boolean started = false;
|
||||
|
||||
public BolusProgressDialog(double amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
getDialog().setTitle(String.format(MainApp.sResources.getString(R.string.overview_bolusprogress_goingtodeliver), amount));
|
||||
View view = inflater.inflate(R.layout.overview_bolusprogress_dialog, container, false);
|
||||
stopButton = (Button) view.findViewById(R.id.overview_bolusprogress_stop);
|
||||
statusView = (TextView) view.findViewById(R.id.overview_bolusprogress_status);
|
||||
stopPressedView = (TextView) view.findViewById(R.id.overview_bolusprogress_stoppressed);
|
||||
progressBar = (ProgressBar) view.findViewById(R.id.overview_bolusprogress_progressbar);
|
||||
|
||||
stopButton.setOnClickListener(this);
|
||||
progressBar.setMax(100);
|
||||
statusView.setText(MainApp.sResources.getString(R.string.waitingforpump));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.overview_bolusprogress_stop:
|
||||
log.debug("Stop bolus delivery button pressed");
|
||||
stopPressedView.setVisibility(View.VISIBLE);
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
pump.stopBolusDelivering();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRBolusProgress ev) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.debug("Status: " + ev.status + " Percent: " + ev.percent);
|
||||
statusView.setText(ev.status);
|
||||
progressBar.setProgress(ev.percent);
|
||||
if (ev.percent == 100) {
|
||||
stopButton.setVisibility(View.INVISIBLE);
|
||||
scheduleDismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRBolusStart ev) {
|
||||
started = true;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRConnectionStatus c) {
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (c.sStatus == c.CONNECTING) {
|
||||
statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
|
||||
} else if (c.sStatus == c.CONNECTED) {
|
||||
statusView.setText(MainApp.sResources.getString(R.string.connected));
|
||||
} else {
|
||||
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
|
||||
if (started) scheduleDismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void scheduleDismiss() {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -33,10 +35,13 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
Handler mHandler;
|
||||
public static HandlerThread mHandlerThread;
|
||||
|
||||
public NewTreatmentDialog() {
|
||||
mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName());
|
||||
Context parentContext;
|
||||
|
||||
public NewTreatmentDialog(Context context) {
|
||||
mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||
parentContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,12 +98,12 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, parentContext);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||
builder.setMessage(result.comment);
|
||||
builder.setPositiveButton(getContext().getString(R.string.ok), null);
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -77,10 +78,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
Handler mHandler;
|
||||
public static HandlerThread mHandlerThread;
|
||||
|
||||
public WizardDialog() {
|
||||
Context parentContext;
|
||||
|
||||
public WizardDialog(Context context) {
|
||||
mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
mHandler = new Handler(mHandlerThread.getLooper());
|
||||
parentContext = context;
|
||||
}
|
||||
|
||||
final private TextWatcher textWatcher = new TextWatcher() {
|
||||
|
@ -193,6 +197,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
@Override
|
||||
public void run() {
|
||||
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
|
||||
parentContext,
|
||||
finalInsulinAfterConstraints,
|
||||
finalCarbsAfterConstraints,
|
||||
SafeParse.stringToDouble(bgInput.getText().toString()),
|
||||
|
|
|
@ -185,7 +185,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager manager = getFragmentManager();
|
||||
NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog();
|
||||
NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(getContext());
|
||||
treatmentDialogFragment.show(manager, "TreatmentDialog");
|
||||
}
|
||||
});
|
||||
|
@ -194,7 +194,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager manager = getFragmentManager();
|
||||
WizardDialog wizardDialog = new WizardDialog();
|
||||
WizardDialog wizardDialog = new WizardDialog(getContext());
|
||||
wizardDialog.show(manager, "WizardDialog");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -234,7 +234,7 @@ public class SmsCommunicatorFragment extends Fragment implements PluginBase {
|
|||
PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump();
|
||||
if (pumpInterface != null) {
|
||||
danaRFragment = (DanaRFragment) MainApp.getSpecificPlugin(DanaRFragment.class);
|
||||
PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0);
|
||||
PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0, null);
|
||||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.bolusdelivered), bolusWaitingForConfirmation.bolusRequested);
|
||||
if (danaRFragment != null) reply += "\n" + danaRFragment.shortStatus();
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.VirtualPump;
|
|||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -181,7 +182,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.bolusDelivered = insulin;
|
||||
|
@ -194,6 +195,11 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopBolusDelivering() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
PumpEnactResult result = cancelTempBasal();
|
||||
|
|
50
app/src/main/res/layout/overview_bolusprogress_dialog.xml
Normal file
50
app/src/main/res/layout/overview_bolusprogress_dialog.xml
Normal file
|
@ -0,0 +1,50 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/overview_bolusprogress_status"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/overview_bolusprogress_stoppressed"
|
||||
android:id="@+id/overview_bolusprogress_stoppressed"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#fd0101"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/overview_bolusprogress_progressbar"
|
||||
android:layout_height="20dp"
|
||||
android:layout_width="match_parent"
|
||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||
android:minHeight="3dp"
|
||||
android:maxHeight="5dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/overview_bolusprogress_stop"
|
||||
android:id="@+id/overview_bolusprogress_stop"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="30dp" />
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
|
@ -65,7 +65,7 @@
|
|||
<string name="delta">Rozdíl</string>
|
||||
<string name="duration">Trvání</string>
|
||||
<string name="en_lang">English</string>
|
||||
<string name="entertreatmentquestion">Zadej nové ošetření</string>
|
||||
<string name="entertreatmentquestion">Aplikovat bolus</string>
|
||||
<string name="glucose">Glykémie</string>
|
||||
<string name="loop">Smyčka</string>
|
||||
<string name="loop_aps_label">APS</string>
|
||||
|
@ -279,4 +279,11 @@
|
|||
<string name="wrongpumppassword">Špatné heslo k pumpě</string>
|
||||
<string name="mm640g"></string>
|
||||
<string name="danar_password">Heslo k pumpě (pouze verze 2016)</string>
|
||||
<string name="overview_bolusiprogress_occlusion">Okluze</string>
|
||||
<string name="overview_bolusprogress_delivered">Podáno</string>
|
||||
<string name="overview_bolusprogress_stop">Stop</string>
|
||||
<string name="overview_bolusprogress_stoped">Zastaveno</string>
|
||||
<string name="overview_bolusprogress_stoppressed">STISKNUTO STOP</string>
|
||||
<string name="waitingforpump">Čekání na pumpu</string>
|
||||
<string name="overview_bolusprogress_goingtodeliver" formatted="false">Podávání %.2fU inzulínu</string>
|
||||
</resources>
|
|
@ -288,5 +288,12 @@
|
|||
<string name="danar_password">Pump password (2016 pump only)</string>
|
||||
<string name="wrongpumppassword">Wrong pump password!</string>
|
||||
<string name="pumpbusy">Pump is busy</string>
|
||||
<string name="overview_bolusprogress_delivered">Delivered</string>
|
||||
<string name="overview_bolusprogress_stoped">Stopped</string>
|
||||
<string name="overview_bolusiprogress_occlusion">Occlusion</string>
|
||||
<string name="overview_bolusprogress_stop">Stop</string>
|
||||
<string name="overview_bolusprogress_stoppressed">STOP PRESSED</string>
|
||||
<string name="waitingforpump">Waiting for pump</string>
|
||||
<string name="overview_bolusprogress_goingtodeliver" formatted="false">Going to deliver %.2fU</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue