wear wizard working
This commit is contained in:
parent
9785d507a8
commit
4220d7712a
|
@ -48,6 +48,8 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
private static long lastSentTimestamp = 0;
|
private static long lastSentTimestamp = 0;
|
||||||
private static String lastConfirmActionString = null;
|
private static String lastConfirmActionString = null;
|
||||||
|
private static BolusWizard lastBolusWizard = null;
|
||||||
|
|
||||||
private static SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
private static SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +60,8 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
public synchronized static void handleInitiate(String actionstring){
|
public synchronized static void handleInitiate(String actionstring){
|
||||||
|
|
||||||
|
lastBolusWizard = null;
|
||||||
|
|
||||||
String rTitle = "CONFIRM"; //TODO: i18n
|
String rTitle = "CONFIRM"; //TODO: i18n
|
||||||
String rMessage = "";
|
String rMessage = "";
|
||||||
String rAction = "";
|
String rAction = "";
|
||||||
|
@ -178,19 +182,59 @@ public class ActionStringHandler {
|
||||||
////////////////////////////////////////////// WIZARD
|
////////////////////////////////////////////// WIZARD
|
||||||
Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]);
|
Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]);
|
||||||
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbsBeforeConstraints);
|
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbsBeforeConstraints);
|
||||||
//TODO: wizard calculation
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
if(carbsAfterConstraints - carbsBeforeConstraints !=0){
|
||||||
|
sendError("Carb constraint violation!"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(false){
|
boolean useBG = Boolean.parseBoolean(act[2]);
|
||||||
//... add more actions
|
boolean useBolusIOB = Boolean.parseBoolean(act[3]);
|
||||||
|
boolean useBasalIOB = Boolean.parseBoolean(act[4]);
|
||||||
|
|
||||||
|
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
|
if (profile == null) {
|
||||||
|
sendError("No profile found!"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BgReading bgReading = MainApp.getDbHelper().actualBg();
|
||||||
|
if(bgReading==null && useBG){
|
||||||
|
sendError("No recent BG to base calculation on!"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BolusWizard bolusWizard = new BolusWizard();
|
||||||
|
bolusWizard.doCalc(profile.getDefaultProfile(), carbsAfterConstraints, useBG?bgReading.valueToUnits(profile.getUnits()):0d, 0d, useBolusIOB, useBasalIOB);
|
||||||
|
|
||||||
|
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin);
|
||||||
|
if(insulinAfterConstraints - bolusWizard.calculatedTotalInsulin !=0){
|
||||||
|
sendError("Insulin contraint violation!"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double insulin = bolusWizard.calculatedTotalInsulin;
|
||||||
|
if(bolusWizard.calculatedTotalInsulin < 0) {
|
||||||
|
bolusWizard.calculatedTotalInsulin = 0d;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bolusWizard.calculatedTotalInsulin <=0 && bolusWizard.carbs <=0){
|
||||||
|
rAction = "info";
|
||||||
|
rTitle = "INFO";
|
||||||
|
}
|
||||||
|
rAction = actionstring;
|
||||||
|
|
||||||
|
DecimalFormat format = new DecimalFormat("0.00");
|
||||||
|
rMessage += "Bolus: " + format.format(bolusWizard.calculatedTotalInsulin) + "U";
|
||||||
|
rMessage += "\nWizard: " + format.format(insulin) + "U";
|
||||||
|
rMessage += "\nCarb: " + format.format(bolusWizard.insulinFromCarbs) + "U";
|
||||||
|
if(useBG)rMessage += "\nBG: " + format.format(bolusWizard.insulinFromBG) + "U";
|
||||||
|
if(useBolusIOB)rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
||||||
|
if(useBasalIOB)rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
||||||
|
rMessage += "\nIC:" + DecimalFormatter.to1Decimal(bolusWizard.ic);
|
||||||
|
if(useBG)rMessage += " ISF:" + DecimalFormatter.to1Decimal(bolusWizard.sens);
|
||||||
|
|
||||||
|
lastBolusWizard = bolusWizard;
|
||||||
|
|
||||||
} else return;
|
} else return;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// send result
|
// send result
|
||||||
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, rMessage, rAction);
|
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation(rTitle, rMessage, rAction);
|
||||||
lastSentTimestamp = System.currentTimeMillis();
|
lastSentTimestamp = System.currentTimeMillis();
|
||||||
|
@ -228,10 +272,17 @@ public class ActionStringHandler {
|
||||||
high *= Constants.MMOLL_TO_MGDL;
|
high *= Constants.MMOLL_TO_MGDL;
|
||||||
}
|
}
|
||||||
generateTempTarget(duration, low, high);
|
generateTempTarget(duration, low, high);
|
||||||
|
} else if ("wizard".equals(act[0])){
|
||||||
|
//use last calculation as confirmed string matches
|
||||||
|
|
||||||
|
doBolus(lastBolusWizard.calculatedTotalInsulin, lastBolusWizard.carbs);
|
||||||
|
lastBolusWizard = null;
|
||||||
|
} else if ("bolus".equals(act[0])) {
|
||||||
|
double insulin = SafeParse.stringToDouble(act[1]);
|
||||||
|
int carbs = SafeParse.stringToInt(act[2]);
|
||||||
|
doBolus(insulin, carbs);
|
||||||
}
|
}
|
||||||
|
lastBolusWizard = null;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateTempTarget(int duration, double low, double high) {
|
private static void generateTempTarget(int duration, double low, double high) {
|
||||||
|
@ -275,9 +326,25 @@ public class ActionStringHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void doBolus(final Double amount, final Integer carbs) {
|
||||||
|
Handler handler = new Handler(handlerThread.getLooper());
|
||||||
|
handler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(amount, carbs, null, true);
|
||||||
|
if (!result.success) {
|
||||||
|
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||||
|
"\n" +
|
||||||
|
result.comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized static void sendError(String errormessage){
|
private synchronized static void sendError(String errormessage){
|
||||||
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation("ERROR", errormessage, "error");
|
WearFragment.getPlugin(MainApp.instance()).requestActionConfirmation("ERROR", errormessage, "error");
|
||||||
lastSentTimestamp = System.currentTimeMillis();
|
lastSentTimestamp = System.currentTimeMillis();
|
||||||
lastConfirmActionString = null;
|
lastConfirmActionString = null;
|
||||||
|
lastBolusWizard = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import info.nightscout.client.data.NSProfile;
|
||||||
public class BolusWizard {
|
public class BolusWizard {
|
||||||
// Inputs
|
// Inputs
|
||||||
JSONObject specificProfile = null;
|
JSONObject specificProfile = null;
|
||||||
Integer carbs = 0;
|
public Integer carbs = 0;
|
||||||
Double bg = 0d;
|
Double bg = 0d;
|
||||||
Double correction;
|
Double correction;
|
||||||
Boolean includeBolusIOB = true;
|
Boolean includeBolusIOB = true;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class FillActivity extends Activity {
|
||||||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount(int arg0) {
|
public int getColumnCount(int arg0) {
|
||||||
return 3;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,13 +43,6 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/shaders" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/shaders" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/full/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/full/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/full/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/full/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/full/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/full/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/full/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/res" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/res" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/resources" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/resources" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/assets" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/assets" type="java-test-resource" />
|
||||||
|
@ -58,6 +51,13 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/jni" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/jni" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/rs" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/shaders" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/full/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/full/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/full/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/full/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/full/debug" isTestSource="true" generated="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/full/debug" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/full/debug" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/full/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/full/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/full/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/full/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/full/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/full/assets" type="java-resource" />
|
||||||
|
|
Loading…
Reference in a new issue